2025-04-17 16:51:20 +08:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include "selectorDialog.h"
|
|
|
|
|
#include "global.h"
|
|
|
|
|
#include "dataBase.h"
|
|
|
|
|
|
|
|
|
|
SelectorDialog::SelectorDialog(QWidget* parent)
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
,m_buttonBox(nullptr)
|
|
|
|
|
{
|
|
|
|
|
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SelectorDialog::initial(SelectorDialogType tpe)
|
|
|
|
|
{
|
|
|
|
|
m_dlgType = tpe;
|
|
|
|
|
setupUI();
|
|
|
|
|
setupConnections();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SelectorDialog::setupUI() {
|
|
|
|
|
setWindowTitle("选择类型");
|
|
|
|
|
setFixedSize(200, 200);
|
|
|
|
|
|
|
|
|
|
m_listView = new QListView(this);
|
|
|
|
|
QStandardItemModel* model = initialModel();
|
|
|
|
|
m_listView->setModel(model);
|
|
|
|
|
m_listView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
|
|
|
|
m_buttonBox = new QDialogButtonBox(
|
|
|
|
|
QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
|
|
|
layout->addWidget(m_listView);
|
|
|
|
|
layout->addWidget(m_buttonBox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStandardItemModel * SelectorDialog::initialModel()
|
|
|
|
|
{
|
|
|
|
|
QStandardItemModel *model = new QStandardItemModel(this);
|
|
|
|
|
if(m_dlgType == ST_MetaModel){
|
2025-05-23 10:30:52 +08:00
|
|
|
QList<modelType> metas = getMetaList();
|
2025-04-17 16:51:20 +08:00
|
|
|
for(auto &meta:metas)
|
|
|
|
|
{
|
|
|
|
|
QStandardItem *item = new QStandardItem();
|
|
|
|
|
//item->setIcon(QIcon(":/icons/folder.png")); // 设置图标
|
2025-05-23 10:30:52 +08:00
|
|
|
item->setText(meta.modelName); // 设置文本
|
|
|
|
|
item->setData(meta.modelType,Qt::UserRole);
|
2025-04-17 16:51:20 +08:00
|
|
|
model->appendRow(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(m_dlgType == ST_ComponentType){
|
|
|
|
|
QStringList components = {"断路器", "母线", "异步电动机"};
|
|
|
|
|
for(auto &obj:components)
|
|
|
|
|
{
|
|
|
|
|
QStandardItem *item = new QStandardItem();
|
|
|
|
|
//item->setIcon(QIcon(":/icons/folder.png")); // 设置图标
|
|
|
|
|
item->setText(obj); // 设置文本
|
|
|
|
|
//item->setData("Extra Data for Item 1", Qt::UserRole); // 设置额外属性
|
|
|
|
|
|
|
|
|
|
model->appendRow(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SelectorDialog::setupConnections() {
|
|
|
|
|
connect(m_listView, &QListView::doubleClicked, [this](const QModelIndex& index){
|
2025-05-23 10:30:52 +08:00
|
|
|
if(m_dlgType == ST_MetaModel){
|
|
|
|
|
m_selectedMeta.modelName = index.data().toString();
|
|
|
|
|
m_selectedMeta.modelType = index.data(Qt::UserRole).toString();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
m_selectedComponent = index.data().toString();
|
|
|
|
|
}
|
2025-04-17 16:51:20 +08:00
|
|
|
accept();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_buttonBox, &QDialogButtonBox::accepted, [this]{
|
|
|
|
|
if(auto index = m_listView->currentIndex(); index.isValid()) {
|
2025-05-23 10:30:52 +08:00
|
|
|
if(m_dlgType == ST_MetaModel){
|
|
|
|
|
m_selectedMeta.modelName = index.data().toString();
|
|
|
|
|
m_selectedMeta.modelType = index.data(Qt::UserRole).toString();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
m_selectedComponent = index.data().toString();
|
|
|
|
|
}
|
2025-04-17 16:51:20 +08:00
|
|
|
}
|
|
|
|
|
accept();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-23 10:30:52 +08:00
|
|
|
QList<modelType> SelectorDialog::getMetaList() const
|
2025-04-17 16:51:20 +08:00
|
|
|
{
|
|
|
|
|
QMap<int,modelType> modelMap = DataBase::GetInstance()->ModelType();
|
|
|
|
|
|
2025-05-23 10:30:52 +08:00
|
|
|
QList<modelType> modelSet;
|
2025-04-17 16:51:20 +08:00
|
|
|
for(auto &model:modelMap)
|
|
|
|
|
{
|
2025-05-23 10:30:52 +08:00
|
|
|
modelSet.append(model);
|
2025-04-17 16:51:20 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-23 10:30:52 +08:00
|
|
|
return modelSet;
|
2025-04-17 16:51:20 +08:00
|
|
|
}
|
|
|
|
|
|