DialogAlongLine - check if names of points don't equal.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-14 13:21:46 +03:00
parent 81f77054af
commit 0e3da0d902
6 changed files with 60 additions and 30 deletions

View File

@ -63,6 +63,10 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent)
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogAlongLine::FormulaTextChanged);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogAlongLine::DeployFormulaTextEdit);
connect(listWidget, &QListWidget::itemDoubleClicked, this, &DialogTool::PutVal);
connect(ui->comboBoxFirstPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogAlongLine::PointChanged);
connect(ui->comboBoxSecondPoint, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &DialogAlongLine::PointChanged);
}
//---------------------------------------------------------------------------------------------------------------------
@ -71,6 +75,24 @@ void DialogAlongLine::FormulaTextChanged()
this->FormulaChangedPlainText();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::PointChanged()
{
if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint))
{
flagError = false;
ChangeColor(ui->labelFirstPoint, Qt::red);
ChangeColor(ui->labelSecondPoint, Qt::red);
}
else
{
flagError = true;
ChangeColor(ui->labelFirstPoint, QColor(76, 76, 76));
ChangeColor(ui->labelSecondPoint, QColor(76, 76, 76));
}
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::DeployFormulaTextEdit()
{

View File

@ -65,15 +65,16 @@ public slots:
/**
* @brief DialogApply apply data and emit signal about applied dialog.
*/
virtual void DialogApply();
virtual void DialogApply();
/**
* @brief DeployFormulaTextEdit grow or shrink formula input
*/
void DeployFormulaTextEdit();
void DeployFormulaTextEdit();
/**
* @brief FormulaTextChanged when formula text changes for validation and calc
*/
void FormulaTextChanged();
void FormulaTextChanged();
void PointChanged();
private:
Q_DISABLE_COPY(DialogAlongLine)

View File

@ -195,7 +195,9 @@
<string/>
</property>
<property name="icon">
<iconset theme="go-down"/>
<iconset theme="go-down">
<normaloff/>
</iconset>
</property>
<property name="iconSize">
<size>
@ -268,7 +270,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="labelFirstPoint">
<property name="text">
<string>First point</string>
</property>
@ -286,7 +288,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_5">
<widget class="QLabel" name="labelSecondPoint">
<property name="text">
<string>Second point</string>
</property>

View File

@ -59,9 +59,7 @@ DialogDetail::DialogDetail(const VContainer *data, QWidget *parent)
connect(bCansel, &QPushButton::clicked, this, &DialogTool::DialogRejected);
flagName = true;//We have default name of detail.
QPalette palette = labelEditNamePoint->palette();
palette.setColor(labelEditNamePoint->foregroundRole(), QColor(76, 76, 76));
labelEditNamePoint->setPalette(palette);
ChangeColor(labelEditNamePoint, QColor(76, 76, 76));
CheckState();
connect(ui.listWidget, &QListWidget::currentRowChanged, this, &DialogDetail::ObjectChanged);

View File

@ -57,8 +57,8 @@
* @param parent parent widget
*/
DialogTool::DialogTool(const VContainer *data, QWidget *parent)
:QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(nullptr),
bOk(nullptr), bApply(nullptr), spinBoxAngle(nullptr), plainTextEditFormula(nullptr),
:QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), flagError(true),
timerFormula(nullptr), bOk(nullptr), bApply(nullptr), spinBoxAngle(nullptr), plainTextEditFormula(nullptr),
listWidget(nullptr), labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr),
labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr),
radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr),
@ -401,9 +401,7 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer)
{
flag = false;
CheckState();
QPalette palette = labelEditFormula->palette();
palette.setColor(labelEditFormula->foregroundRole(), Qt::red);
labelEditFormula->setPalette(palette);
ChangeColor(labelEditFormula, Qt::red);
return;
}
timer->start(1000);
@ -418,9 +416,7 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim
{
flag = false;
CheckState();
QPalette palette = labelEditFormula->palette();
palette.setColor(labelEditFormula->foregroundRole(), Qt::red);
labelEditFormula->setPalette(palette);
ChangeColor(labelEditFormula, Qt::red);
return;
}
timer->start(1000);
@ -439,11 +435,10 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la
SCASSERT(timer != nullptr);
SCASSERT(label != nullptr);
SCASSERT(labelEditFormula != nullptr);
QPalette palette = labelEditFormula->palette();
if (text.isEmpty())
{
flag = false;
palette.setColor(labelEditFormula->foregroundRole(), Qt::red);
ChangeColor(labelEditFormula, Qt::red);
}
else
{
@ -468,14 +463,14 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la
label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true));
}
flag = true;
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76));
ChangeColor(labelEditFormula, QColor(76, 76, 76));
emit ToolTip("");
}
catch (qmu::QmuParserError &e)
{
label->setText(tr("Error"));
flag = false;
palette.setColor(labelEditFormula->foregroundRole(), Qt::red);
ChangeColor(labelEditFormula, Qt::red);
emit ToolTip("Parser error: "+e.GetMsg());
qDebug() << "\nMath parser error:\n"
<< "--------------------------------------\n"
@ -486,7 +481,6 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la
}
CheckState();
timer->stop();
labelEditFormula->setPalette(palette);
}
//---------------------------------------------------------------------------------------------------------------------
@ -636,11 +630,11 @@ void DialogTool::FillList(QComboBox *box, const QMap<QString, quint32> &list) co
void DialogTool::CheckState()
{
SCASSERT(bOk != nullptr);
bOk->setEnabled(flagFormula && flagName);
bOk->setEnabled(flagFormula && flagName && flagError);
// In case dialog hasn't apply button
if ( bApply != nullptr)
{
bApply->setEnabled(flagFormula && flagName);
bApply->setEnabled(bOk->isEnabled());
}
}
@ -670,21 +664,26 @@ void DialogTool::NamePointChanged()
if (name.isEmpty() || name.contains(" "))
{
flagName = false;
QPalette palette = labelEditNamePoint->palette();
palette.setColor(labelEditNamePoint->foregroundRole(), Qt::red);
labelEditNamePoint->setPalette(palette);
ChangeColor(labelEditNamePoint, Qt::red);
}
else
{
flagName = true;
QPalette palette = labelEditNamePoint->palette();
palette.setColor(labelEditNamePoint->foregroundRole(), QColor(76, 76, 76));
labelEditNamePoint->setPalette(palette);
ChangeColor(labelEditNamePoint, QColor(76, 76, 76));
}
}
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::ChangeColor(QWidget *widget, const QColor &color)
{
SCASSERT(widget != nullptr);
QPalette palette = widget->palette();
palette.setColor(widget->foregroundRole(), color);
widget->setPalette(palette);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogAccepted save data and emit signal about closed dialog.

View File

@ -122,6 +122,13 @@ protected:
/** @brief flagFormula true if formula correct */
bool flagFormula;
/** @brief flagError use this flag if for you do not enought @see flagName and @see flagFormula.
*
* In many cases you will need more flags fore checking if all data are valid.
* By default this flag is true.
*/
bool flagError;
/** @brief timerFormula timer for check formula */
QTimer *timerFormula;
@ -292,6 +299,7 @@ protected:
* @brief associatedTool vdrawtool associated with opened dialog.
*/
VAbstractTool* associatedTool;
void ChangeColor(QWidget *widget, const QColor &color);
private:
void FillList(QComboBox *box, const QMap<QString, quint32> &list)const;
};