将dataPanel配置相关组件改为Model/View体系

This commit is contained in:
duanshengchao 2025-01-16 20:26:17 +08:00
parent 5a92f5cb90
commit edde3a25a8
10 changed files with 277 additions and 16 deletions

View File

@ -1,12 +1,15 @@
#include "dpConfigurationDialog.h"
#include "ui_dpConfigurationDialog.h"
#include "dataPanel.h"
#include <QStandardItemModel>
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<QStandardItem*> 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<QStandardItem*> items = m_pModel_typeSelected->takeRow(nCurrentRow);
for(QStandardItem* item: items)
delete item;
}
}
void dpConfigurationDialog::onBtnClicked_remove_source()
{}

View File

@ -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;
};

View File

@ -14,4 +14,23 @@ enum DataPanelType
map //地图
};
#include <QStandardItemModel>
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

View File

@ -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

View File

@ -1,5 +1,7 @@
<RCC>
<qresource prefix="/">
<file>images/btn_remove_default.png</file>
<file>images/btn_remove_hover.png</file>
<file>images/icon_double-left.png</file>
<file>images/icon_double-right.png</file>
<file>images/icon_left.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

View File

@ -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;

View File

@ -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);

View File

@ -56,7 +56,7 @@ border:1px solid rgb(67,160,249);
QTreeView
{
padding-top:6px;
padding:6px;
font: 12pt &quot;黑体&quot;;
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 &quot;黑体&quot;;
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 &quot;黑体&quot;;
color: rgb(250, 250, 250);
border:0px;
@ -303,16 +303,6 @@ background-color:transparent;
<string notr="true"/>
</property>
</widget>
<widget class="QListWidget" name="dataTypeList">
<property name="geometry">
<rect>
<x>0</x>
<y>55</y>
<width>251</width>
<height>261</height>
</rect>
</property>
</widget>
<widget class="QTableView" name="typeSelectedList">
<property name="geometry">
<rect>
@ -322,6 +312,67 @@ background-color:transparent;
<height>261</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::NoFocus</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>25</number>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>false</bool>
</attribute>
</widget>
<widget class="QListView" name="typeSourceList">
<property name="geometry">
<rect>
<x>0</x>
<y>55</y>
<width>251</width>
<height>261</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::NoFocus</enum>
</property>
</widget>
<widget class="QPushButton" name="btnReomve_type">
<property name="geometry">
<rect>
<x>495</x>
<y>30</y>
<width>24</width>
<height>24</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">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);
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<widget class="QWidget" name="pageDataSource">
@ -353,6 +404,9 @@ background-color:transparent;
<height>261</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::NoFocus</enum>
</property>
</widget>
<widget class="QTableView" name="dataSelectedList">
<property name="geometry">
@ -363,6 +417,60 @@ background-color:transparent;
<height>261</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::FocusPolicy::NoFocus</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>200</number>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>25</number>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderShowSortIndicator" stdset="0">
<bool>false</bool>
</attribute>
</widget>
<widget class="QPushButton" name="btnReomve_source">
<property name="geometry">
<rect>
<x>495</x>
<y>30</y>
<width>24</width>
<height>24</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">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);
}</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<widget class="QWidget" name="pageDisplaySetting">
@ -446,6 +554,8 @@ background-color:rgb(67,160,249);
</item>
</layout>
</widget>
<resources/>
<resources>
<include location="../resource/PowerMaster.qrc"/>
</resources>
<connections/>
</ui>