208 lines
7.1 KiB
C++
208 lines
7.1 KiB
C++
#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);
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
initialize();
|
|
}
|
|
|
|
dpConfigurationDialog::~dpConfigurationDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void dpConfigurationDialog::initialize()
|
|
{
|
|
ui->tabDataType->setProperty("index", 0);
|
|
connect(ui->tabDataType, SIGNAL(clicked()), this, SLOT(onBtnClicked_tabBtn()));
|
|
ui->tabDataSource->setProperty("index", 1);
|
|
connect(ui->tabDataSource, SIGNAL(clicked()), this, SLOT(onBtnClicked_tabBtn()));
|
|
ui->tabDisplaySetting->setProperty("index", 2);
|
|
connect(ui->tabDisplaySetting, SIGNAL(clicked()), this, SLOT(onBtnClicked_tabBtn()));
|
|
m_curActiveTab = ui->tabDataType;
|
|
|
|
ui->stackedWidget->setCurrentIndex(0);
|
|
|
|
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()
|
|
{
|
|
QPushButton* pTab = qobject_cast<QPushButton*>(sender());
|
|
if(pTab == m_curActiveTab)
|
|
return;
|
|
|
|
if(m_curActiveTab)
|
|
{
|
|
m_curActiveTab->setStyleSheet("QPushButton\n"
|
|
"{\n"
|
|
"color: rgb(250, 250, 250);\n"
|
|
"font: 700 12pt \"黑体\";\n"
|
|
"border:0px;\n"
|
|
"background-color:transparent;\n"
|
|
"}\n"
|
|
"QPushButton:hover\n"
|
|
"{\n"
|
|
"}\n"
|
|
"QPushButton:pressed\n"
|
|
"{\n"
|
|
"}");
|
|
}
|
|
if(pTab)
|
|
{
|
|
pTab->setStyleSheet("QPushButton\n"
|
|
"{\n"
|
|
"color: rgb(250, 250, 250);\n"
|
|
"font: 700 12pt \"黑体\";\n"
|
|
"border:1px solid rgb(200,200,200);\n"
|
|
"border-bottom:0px;\n"
|
|
"background-color:rgba(36,43,50, 250);\n"
|
|
"}\n"
|
|
"QPushButton:hover\n"
|
|
"{\n"
|
|
"}\n"
|
|
"QPushButton:pressed\n"
|
|
"{\n"
|
|
"}");
|
|
|
|
int nIndex = pTab->property("index").toInt();
|
|
ui->stackedWidget->setCurrentIndex(nIndex);
|
|
}
|
|
m_curActiveTab = pTab;
|
|
|
|
}
|
|
|
|
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()
|
|
{
|
|
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()
|
|
{}
|