diff --git a/dataPanel/dpConfigurationDialog.cpp b/dataPanel/dpConfigurationDialog.cpp index 8e5bd50..0b6ae7e 100644 --- a/dataPanel/dpConfigurationDialog.cpp +++ b/dataPanel/dpConfigurationDialog.cpp @@ -1,12 +1,15 @@ #include "dpConfigurationDialog.h" #include "ui_dpConfigurationDialog.h" #include "dataPanel.h" +#include dpConfigurationDialog::dpConfigurationDialog(QWidget *parent) : QDialog(parent) , ui(new Ui::dpConfigurationDialog) , m_curActiveTab(nullptr) , m_pDataPanel(nullptr) + , m_pModel_typeSource(nullptr) + , m_pModel_typeSelected(nullptr) { ui->setupUi(this); setWindowFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); @@ -34,11 +37,68 @@ void dpConfigurationDialog::initialize() connect(ui->btnConfirm, SIGNAL(clicked()), this, SLOT(onBtnClicked_confirm())); connect(ui->btnCancle, SIGNAL(clicked()), this, SLOT(onBtnClicked_cancle())); + + connect(ui->btnReomve_type, SIGNAL(clicked()), this, SLOT(onBtnClicked_remove_type())); + connect(ui->btnReomve_source, SIGNAL(clicked()), this, SLOT(onBtnClicked_remove_source())); + + connect(ui->typeSourceList, SIGNAL(clicked(const QModelIndex&)), this, SLOT(onItemClicked_typeSource(const QModelIndex&))); + + //typeSourceList + m_pModel_typeSource = new QStandardItemModel(this); + ui->typeSourceList->setModel(m_pModel_typeSource); + QStringList typeSourceTextList; + typeSourceTextList << QString::fromStdWString(L"电压") << QString::fromStdWString(L"电流") << QString::fromStdWString(L"功率"); + for(QString& text: typeSourceTextList) + { + QStandardItem* item = new QStandardItem(text); + item->setEditable(false); //不可编辑 + m_pModel_typeSource->appendRow(item); + } + //typeSelectedList + ui->typeSelectedList->setSelectionBehavior(QAbstractItemView::SelectRows); + m_pModel_typeSelected = new QStandardItemModel(this); + ui->typeSelectedList->setModel(m_pModel_typeSelected); +} + +void dpConfigurationDialog::copyModelData(QStandardItemModel* sourceModel, QStandardItemModel* destModel) +{ + if(!sourceModel || !destModel) + return; + + for(int row = 0; row < destModel->rowCount(); row++) + { + for(int col = 0; col < destModel->columnCount(); col++) + { + QStandardItem* item = destModel->item(row, col); + if(item) + delete item; + } + } + destModel->clear(); //只做clear不会释放其中的item + + for(int row = 0; row < sourceModel->rowCount(); row++) + { + QList itemList; + for(int col = 0; col < sourceModel->columnCount(); col++) + { + QStandardItem* item = sourceModel->item(row, col); + if(item) + { + QStandardItem* newItem = new QStandardItem(item->text()); + itemList.push_back(newItem); + } + } + destModel->appendRow(itemList); + } } void dpConfigurationDialog::setPanel(DataPanel* pPanel) { m_pDataPanel = pPanel; + copyModelData(pPanel->m_cofigurationResults.m_pModel_dataType, m_pModel_typeSelected); + // m_pModel_typeSelected = pPanel->m_cofigurationResults.m_pModel_dataType; + // if(m_pModel_typeSelected) + // ui->typeSelectedList->setModel(m_pModel_typeSelected); } void dpConfigurationDialog::onBtnClicked_tabBtn() @@ -91,6 +151,13 @@ void dpConfigurationDialog::onBtnClicked_confirm() { hide(); emit sgl_hide(); + + if(m_pDataPanel) + { + //m_pDataPanel->m_cofigurationResults.m_pModel_dataType = m_pModel_typeSelected; + copyModelData(m_pModel_typeSelected, m_pDataPanel->m_cofigurationResults.m_pModel_dataType); + m_pDataPanel->configurationComplete(); + } } void dpConfigurationDialog::onBtnClicked_cancle() @@ -98,3 +165,43 @@ void dpConfigurationDialog::onBtnClicked_cancle() hide(); emit sgl_hide(); } + +void dpConfigurationDialog::onItemClicked_typeSource(const QModelIndex& index) +{ + QStandardItem* item = m_pModel_typeSource->itemFromIndex(index); + if(item) + { + bool bIsHad = false; + for(int i = 0; i< m_pModel_typeSelected->rowCount(); i++) + { + QString itemText = m_pModel_typeSelected->item(i, 0)->text(); + if(itemText == item->text()) + { + bIsHad = true; + break; + } + } + + if(!bIsHad && m_pModel_typeSelected) + { + QStandardItem* newItem = new QStandardItem(item->text()); + m_pModel_typeSelected->appendRow(newItem); + ui->typeSelectedList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); + } + } +} + +void dpConfigurationDialog::onBtnClicked_remove_type() +{ + QItemSelectionModel* selectionModel = ui->typeSelectedList->selectionModel(); + if(selectionModel && m_pModel_typeSelected) + { + int nCurrentRow = selectionModel->currentIndex().row(); + QList items = m_pModel_typeSelected->takeRow(nCurrentRow); + for(QStandardItem* item: items) + delete item; + } +} + +void dpConfigurationDialog::onBtnClicked_remove_source() +{} diff --git a/dataPanel/dpConfigurationDialog.h b/dataPanel/dpConfigurationDialog.h index 82121d0..0a6545a 100644 --- a/dataPanel/dpConfigurationDialog.h +++ b/dataPanel/dpConfigurationDialog.h @@ -10,6 +10,7 @@ class dpConfigurationDialog; QT_END_NAMESPACE class DataPanel; +class QStandardItemModel; class dpConfigurationDialog : public QDialog { @@ -28,14 +29,23 @@ public slots: void onBtnClicked_tabBtn(); void onBtnClicked_confirm(); void onBtnClicked_cancle(); + void onBtnClicked_remove_type(); + void onBtnClicked_remove_source(); + + void onItemClicked_typeSource(const QModelIndex&); private: void initialize(); + void copyModelData(QStandardItemModel*, QStandardItemModel*); Ui::dpConfigurationDialog* ui; QPushButton* m_curActiveTab; DataPanel* m_pDataPanel; + + //Models + QStandardItemModel* m_pModel_typeSource; + QStandardItemModel* m_pModel_typeSelected; }; diff --git a/dataPanel/dpGlobals.h b/dataPanel/dpGlobals.h index 3cbb86c..d595382 100644 --- a/dataPanel/dpGlobals.h +++ b/dataPanel/dpGlobals.h @@ -14,4 +14,23 @@ enum DataPanelType map //地图 }; +#include +struct configurationResults +{ + QStandardItemModel* m_pModel_dataType; + QStandardItemModel* m_pModel_dataSource; + + configurationResults() + { + m_pModel_dataType = nullptr; + m_pModel_dataSource = nullptr; + } + + void setParent(QObject* parent) + { + m_pModel_dataType = new QStandardItemModel(parent); + m_pModel_dataSource = new QStandardItemModel(parent); + } +}; + #endif diff --git a/include/dataPanel.h b/include/dataPanel.h index ab3af86..aa9e926 100644 --- a/include/dataPanel.h +++ b/include/dataPanel.h @@ -66,6 +66,8 @@ public: void setDateTime(const QDateTime&); void setTimeRange(TimeUnit); + void configurationComplete(); + protected: bool event(QEvent*); /*void keyPressEvent(QKeyEvent*); @@ -108,6 +110,9 @@ private: PanelToolWidget* m_pToolWidget; PanelConfigurationWidget* m_pConfigurationWidget; CustomBorderContainer* m_pCustomBorderContainer; + + friend class dpConfigurationDialog; + configurationResults m_cofigurationResults; }; #endif diff --git a/resource/PowerMaster.qrc b/resource/PowerMaster.qrc index e730043..51b7772 100644 --- a/resource/PowerMaster.qrc +++ b/resource/PowerMaster.qrc @@ -1,5 +1,7 @@ + images/btn_remove_default.png + images/btn_remove_hover.png images/icon_double-left.png images/icon_double-right.png images/icon_left.png diff --git a/resource/images/btn_remove_default.png b/resource/images/btn_remove_default.png new file mode 100644 index 0000000..bd10845 Binary files /dev/null and b/resource/images/btn_remove_default.png differ diff --git a/resource/images/btn_remove_hover.png b/resource/images/btn_remove_hover.png new file mode 100644 index 0000000..5aa7183 Binary files /dev/null and b/resource/images/btn_remove_hover.png differ diff --git a/source/dashboardFrame.cpp b/source/dashboardFrame.cpp index 3199c34..3c26bfb 100644 --- a/source/dashboardFrame.cpp +++ b/source/dashboardFrame.cpp @@ -462,6 +462,7 @@ void DashboardFrame::openPanelConfigurationDialog(DataPanel* pPanel) connect(m_pPanelConfigurationDialog, SIGNAL(sgl_hide()), this, SLOT(onSignal_subDialogClose())); } + m_pPanelConfigurationDialog->setPanel(pPanel); showTransparentMask(); int nX = (ui->navigationPanel->width() - m_pPanelConfigurationDialog->width()) * 0.5; int nY = ui->navigationPanel->y() + ui->navigationPanel->height() * 0.5; diff --git a/source/dataPanel.cpp b/source/dataPanel.cpp index 8c397ad..f46635f 100644 --- a/source/dataPanel.cpp +++ b/source/dataPanel.cpp @@ -75,6 +75,7 @@ DataPanel::DataPanel(QWidget *parent, DataPanelType type) m_pToolMenu->addAction(QString::fromWCharArray(L"放置最后"), this, SLOT(onAction_moveToBack())); createDataWidget(type); + m_cofigurationResults.setParent(this); } DataPanel::~DataPanel() @@ -337,6 +338,12 @@ void DataPanel::setTimeRange(TimeUnit unit) baseWidget->setTimeRange(unit); } +void DataPanel::configurationComplete() +{ + if(m_pConfigurationWidget->isVisible()) + m_pConfigurationWidget->hide(); +} + void DataPanel::onToolBtnClicked_setting() { emit sgl_openCofigurationDialog(this); diff --git a/ui/dpConfigurationDialog.ui b/ui/dpConfigurationDialog.ui index 3c2b927..71e488d 100644 --- a/ui/dpConfigurationDialog.ui +++ b/ui/dpConfigurationDialog.ui @@ -56,7 +56,7 @@ border:1px solid rgb(67,160,249); QTreeView { -padding-top:6px; +padding:6px; font: 12pt "黑体"; color: rgb(250, 250, 250); border:0px; @@ -92,7 +92,7 @@ QTreeView::branch:open:has-children:has-siblings { QTableView { -padding-top:6px; +padding:6px; font: 12pt "黑体"; color: rgb(250, 250, 250); border:0px; @@ -106,17 +106,17 @@ height:25px; } QTableView::item:selected { color: rgb(250, 250, 250); -background-color: transparent; +background-color: rgba(67,160,249, 15); border:0px; } QTableView::item:hover { -background-color: rgba(67,160,249, 30); +background-color: rgba(67,160,249, 15); border:0px; } QListView { -padding-top:6px; +padding:6px; font: 12pt "黑体"; color: rgb(250, 250, 250); border:0px; @@ -303,16 +303,6 @@ background-color:transparent; - - - - 0 - 55 - 251 - 261 - - - @@ -322,6 +312,67 @@ background-color:transparent; 261 + + Qt::FocusPolicy::NoFocus + + + false + + + false + + + false + + + false + + + 25 + + + false + + + + + + 0 + 55 + 251 + 261 + + + + Qt::FocusPolicy::NoFocus + + + + + + 495 + 30 + 24 + 24 + + + + QPushButton +{ + border-image: url(:/images/btn_remove_hover.png); +} +QPushButton:hover +{ + border-image: url(:/images/btn_remove_default.png); +} +QPushButton:pressed +{ + border-image: url(:/images/btn_remove_hover.png); +} + + + + @@ -353,6 +404,9 @@ background-color:transparent; 261 + + Qt::FocusPolicy::NoFocus + @@ -363,6 +417,60 @@ background-color:transparent; 261 + + Qt::FocusPolicy::NoFocus + + + QAbstractItemView::SelectionBehavior::SelectRows + + + false + + + 200 + + + false + + + false + + + 25 + + + false + + + false + + + + + + 495 + 30 + 24 + 24 + + + + QPushButton +{ + border-image: url(:/images/btn_remove_hover.png); +} +QPushButton:hover +{ + border-image: url(:/images/btn_remove_default.png); +} +QPushButton:pressed +{ + border-image: url(:/images/btn_remove_hover.png); +} + + + + @@ -446,6 +554,8 @@ background-color:rgb(67,160,249); - + + +