140 lines
3.6 KiB
C++
140 lines
3.6 KiB
C++
#include "dialog_userinput.h"
|
|
#include "ui_dialog_userinput.h"
|
|
#include <QRegExpValidator>
|
|
#include <QMessageBox>
|
|
|
|
Dialog_UserInput::Dialog_UserInput(ui_helper::value_type type, const QString &title, const wchar_t* desc, QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::Dialog_UserInput),
|
|
m_type(type),
|
|
m_title(title)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
ui->radioButton_yes->setVisible(false);
|
|
ui->radioButton_no->setVisible(false);
|
|
ui->lineEdit->setVisible(false);
|
|
ui->comboBox->setVisible(false);
|
|
if (type == ui_helper::VAL_TYPE_BOOL)
|
|
{
|
|
ui->label->setText(QString::fromStdWString(desc));
|
|
ui->radioButton_yes->setVisible(true);
|
|
ui->radioButton_no->setVisible(true);
|
|
}
|
|
else if (type == ui_helper::VAL_TYPE_INT || type == ui_helper::VAL_TYPE_FLOAT || type == ui_helper::VAL_TYPE_STRING)
|
|
{
|
|
ui->label->setText(QString::fromStdWString(desc));
|
|
ui->lineEdit->setVisible(true);
|
|
}
|
|
else if (type == ui_helper::VAL_TYPE_TIPS_VAL)
|
|
{
|
|
ui_helper::PINFOTIPS p = (ui_helper::PINFOTIPS)desc;
|
|
while(*(p->desc) != '\0')
|
|
{
|
|
ui->comboBox->addItem(QString::number(*(p->desc)));
|
|
p->desc++;
|
|
}
|
|
|
|
ui->label->setText(QString::fromStdWString(p->info));
|
|
ui->comboBox->setVisible(true);
|
|
}
|
|
|
|
setWindowTitle(m_title);
|
|
|
|
QFont ft;
|
|
ft.setPointSize(15);
|
|
this->setFont(ft);
|
|
|
|
|
|
ui->lineEdit->setValidator(new QRegExpValidator(QRegExp("[0-9]+$")));
|
|
}
|
|
|
|
Dialog_UserInput::~Dialog_UserInput()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
parameter *Dialog_UserInput::getParam()
|
|
{
|
|
UserInputParams *param = new UserInputParams(m_type);
|
|
if (m_type == ui_helper::VAL_TYPE_BOOL)
|
|
{
|
|
if (ui->radioButton_yes->isChecked())
|
|
param->m_bData = true;
|
|
else if (ui->radioButton_no->isChecked())
|
|
param->m_bData = false;
|
|
}
|
|
else if (m_type == ui_helper::VAL_TYPE_INT)
|
|
{
|
|
param->m_iData = ui->lineEdit->text().toInt();
|
|
}
|
|
else if (m_type == ui_helper::VAL_TYPE_FLOAT)
|
|
{
|
|
param->m_fData = ui->lineEdit->text().toDouble();
|
|
}
|
|
else if (m_type == ui_helper::VAL_TYPE_STRING)
|
|
{
|
|
param->m_sData = ui->lineEdit->text().toStdWString();
|
|
}
|
|
else if (m_type == ui_helper::VAL_TYPE_TIPS_VAL)
|
|
{
|
|
param->m_iData = ui->comboBox->currentText().toInt();
|
|
}
|
|
|
|
return param;
|
|
}
|
|
|
|
void Dialog_UserInput::on_pbtn_yes_clicked()
|
|
{
|
|
if (ui->lineEdit->text().isEmpty() && (m_type == ui_helper::VAL_TYPE_INT || m_type == ui_helper::VAL_TYPE_FLOAT || m_type == ui_helper::VAL_TYPE_STRING))
|
|
{
|
|
QMessageBox::information(this, tr("tips"), tr("please input valid contents"));
|
|
return;
|
|
}
|
|
|
|
getParam();
|
|
accept();
|
|
}
|
|
|
|
void Dialog_UserInput::on_pbtn_no_clicked()
|
|
{
|
|
reject();
|
|
}
|
|
|
|
|
|
UserInputParams::UserInputParams(ui_helper::value_type type)
|
|
{
|
|
m_type = type;
|
|
}
|
|
|
|
UserInputParams::~UserInputParams()
|
|
{
|
|
|
|
}
|
|
|
|
size_t UserInputParams::get_size()
|
|
{
|
|
if (m_type == ui_helper::VAL_TYPE_BOOL)
|
|
return sizeof(bool);
|
|
if (m_type == ui_helper::VAL_TYPE_INT || m_type == ui_helper::VAL_TYPE_TIPS_VAL)
|
|
return sizeof(int);
|
|
if (m_type == ui_helper::VAL_TYPE_FLOAT)
|
|
return sizeof(double);
|
|
if (m_type == ui_helper::VAL_TYPE_STRING)
|
|
return m_sData.size() + 1;
|
|
return 0;
|
|
}
|
|
|
|
void *UserInputParams::get_data()
|
|
{
|
|
if (m_type == ui_helper::VAL_TYPE_BOOL)
|
|
return &m_bData;
|
|
if (m_type == ui_helper::VAL_TYPE_INT || m_type == ui_helper::VAL_TYPE_TIPS_VAL)
|
|
return &m_iData;
|
|
if (m_type == ui_helper::VAL_TYPE_FLOAT)
|
|
return &m_fData;
|
|
if (m_type == ui_helper::VAL_TYPE_STRING)
|
|
return (void*)m_sData.c_str();
|
|
return nullptr;
|
|
}
|