350 lines
8.0 KiB
C++
350 lines
8.0 KiB
C++
#include "AddParamSetting.h"
|
|
|
|
#include "../DockTitleBar.h"
|
|
#include "../DockWidget.h"
|
|
|
|
#include <qcombobox.h>
|
|
#include <QDoubleSpinBox>
|
|
#include <QSpinBox>
|
|
|
|
#include <qsettings.h>
|
|
#include <qdebug.h>
|
|
|
|
AddParamSetting::AddParamSetting(const QString& strDir, QWidget* parent)
|
|
: QWidget(parent)
|
|
{
|
|
ui.setupUi(this);
|
|
|
|
setWindowFlags(/*Qt::FramelessWindowHint | */Qt::Window);
|
|
|
|
m_strDir = strDir;
|
|
|
|
QHeaderView* horizontalHeader = ui.tableWidget->horizontalHeader();
|
|
QColor headerColor = QColor(100, 100, 100); // »ÒÉ«
|
|
horizontalHeader->setStyleSheet(QString("QHeaderView::section {background-color: %1;}").arg(headerColor.name()));
|
|
horizontalHeader->setStretchLastSection(true);
|
|
|
|
connect(ui.pushButton, &QPushButton::clicked, this, &AddParamSetting::slotButtonAdd);
|
|
connect(ui.pushButton_2, &QPushButton::clicked, this, &AddParamSetting::slotButtonRemove);
|
|
connect(ui.pushButton_3, &QPushButton::clicked, this, &AddParamSetting::slotButtonCommit);
|
|
|
|
InitTable();
|
|
}
|
|
|
|
AddParamSetting::~AddParamSetting()
|
|
{
|
|
}
|
|
|
|
void AddParamSetting::AttachDock(DockWidget* dockWidget)
|
|
{
|
|
if (nullptr == dockWidget) {
|
|
qDebug() << __FUNCTION__ << "dockwidget is nullptr";
|
|
return;
|
|
}
|
|
|
|
dockWidget->SetDockWidgetTitleBar(nullptr);
|
|
dockWidget->setWidget(this);
|
|
|
|
DockTitleBar* dockTitleBar = new DockTitleBar;
|
|
|
|
dockTitleBar->SetTitle(tr("ParamSetting"));
|
|
|
|
dockWidget->SetDockWidgetTitleBar(dockTitleBar);
|
|
}
|
|
|
|
void AddParamSetting::InitTable()
|
|
{
|
|
QSettings sett(m_strDir, QSettings::IniFormat);
|
|
|
|
QStringList listGroup = sett.childGroups();
|
|
|
|
for each (QString strGroup in listGroup)
|
|
{
|
|
sett.beginGroup(strGroup);
|
|
|
|
QString strName = sett.value("Name").toString();
|
|
QString strDes = sett.value("Des").toString();
|
|
QString strType = sett.value("Type").toString();
|
|
QString strMaxValue = sett.value("MaxValue").toString();
|
|
QString strMinValue = sett.value("MinValue").toString();
|
|
QString strDecimal = sett.value("Decimal").toString();
|
|
QString strValue = sett.value("Value","0").toString();
|
|
|
|
QStringList values;
|
|
values << strName << strDes << strType << strMaxValue << strMinValue << strDecimal << strValue;
|
|
|
|
InsertRow(values);
|
|
|
|
sett.endGroup();
|
|
}
|
|
}
|
|
|
|
void AddParamSetting::InsertRow()
|
|
{
|
|
int iRow = ui.tableWidget->rowCount();
|
|
ui.tableWidget->insertRow(iRow);
|
|
|
|
int iCol = 0;
|
|
// ²ÎÊýÃû³Æ
|
|
{
|
|
QString strText = u8"ÊäÈë²ÎÊýÃû³Æ";
|
|
ui.tableWidget->setItem(iRow, iCol, new QTableWidgetItem(strText));
|
|
iCol++;
|
|
}
|
|
|
|
// ²ÎÊýÃèÊö
|
|
{
|
|
QString strText = u8"ÊäÈë²ÎÊýÃèÊö";
|
|
ui.tableWidget->setItem(iRow, iCol, new QTableWidgetItem(strText));
|
|
iCol++;
|
|
}
|
|
|
|
// Êý¾ÝÀàÐÍ
|
|
{
|
|
QStringList listType;
|
|
listType << "String" << "Int" << "Float";
|
|
|
|
QComboBox* pCombox = new QComboBox;
|
|
pCombox->addItems(listType);
|
|
pCombox->setCurrentIndex(0);
|
|
pCombox->setProperty("Row", iRow);
|
|
|
|
ui.tableWidget->setCellWidget(iRow, iCol, pCombox);
|
|
|
|
connect(pCombox, &QComboBox::currentTextChanged, this, &AddParamSetting::slotSelectDataType);
|
|
iCol++;
|
|
}
|
|
|
|
// ×î´óÖµ
|
|
{
|
|
QDoubleSpinBox* pValue = new QDoubleSpinBox;
|
|
pValue->setDisabled(true);
|
|
pValue->setValue(100);
|
|
ui.tableWidget->setCellWidget(iRow, iCol, pValue);
|
|
iCol++;
|
|
}
|
|
|
|
// ×îСֵ
|
|
{
|
|
QDoubleSpinBox* pValue = new QDoubleSpinBox;
|
|
pValue->setDisabled(true);
|
|
pValue->setValue(1);
|
|
ui.tableWidget->setCellWidget(iRow, iCol, pValue);
|
|
iCol++;
|
|
}
|
|
|
|
// СÊýµãÓÐЧλ
|
|
{
|
|
QSpinBox* pValue = new QSpinBox;
|
|
pValue->setDisabled(true);
|
|
pValue->setValue(0);
|
|
ui.tableWidget->setCellWidget(iRow, iCol, pValue);
|
|
iCol++;
|
|
}
|
|
|
|
// ²ÎÊýÃèÊö
|
|
{
|
|
QString strText = u8"ÊäÈë²ÎÊýÖµ";
|
|
ui.tableWidget->setItem(iRow, iCol, new QTableWidgetItem(strText));
|
|
}
|
|
}
|
|
|
|
void AddParamSetting::InsertRow(QStringList values)
|
|
{
|
|
int iRow = ui.tableWidget->rowCount();
|
|
ui.tableWidget->insertRow(iRow);
|
|
|
|
int iCol = 0;
|
|
// ²ÎÊýÃû³Æ
|
|
{
|
|
QString strText = values[0];
|
|
ui.tableWidget->setItem(iRow, iCol, new QTableWidgetItem(strText));
|
|
iCol++;
|
|
}
|
|
|
|
// ²ÎÊýÃèÊö
|
|
{
|
|
QString strText = values[1];
|
|
ui.tableWidget->setItem(iRow, iCol, new QTableWidgetItem(strText));
|
|
iCol++;
|
|
}
|
|
|
|
// Êý¾ÝÀàÐÍ
|
|
{
|
|
QStringList listType;
|
|
listType << "String" << "Int" << "Float";
|
|
|
|
QComboBox* pCombox = new QComboBox;
|
|
pCombox->addItems(listType);
|
|
pCombox->setCurrentText(values[2]);
|
|
pCombox->setProperty("Row", iRow);
|
|
|
|
ui.tableWidget->setCellWidget(iRow, iCol, pCombox);
|
|
|
|
connect(pCombox, &QComboBox::currentTextChanged, this, &AddParamSetting::slotSelectDataType);
|
|
iCol++;
|
|
}
|
|
|
|
// ×î´óÖµ
|
|
{
|
|
QDoubleSpinBox* pValue = new QDoubleSpinBox;
|
|
|
|
if (values[2] == "String")
|
|
{
|
|
pValue->setDisabled(true);
|
|
}
|
|
|
|
pValue->setValue(values[3].toFloat());
|
|
|
|
ui.tableWidget->setCellWidget(iRow, iCol, pValue);
|
|
iCol++;
|
|
}
|
|
|
|
// ×îСֵ
|
|
{
|
|
QDoubleSpinBox* pValue = new QDoubleSpinBox;
|
|
|
|
if (values[2] == "String")
|
|
{
|
|
pValue->setDisabled(true);
|
|
}
|
|
|
|
pValue->setValue(values[4].toFloat());
|
|
|
|
ui.tableWidget->setCellWidget(iRow, iCol, pValue);
|
|
|
|
iCol++;
|
|
}
|
|
|
|
// СÊýµãÓÐЧλ
|
|
{
|
|
QSpinBox* pValue = new QSpinBox;
|
|
if (values[2] == "String")
|
|
{
|
|
pValue->setDisabled(true);
|
|
}
|
|
|
|
pValue->setValue(values[5].toFloat());
|
|
|
|
ui.tableWidget->setCellWidget(iRow, iCol, pValue);
|
|
|
|
iCol++;
|
|
}
|
|
|
|
// ²ÎÊý³õʼֵ
|
|
{
|
|
QString strText = values[6];
|
|
ui.tableWidget->setItem(iRow, iCol, new QTableWidgetItem(strText));
|
|
}
|
|
}
|
|
|
|
void AddParamSetting::RemoveRow()
|
|
{
|
|
int iRow = ui.tableWidget->currentRow();
|
|
if (iRow >= 0)
|
|
{
|
|
ui.tableWidget->removeRow(iRow);
|
|
|
|
ResetTable();
|
|
}
|
|
}
|
|
|
|
void AddParamSetting::ResetTable()
|
|
{
|
|
for (int iRow = 0; iRow < ui.tableWidget->rowCount(); iRow++)
|
|
{
|
|
QWidget* pCellWgt = ui.tableWidget->cellWidget(iRow, 2);
|
|
pCellWgt->setProperty("Row", iRow);
|
|
}
|
|
}
|
|
|
|
void AddParamSetting::slotButtonAdd()
|
|
{
|
|
InsertRow();
|
|
}
|
|
|
|
void AddParamSetting::slotButtonRemove()
|
|
{
|
|
RemoveRow();
|
|
}
|
|
|
|
void AddParamSetting::slotButtonCommit()
|
|
{
|
|
QSettings sett(m_strDir, QSettings::IniFormat);
|
|
sett.clear();
|
|
sett.sync();
|
|
|
|
for (int iRow = 0; iRow < ui.tableWidget->rowCount(); iRow++)
|
|
{
|
|
QString strGroup = QString::number(iRow + 1);
|
|
QString strName = ui.tableWidget->item(iRow, 0)->text();
|
|
QString strDes = ui.tableWidget->item(iRow, 1)->text();
|
|
QString strType = ((QComboBox*)ui.tableWidget->cellWidget(iRow, 2))->currentText();
|
|
|
|
sett.beginGroup(strGroup);
|
|
|
|
sett.setValue("Name", strName);
|
|
sett.setValue("Des", strDes);
|
|
sett.setValue("Type", strType);
|
|
|
|
QDoubleSpinBox* pMaxValue = (QDoubleSpinBox*)ui.tableWidget->cellWidget(iRow, 3);
|
|
sett.setValue("MaxValue", pMaxValue->value());
|
|
|
|
QDoubleSpinBox* pMinValue = (QDoubleSpinBox*)ui.tableWidget->cellWidget(iRow, 4);
|
|
sett.setValue("MinValue", pMinValue->value());
|
|
|
|
QSpinBox* pDecimalValue = (QSpinBox*)ui.tableWidget->cellWidget(iRow, 5);
|
|
sett.setValue("Decimal", pDecimalValue->value());
|
|
|
|
sett.setValue("Value", ui.tableWidget->item(iRow, 6)->text());
|
|
|
|
sett.endGroup();
|
|
}
|
|
}
|
|
|
|
void AddParamSetting::slotSelectDataType(const QString& strType)
|
|
{
|
|
QObject* pSender = sender();
|
|
int iRow = pSender->property("Row").toInt();
|
|
if (iRow < ui.tableWidget->rowCount())
|
|
{
|
|
if ("Int" == strType)
|
|
{
|
|
QDoubleSpinBox* pMaxValue = (QDoubleSpinBox*)ui.tableWidget->cellWidget(iRow, 3);
|
|
pMaxValue->setDecimals(0);
|
|
pMaxValue->setDisabled(false);
|
|
|
|
QDoubleSpinBox* pMinValue = (QDoubleSpinBox*)ui.tableWidget->cellWidget(iRow, 4);
|
|
pMinValue->setDecimals(0);
|
|
pMinValue->setDisabled(false);
|
|
|
|
QSpinBox* pDecimalValue = (QSpinBox*)ui.tableWidget->cellWidget(iRow, 5);
|
|
pDecimalValue->setDisabled(true);
|
|
}
|
|
else if ("Float" == strType)
|
|
{
|
|
QDoubleSpinBox* pMaxValue = (QDoubleSpinBox*)ui.tableWidget->cellWidget(iRow, 3);
|
|
pMaxValue->setDecimals(0);
|
|
pMaxValue->setDisabled(false);
|
|
|
|
QDoubleSpinBox* pMinValue = (QDoubleSpinBox*)ui.tableWidget->cellWidget(iRow, 4);
|
|
pMinValue->setDecimals(0);
|
|
pMinValue->setDisabled(false);
|
|
|
|
QSpinBox* pDecimalValue = (QSpinBox*)ui.tableWidget->cellWidget(iRow, 5);
|
|
pDecimalValue->setDisabled(false);
|
|
}
|
|
else
|
|
{
|
|
QDoubleSpinBox* pMaxValue = (QDoubleSpinBox*)ui.tableWidget->cellWidget(iRow, 3);
|
|
pMaxValue->setDisabled(true);
|
|
|
|
QDoubleSpinBox* pMinValue = (QDoubleSpinBox*)ui.tableWidget->cellWidget(iRow, 4);
|
|
pMinValue->setDisabled(true);
|
|
|
|
QSpinBox* pDecimalValue = (QSpinBox*)ui.tableWidget->cellWidget(iRow, 5);
|
|
pDecimalValue->setDisabled(true);
|
|
}
|
|
}
|
|
}
|