|
|
#include "nmWxGridDlg.h"
|
|
|
|
|
|
#include <QDebug>
|
|
|
#include <QVBoxLayout>
|
|
|
#include <QFormLayout>
|
|
|
#include <QPushButton>
|
|
|
#include <QLineEdit>
|
|
|
#include <QLabel>
|
|
|
#include <QComboBox>
|
|
|
#include <QDoubleValidator>
|
|
|
|
|
|
nmWxGridDlg::nmWxGridDlg(double *pGridSize, int *pGridType):
|
|
|
m_pGridSize(pGridSize), m_pGridType(pGridType)
|
|
|
{
|
|
|
// 设置初始值
|
|
|
m_dGridSizeTmp = pGridSize ? *pGridSize : 0.5;
|
|
|
m_iGridTypeTmp = pGridType ? *pGridType : NM_Grid_Triangle;
|
|
|
this->initUI();
|
|
|
}
|
|
|
|
|
|
void nmWxGridDlg::on_save()
|
|
|
{
|
|
|
// 检查第1列是否都写了值,如何不全则不能提交
|
|
|
qDebug() << "=================" << m_dGridSizeTmp << " " << m_iGridTypeTmp;
|
|
|
if (m_pGridSize != NULL) {
|
|
|
*m_pGridSize = m_dGridSizeTmp;
|
|
|
}
|
|
|
if (m_pGridType != NULL) {
|
|
|
*m_pGridType = m_iGridTypeTmp;
|
|
|
}
|
|
|
this->accept();
|
|
|
}
|
|
|
|
|
|
void nmWxGridDlg::on_gridSizeChanged(QString newValue)
|
|
|
{
|
|
|
qDebug() << newValue;
|
|
|
m_dGridSizeTmp = newValue.toDouble();
|
|
|
}
|
|
|
|
|
|
void nmWxGridDlg::on_gridTypeChanged(int index)
|
|
|
{
|
|
|
m_iGridTypeTmp = index;
|
|
|
}
|
|
|
|
|
|
void nmWxGridDlg::initUI()
|
|
|
{
|
|
|
QVBoxLayout* mainLayout = new QVBoxLayout;
|
|
|
this->setLayout(mainLayout);
|
|
|
// 设置内容区域
|
|
|
QFormLayout* contentLayout = new QFormLayout;
|
|
|
contentLayout->addRow(new QLabel(tr("GridType")), initGridTypeComboBox());
|
|
|
contentLayout->addRow(new QLabel(tr("GridSize")), initGridSizeEdit());
|
|
|
mainLayout->addLayout(contentLayout);
|
|
|
// 底部按钮
|
|
|
QHBoxLayout* hLayout = new QHBoxLayout;
|
|
|
QPushButton* saveBT = new QPushButton("Save");
|
|
|
QPushButton* cancelBT = new QPushButton("Cancel");
|
|
|
connect(saveBT, SIGNAL(clicked()), this, SLOT(on_save()));
|
|
|
connect(cancelBT, SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
hLayout->addStretch();
|
|
|
hLayout->addWidget(saveBT);
|
|
|
hLayout->addWidget(cancelBT);
|
|
|
mainLayout->addLayout(hLayout);
|
|
|
}
|
|
|
|
|
|
QLineEdit *nmWxGridDlg::initGridSizeEdit()
|
|
|
{
|
|
|
QLineEdit* pEdit = new QLineEdit;
|
|
|
pEdit->setText(QString::number(m_dGridSizeTmp));
|
|
|
pEdit->setValidator(new QDoubleValidator(0, 100, 10));
|
|
|
pEdit->setPlaceholderText(QString("{%1 - %2}").arg(0).arg(100));
|
|
|
// 监听变化
|
|
|
connect(pEdit, SIGNAL(textChanged(QString)), this, SLOT(on_gridSizeChanged(QString)));
|
|
|
return pEdit;
|
|
|
}
|
|
|
|
|
|
QComboBox *nmWxGridDlg::initGridTypeComboBox()
|
|
|
{
|
|
|
QComboBox* pComboBox = new QComboBox;
|
|
|
QStringList options;
|
|
|
options << tr("Triangle") << tr("Quadrilateral") << tr("Hexagon");
|
|
|
pComboBox->addItems(options);
|
|
|
pComboBox->setCurrentIndex(m_iGridTypeTmp);
|
|
|
// 监听变化
|
|
|
connect(pComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_gridTypeChanged(int)));
|
|
|
return pComboBox;
|
|
|
}
|