Better way check values in dialog arc. Issue 193.

--HG--
branch : develop
This commit is contained in:
dismine 2014-11-22 12:57:05 +02:00
parent 22f52e4101
commit cf36ec0b09
8 changed files with 56 additions and 27 deletions

View File

@ -38,7 +38,7 @@
* I took idea from this article http://ololoepepe.blogspot.com/2013/08/qt.html.
* As you know, if wrap string to a function translate, it will be marked for translation. No matter what namespace
* contains this function. In class Translation used this circumstance.
* It is mean never change name of method translate!!!!!.
* This mean never change name of method translate!!!!!.
* Instead of using QT_TRANSLATE_NOOP3 macros we can store strings in QMap.
* Example:
* create map and fill up its

View File

@ -86,8 +86,8 @@ void ConfigurationPage::Apply()
QString locale = qvariant_cast<QString>(langCombo->itemData(langCombo->currentIndex()));
qApp->getSettings()->setValue("configuration/locale", locale);
langChanged = false;
QString text = QString(tr("Setup user interface language updated and will be used the next time start") + " " +
QApplication::applicationName());
QString text = tr("Setup user interface language updated and will be used the next time start") + " " +
QApplication::applicationName();
QMessageBox::information(this, QApplication::applicationName(), text);
}
if (this->unitChanged)
@ -95,7 +95,7 @@ void ConfigurationPage::Apply()
QString unit = qvariant_cast<QString>(this->unitCombo->itemData(this->unitCombo->currentIndex()));
qApp->getSettings()->setValue("configuration/unit", unit);
this->unitChanged = false;
QString text = QString(tr("Default unit updated and will be used the next pattern creation"));
QString text = tr("Default unit updated and will be used the next pattern creation");
QMessageBox::information(this, QApplication::applicationName(), text);
}
if (labelLangChanged)

View File

@ -201,7 +201,7 @@ QString DialogHistory::Record(const VToolRecord &tool)
if (domElem.isElement() == false)
{
qDebug()<<"Can't find element by id"<<Q_FUNC_INFO;
return QString(tr("Can't create record."));
return tr("Can't create record.");
}
try
{
@ -291,7 +291,7 @@ QString DialogHistory::Record(const VToolRecord &tool)
else
{
qDebug()<<"Not enough points in splinepath"<<Q_FUNC_INFO;
return QString(tr("Can't create record."));
return tr("Can't create record.");
}
return record;
}
@ -397,14 +397,14 @@ QString DialogHistory::Record(const VToolRecord &tool)
break;
default:
qDebug()<<"Got wrong tool type. Ignore.";
return QString(tr("Can't create record."));
return tr("Can't create record.");
break;
}
}
catch (const VExceptionBadId &e)
{
qDebug()<<e.ErrorMessage()<<Q_FUNC_INFO;
return QString(tr("Can't create record."));
return tr("Can't create record.");
}
return QString();
}

View File

@ -458,7 +458,7 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked()
Changes += currentChange->element->GettreeNodeName();
Changes += "/";
Changes += (currentChange->element->GettreeNodeValueSet()) ?
currentChange->element->GettreeNodeValue(): QString(tr("<no value>"));
currentChange->element->GettreeNodeValue(): tr("<no value>");
Changes += "\n";
}
else
@ -466,9 +466,9 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked()
if (currentChange->type == DialogPatternXmlEdit::ChangeTypeModify)
{
Changes += QString("Modified type %1 : ").arg(nodetype);
Changes += (currentChange->changedText) ? *currentChange->newText : QString(tr("Unchanged"));
Changes += (currentChange->changedText) ? *currentChange->newText : tr("Unchanged");
Changes += "/";
Changes += (currentChange->changedValue) ? *currentChange->newValue: QString(tr("Unchanged"));
Changes += (currentChange->changedValue) ? *currentChange->newValue: tr("Unchanged");
Changes += "\n";
}
else
@ -479,7 +479,7 @@ void DialogPatternXmlEdit::ButtonApplyChangesClicked()
Changes += currentChange->element->GettreeNodeName();
Changes += "/";
Changes += (currentChange->element->GettreeNodeValueSet()) ?
currentChange->element->GettreeNodeValue(): QString(tr("<no value>"));
currentChange->element->GettreeNodeValue(): tr("<no value>");
Changes += "\n";
}
}

View File

@ -47,7 +47,7 @@ DialogArc::DialogArc(const VContainer *data, const quint32 &toolId, QWidget *par
:DialogTool(data, toolId, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false),
timerRadius(nullptr), timerF1(nullptr), timerF2(nullptr), center(NULL_ID), radius(QString()),
f1(QString()), f2(QString()), formulaBaseHeight(0), formulaBaseHeightF1(0), formulaBaseHeightF2(0), path(nullptr),
angleF1(0), angleF2(0)
angleF1(INT_MIN), angleF2(INT_MIN)
{
ui->setupUi(this);
@ -352,7 +352,17 @@ void DialogArc::EvalRadius()
{
labelEditFormula = ui->labelEditRadius;
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true);
Eval(ui->plainTextEditFormula->toPlainText(), flagRadius, ui->labelResultRadius, postfix);
const qreal radius = Eval(ui->plainTextEditFormula->toPlainText(), flagRadius, ui->labelResultRadius, postfix);
if (radius < 0)
{
flagRadius = false;
ChangeColor(labelEditFormula, Qt::red);
ui->labelResultRadius->setText(tr("Error"));
ui->labelResultRadius->setToolTip(tr("Radius can't be negative"));
DialogArc::CheckState();
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -394,14 +404,21 @@ void DialogArc::ShowLineAngles()
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::CheckAngles()
{
if (angleF1 == INT_MIN || angleF2 == INT_MIN)
{
return;
}
if (qFuzzyCompare(angleF1 + 1, angleF2 + 1))
{
flagF1 = false;
ChangeColor(ui->labelEditF1, Qt::red);
ui->labelResultF1->setText(tr("Error"));
ui->labelResultF1->setToolTip(tr("Angles equal"));
flagF2 = false;
ChangeColor(ui->labelEditF2, Qt::red);
ui->labelResultF2->setText(tr("Error"));
ui->labelResultF2->setToolTip(tr("Angles equal"));
}

View File

@ -441,6 +441,7 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer)
CheckState();
ChangeColor(labelEditFormula, Qt::red);
labelResultCalculation->setText(tr("Error"));
labelResultCalculation->setToolTip(tr("Empty field"));
return;
}
timer->start(1000);
@ -458,6 +459,7 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim
CheckState();
ChangeColor(labelEditFormula, Qt::red);
labelResultCalculation->setText(tr("Error"));
labelResultCalculation->setToolTip(tr("Empty field"));
return;
}
timer->setSingleShot(true);
@ -478,7 +480,7 @@ qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QSt
SCASSERT(label != nullptr);
SCASSERT(labelEditFormula != nullptr);
qreal result = 0;
qreal result = INT_MIN;//Value can be 0, so use max imposible value
if (text.isEmpty())
{
@ -908,7 +910,7 @@ void DialogTool::EvalFormula()
SCASSERT(plainTextEditFormula != nullptr);
SCASSERT(labelResultCalculation != nullptr);
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit());
Eval(plainTextEditFormula->toPlainText(), flagFormula, labelResultCalculation, postfix);
Eval(plainTextEditFormula->toPlainText(), flagFormula, labelResultCalculation, postfix, false);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -213,12 +213,15 @@ VFormula VToolArc::getFormulaRadius() const
void VToolArc::setFormulaRadius(const VFormula &value)
{
if (value.error() == false)
{
if (value.getDoubleValue() > 0)// Formula don't check this, but radius can't be 0 or negative
{
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
QSharedPointer<VArc> arc = qSharedPointerDynamicCast<VArc>(obj);
arc->SetFormulaRadius(value);
SaveOption(obj);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -241,9 +244,13 @@ void VToolArc::setFormulaF1(const VFormula &value)
{
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
QSharedPointer<VArc> arc = qSharedPointerDynamicCast<VArc>(obj);
if (qFuzzyCompare(value.getDoubleValue() + 1, arc->GetF2() + 1)==false)// Angles can't be equal
{
arc->SetFormulaF1(value);
SaveOption(obj);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -266,9 +273,12 @@ void VToolArc::setFormulaF2(const VFormula &value)
{
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
QSharedPointer<VArc> arc = qSharedPointerDynamicCast<VArc>(obj);
if (qFuzzyCompare(value.getDoubleValue() + 1, arc->GetF1() + 1)==false)// Angles can't be equal
{
arc->SetFormulaF2(value);
SaveOption(obj);
}
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -84,12 +84,12 @@ void VisToolSplinePath::RefreshGeometry()
}
if (path.CountPoint() < 3)
{
Visualization::toolTip = QString(tr("<b>Curve path</b>: select three or more points"));
Visualization::toolTip = tr("<b>Curve path</b>: select three or more points");
}
else
{
Visualization::toolTip = QString(tr("<b>Curve path</b>: select three or more points, "
"<b>Enter</b> - finish creation"));
Visualization::toolTip = tr("<b>Curve path</b>: select three or more points, "
"<b>Enter</b> - finish creation");
}
}
}