Refactoring tool dialogs.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-02-11 13:25:27 +02:00
parent 03e9c3068a
commit 0c3cce5122
120 changed files with 2608 additions and 2109 deletions

View File

@ -68,6 +68,7 @@ signals:
protected:
virtual void closeEvent ( QCloseEvent * event ) override;
virtual void changeEvent(QEvent* event) override;
virtual bool IsValid() const final {return true;}
private:
Q_DISABLE_COPY(DialogHistory)

View File

@ -66,6 +66,7 @@ protected:
virtual bool eventFilter(QObject *object, QEvent *event) override;
virtual void showEvent( QShowEvent *event ) override;
virtual void resizeEvent(QResizeEvent *event) override;
virtual bool IsValid() const final {return true;}
private slots:
void ShowIncrementDetails();
void AddIncrement();

View File

@ -48,7 +48,8 @@ HEADERS += \
$$PWD/tools/piece/dialoginsertnode.h \
$$PWD/support/dialogeditlabel.h \
$$PWD/tools/piece/dialogplacelabel.h \
$$PWD/tools/piece/dialogduplicatedetail.h
$$PWD/tools/piece/dialogduplicatedetail.h \
$$PWD/dialogtoolbox.h
SOURCES += \
$$PWD/tools/dialogalongline.cpp \
@ -96,7 +97,8 @@ SOURCES += \
$$PWD/tools/piece/dialoginsertnode.cpp \
$$PWD/support/dialogeditlabel.cpp \
$$PWD/tools/piece/dialogplacelabel.cpp \
$$PWD/tools/piece/dialogduplicatedetail.cpp
$$PWD/tools/piece/dialogduplicatedetail.cpp \
$$PWD/dialogtoolbox.cpp
FORMS += \
$$PWD/tools/dialogalongline.ui \

View File

@ -0,0 +1,239 @@
/************************************************************************
**
** @file dialogtoolbox.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 1, 2019
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2019 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "dialogtoolbox.h"
#include "../vmisc/def.h"
#include "../vmisc/vabstractapplication.h"
#include "../vpatterndb/calculator.h"
#include "../vpatterndb/vcontainer.h"
#include <QDialog>
#include <QLabel>
#include <QLocale>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QTextCursor>
#include <QDebug>
#include <QTimer>
#include <QLineEdit>
#include <QRegularExpression>
const QColor errorColor = Qt::red;
namespace
{
const int dialogMaxFormulaHeight = 80;
}
//---------------------------------------------------------------------------------------------------------------------
void MoveCursorToEnd(QPlainTextEdit *plainTextEdit)
{
SCASSERT(plainTextEdit != nullptr)
QTextCursor cursor = plainTextEdit->textCursor();
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
plainTextEdit->setTextCursor(cursor);
}
//---------------------------------------------------------------------------------------------------------------------
void DeployFormula(QDialog *dialog, QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight)
{
SCASSERT(dialog != nullptr)
SCASSERT(formula != nullptr)
SCASSERT(buttonGrowLength != nullptr)
const QTextCursor cursor = formula->textCursor();
//Before deploy ned to release dialog size
//I don't know why, but don't need to fixate again.
//A dialog will be lefted fixated. That's what we need.
dialog->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
dialog->setMinimumSize(QSize(0, 0));
if (formula->height() < dialogMaxFormulaHeight)
{
formula->setFixedHeight(dialogMaxFormulaHeight);
//Set icon from theme (internal for Windows system)
buttonGrowLength->setIcon(QIcon::fromTheme(QStringLiteral("go-next"),
QIcon(":/icons/win.icon.theme/16x16/actions/go-next.png")));
}
else
{
formula->setFixedHeight(formulaBaseHeight);
//Set icon from theme (internal for Windows system)
buttonGrowLength->setIcon(QIcon::fromTheme(QStringLiteral("go-down"),
QIcon(":/icons/win.icon.theme/16x16/actions/go-down.png")));
}
// I found that after change size of formula field, it was filed for angle formula, field for formula became black.
// This code prevent this.
dialog->setUpdatesEnabled(false);
dialog->repaint();
dialog->setUpdatesEnabled(true);
formula->setFocus();
formula->setTextCursor(cursor);
}
//---------------------------------------------------------------------------------------------------------------------
bool FilterObject(QObject *object, QEvent *event)
{
if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(object))
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
{
if (qApp->Settings()->GetOsSeparator())
{
plainTextEdit->insertPlainText(QLocale().decimalPoint());
}
else
{
plainTextEdit->insertPlainText(QLocale::c().decimalPoint());
}
return true;
}
}
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
qreal EvalToolFormula(QDialog *dialog, const FormulaData &data, bool &flag)
{
SCASSERT(data.labelResult != nullptr)
SCASSERT(data.labelEditFormula != nullptr)
qreal result = INT_MIN;//Value can be 0, so use max imposible value
if (data.formula.isEmpty())
{
flag = false;
ChangeColor(data.labelEditFormula, errorColor);
data.labelResult->setText(QObject::tr("Error") + " (" + data.postfix + ")");
data.labelResult->setToolTip(QObject::tr("Empty formula"));
}
else
{
try
{
// Translate to internal look.
QString formula = qApp->TrVars()->FormulaFromUser(data.formula, qApp->Settings()->GetOsSeparator());
QScopedPointer<Calculator> cal(new Calculator());
result = cal->EvalFormula(data.variables, formula);
if (qIsInf(result) || qIsNaN(result))
{
flag = false;
ChangeColor(data.labelEditFormula, errorColor);
data.labelResult->setText(QObject::tr("Error") + " (" + data.postfix + ")");
data.labelResult->setToolTip(QObject::tr("Invalid result. Value is infinite or NaN. Please, check "
"your calculations."));
}
else
{
//if result equal 0
if (data.checkZero && qFuzzyIsNull(result))
{
flag = false;
ChangeColor(data.labelEditFormula, errorColor);
data.labelResult->setText(QObject::tr("Error") + " (" + data.postfix + ")");
data.labelResult->setToolTip(QObject::tr("Value can't be 0"));
}
else if (data.checkLessThanZero && result < 0)
{
flag = false;
ChangeColor(data.labelEditFormula, errorColor);
data.labelResult->setText(QObject::tr("Error") + " (" + data.postfix + ")");
data.labelResult->setToolTip(QObject::tr("Value can't be less than 0"));
}
else
{
data.labelResult->setText(qApp->LocaleToString(result) + QChar(QChar::Space) + data.postfix);
flag = true;
ChangeColor(data.labelEditFormula, OkColor(dialog));
data.labelResult->setToolTip(QObject::tr("Value"));
}
}
}
catch (qmu::QmuParserError &e)
{
data.labelResult->setText(QObject::tr("Error") + " (" + data.postfix + ")");
flag = false;
ChangeColor(data.labelEditFormula, errorColor);
data.labelResult->setToolTip(QObject::tr("Parser error: %1").arg(e.GetMsg()));
qDebug() << "\nMath parser error:\n"
<< "--------------------------------------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: " << e.GetExpr() << "\n"
<< "--------------------------------------";
}
}
return result;
}
//---------------------------------------------------------------------------------------------------------------------
void ChangeColor(QWidget *widget, const QColor &color)
{
SCASSERT(widget != nullptr)
QPalette palette = widget->palette();
palette.setColor(QPalette::Active, widget->foregroundRole(), color);
palette.setColor(QPalette::Inactive, widget->foregroundRole(), color);
widget->setPalette(palette);
}
//---------------------------------------------------------------------------------------------------------------------
QColor OkColor(QWidget *widget)
{
SCASSERT(widget != nullptr);
return widget->palette().color(QPalette::Active, QPalette::WindowText);
}
//---------------------------------------------------------------------------------------------------------------------
void CheckPointLabel(QDialog *dialog, QLineEdit* edit, QLabel *labelEditNamePoint, const QString &pointName,
const VContainer *data, bool &flag)
{
SCASSERT(dialog != nullptr)
SCASSERT(edit != nullptr)
SCASSERT(labelEditNamePoint != nullptr)
QString name = edit->text();
QRegularExpression rx(NameRegExp());
if (name.isEmpty() || (not (pointName != name && data->IsUnique(name))) || not rx.match(name).hasMatch())
{
flag = false;
ChangeColor(labelEditNamePoint, errorColor);
}
else
{
flag = true;
ChangeColor(labelEditNamePoint, OkColor(dialog));
}
}

View File

@ -0,0 +1,77 @@
/************************************************************************
**
** @file dialogtoolbox.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 25 1, 2019
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2019 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef DIALOGTOOLBOX_H
#define DIALOGTOOLBOX_H
#include <QString>
#include <QtGlobal>
#include <QSharedPointer>
#include "../vpatterndb/variables/vinternalvariable.h"
class QPlainTextEdit;
class QPushButton;
class QDialog;
class QObject;
class QEvent;
class QLabel;
class QWidget;
class QColor;
class QLineEdit;
class VContainer;
constexpr int formulaTimerTimeout = 300;
extern const QColor errorColor;
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Weffc++")
struct FormulaData
{
QString formula;
const QHash<QString, QSharedPointer<VInternalVariable> > *variables{nullptr};
QLabel *labelEditFormula{nullptr};
QLabel *labelResult{nullptr};
QString postfix;
bool checkZero{true};
bool checkLessThanZero{false};
};
QT_WARNING_POP
void MoveCursorToEnd(QPlainTextEdit *plainTextEdit);
void DeployFormula(QDialog *dialog, QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight);
bool FilterObject(QObject *object, QEvent *event);
qreal EvalToolFormula(QDialog *dialog, const FormulaData &data, bool &flag);
void ChangeColor(QWidget *widget, const QColor &color);
QColor OkColor(QWidget *widget);
void CheckPointLabel(QDialog *dialog, QLineEdit* edit, QLabel *labelEditNamePoint, const QString &pointName,
const VContainer *data, bool &flag);
#endif // DIALOGTOOLBOX_H

View File

@ -51,6 +51,7 @@
#include <QWidget>
#include <Qt>
#include <new>
#include <QTimer>
#include "../vpatterndb/vcontainer.h"
#include "../vpatterndb/vtranslatevars.h"
@ -73,18 +74,28 @@ template <class T> class QSharedPointer;
enum {ColumnName = 0, ColumnFullName};
//---------------------------------------------------------------------------------------------------------------------
DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogEditWrongFormula), formula(QString()), formulaBaseHeight(0),
checkZero(false), checkLessThanZero(false), postfix(QString()), restoreCursor(false)
DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogEditWrongFormula),
formula(),
formulaBaseHeight(0),
checkZero(false),
checkLessThanZero(false),
postfix(),
restoreCursor(false),
timerFormula(new QTimer(this)),
flagFormula(false)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogEditWrongFormula::EvalFormula);
#if defined(Q_OS_MAC)
setWindowFlags(Qt::Window);
#endif
InitVariables();
InitFormulaUI(ui);
this->formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
ui->filterFormulaInputs->setClearButtonEnabled(true);
@ -92,13 +103,14 @@ DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const qui
connect(ui->filterFormulaInputs, &QLineEdit::textChanged, this, &DialogEditWrongFormula::FilterVariablesEdited);
InitOkCancel(ui);
flagFormula = false;
CheckState();
connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEditWrongFormula::PutHere);
connect(ui->tableWidget, &QTableWidget::itemDoubleClicked, this, &DialogEditWrongFormula::PutVal);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEditWrongFormula::FormulaChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
//Disable Qt::WaitCursor
#ifndef QT_NO_CURSOR
@ -147,10 +159,16 @@ void DialogEditWrongFormula::DialogRejected()
//---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::EvalFormula()
{
SCASSERT(plainTextEditFormula != nullptr)
SCASSERT(labelResultCalculation != nullptr)
Eval(plainTextEditFormula->toPlainText(), flagFormula, labelResultCalculation, postfix, checkZero,
checkLessThanZero);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = postfix;
formulaData.checkZero = checkZero;
formulaData.checkLessThanZero = checkLessThanZero;
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
@ -336,13 +354,6 @@ void DialogEditWrongFormula::Functions()
ShowFunctions();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEditWrongFormula::closeEvent(QCloseEvent *event)
{
@ -371,6 +382,8 @@ void DialogEditWrongFormula::showEvent(QShowEvent *event)
resize(sz);
}
CheckState();
isInitialized = true;//first show windows are held
}

View File

@ -59,7 +59,7 @@ class DialogEditWrongFormula : public DialogTool
{
Q_OBJECT
public:
DialogEditWrongFormula(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogEditWrongFormula(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogEditWrongFormula() override;
QString GetFormula() const;
@ -73,7 +73,7 @@ public:
public slots:
virtual void DialogAccepted() override;
virtual void DialogRejected() override;
virtual void EvalFormula() override;
void EvalFormula();
void ValChanged(int row);
void PutHere();
void PutVal(QTableWidgetItem * item);
@ -89,7 +89,7 @@ public slots:
void PreviewCalculations();
void Functions();
protected:
virtual void CheckState() final;
virtual bool IsValid() const final;
virtual void closeEvent(QCloseEvent *event) override;
virtual void showEvent( QShowEvent *event ) override;
virtual void resizeEvent(QResizeEvent *event) override;
@ -110,6 +110,10 @@ private:
QString postfix;
bool restoreCursor;
QTimer *timerFormula;
bool flagFormula;
void InitVariables();
template <class key, class val>
@ -121,5 +125,10 @@ private:
void SetDescription(const QString &name, qreal value, const QString &unit, const QString &description);
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogEditWrongFormula::IsValid() const
{
return flagFormula;
}
#endif // DIALOGEDITWRONGFORMULA_H

View File

@ -38,6 +38,7 @@
#include <QPointer>
#include <QPushButton>
#include <QSharedPointer>
#include <QTimer>
#include <QToolButton>
#include <new>
@ -61,24 +62,31 @@
* @param data container with data
* @param parent parent widget
*/
DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine),
formula(QString()), formulaBaseHeight(0), buildMidpoint(false)
DialogAlongLine::DialogAlongLine(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogAlongLine),
formula(),
pointName(),
formulaBaseHeight(0),
buildMidpoint(false),
timerFormula(new QTimer(this)),
flagFormula(false),
flagError(true),
flagName(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogAlongLine::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
@ -86,8 +94,15 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId,
FillComboBoxLineColors(ui->comboBoxLineColor);
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogAlongLine::FXLength);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogAlongLine::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogAlongLine::FormulaTextChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogAlongLine::DeployFormulaTextEdit);
connect(ui->comboBoxFirstPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogAlongLine::PointChanged);
@ -100,16 +115,10 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId,
SetTypeLine(TypeLineNone);//By default don't show line
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::FormulaTextChanged()
{
this->FormulaChangedPlainText();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::PointChanged()
{
QColor color = okColor;
QColor color;
if (GetFirstPointId() == GetSecondPointId())
{
flagError = false;
@ -118,7 +127,7 @@ void DialogAlongLine::PointChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
SetCurrentLength();
ChangeColor(ui->labelFirstPoint, color);
@ -140,6 +149,20 @@ void DialogAlongLine::FXLength()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::EvalFormula()
{
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::ShowVisualization()
{
@ -149,7 +172,7 @@ void DialogAlongLine::ShowVisualization()
//---------------------------------------------------------------------------------------------------------------------
void DialogAlongLine::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -191,7 +214,7 @@ void DialogAlongLine::ChosenObject(quint32 id, const SceneObject &type)
line->setObject2Id(id);
if (buildMidpoint)
{
SetFormula(currentLength + QLatin1String("/2"));
SetFormula(currentLength + QStringLiteral("/2"));
}
line->RefreshGeometry();
prepare = true;
@ -254,7 +277,7 @@ void DialogAlongLine::SetCurrentLength()
* @brief SetSecondPointId set id second point of line
* @param value id
*/
void DialogAlongLine::SetSecondPointId(const quint32 &value)
void DialogAlongLine::SetSecondPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxSecondPoint, value);
@ -280,7 +303,7 @@ void DialogAlongLine::Build(const Tool &type)
* @brief SetFirstPointId set id first point of line
* @param value id
*/
void DialogAlongLine::SetFirstPointId(const quint32 &value)
void DialogAlongLine::SetFirstPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxFirstPoint, value);
@ -334,6 +357,12 @@ void DialogAlongLine::SetLineColor(const QString &value)
ChangeCurrentData(ui->comboBoxLineColor, value);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogAlongLine::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetPointName set name of point

View File

@ -50,9 +50,10 @@ class DialogAlongLine : public DialogTool
{
Q_OBJECT
public:
DialogAlongLine(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogAlongLine(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogAlongLine() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetTypeLine() const;
@ -65,10 +66,10 @@ public:
void SetFormula(const QString &value);
quint32 GetFirstPointId() const;
void SetFirstPointId(const quint32 &value);
void SetFirstPointId(quint32 value);
quint32 GetSecondPointId() const;
void SetSecondPointId(const quint32 &value);
void SetSecondPointId(quint32 value);
virtual void Build(const Tool &type) override;
public slots:
@ -77,13 +78,10 @@ public slots:
* @brief DeployFormulaTextEdit grow or shrink formula input
*/
void DeployFormulaTextEdit();
/**
* @brief FormulaTextChanged when formula text changes for validation and calc
*/
void FormulaTextChanged();
void PointChanged();
void FXLength();
void EvalFormula();
protected:
virtual void ShowVisualization() override;
/**
@ -91,6 +89,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogAlongLine)
@ -98,14 +97,28 @@ private:
Ui::DialogAlongLine *ui;
/** @brief formula formula */
QString formula;
QString formula;
QString pointName;
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
bool buildMidpoint;
QTimer *timerFormula;
bool flagFormula;
bool flagError;
bool flagName;
void SetCurrentLength();
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogAlongLine::IsValid() const
{
return flagName &&flagFormula && flagError;
}
#endif // DIALOGALONGLINE_H

View File

@ -40,6 +40,7 @@
#include "../ifc/xml/vdomdocument.h"
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../../visualization/path/vistoolarc.h"
#include "../../visualization/visualization.h"
#include "../support/dialogeditwrongformula.h"
@ -53,16 +54,28 @@
* @param data container with data
* @param parent parent widget
*/
DialogArc::DialogArc(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogArc), flagRadius(false), flagF1(false), flagF2(false),
timerRadius(nullptr), timerF1(nullptr), timerF2(nullptr), radius(QString()), f1(QString()), f2(QString()),
formulaBaseHeight(0), formulaBaseHeightF1(0), formulaBaseHeightF2(0), angleF1(INT_MIN), angleF2(INT_MIN)
DialogArc::DialogArc(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogArc),
flagRadius(false),
flagF1(false),
flagF2(false),
timerRadius(new QTimer(this)),
timerF1(new QTimer(this)),
timerF2(new QTimer(this)),
radius(),
f1(),
f2(),
formulaBaseHeight(0),
formulaBaseHeightF1(0),
formulaBaseHeightF2(0),
angleF1(INT_MIN),
angleF2(INT_MIN)
{
ui->setupUi(this);
ui->doubleSpinBoxApproximationScale->setMaximum(maxCurveApproximationScale);
plainTextEditFormula = ui->plainTextEditFormula;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
this->formulaBaseHeightF1 = ui->plainTextEditF1->height();
this->formulaBaseHeightF2 = ui->plainTextEditF2->height();
@ -71,13 +84,13 @@ DialogArc::DialogArc(const VContainer *data, const quint32 &toolId, QWidget *par
ui->plainTextEditF1->installEventFilter(this);
ui->plainTextEditF2->installEventFilter(this);
timerRadius = new QTimer(this);
timerRadius->setSingleShot(true);
connect(timerRadius, &QTimer::timeout, this, &DialogArc::EvalRadius);
timerF1 = new QTimer(this);
timerF1->setSingleShot(true);
connect(timerF1, &QTimer::timeout, this, &DialogArc::EvalF);
timerF2 = new QTimer(this);
timerF2->setSingleShot(true);
connect(timerF2, &QTimer::timeout, this, &DialogArc::EvalF);
InitOkCancelApply(ui);
@ -86,15 +99,24 @@ DialogArc::DialogArc(const VContainer *data, const quint32 &toolId, QWidget *par
FillComboBoxLineColors(ui->comboBoxColor);
FillComboBoxTypeLine(ui->comboBoxPenStyle, CurvePenStylesPics());
CheckState();
connect(ui->toolButtonExprRadius, &QPushButton::clicked, this, &DialogArc::FXRadius);
connect(ui->toolButtonExprF1, &QPushButton::clicked, this, &DialogArc::FXF1);
connect(ui->toolButtonExprF2, &QPushButton::clicked, this, &DialogArc::FXF2);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogArc::RadiusChanged);
connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, &DialogArc::F1Changed);
connect(ui->plainTextEditF2, &QPlainTextEdit::textChanged, this, &DialogArc::F2Changed);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerRadius->start(formulaTimerTimeout);
});
connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, [this]()
{
timerF1->start(formulaTimerTimeout);
});
connect(ui->plainTextEditF2, &QPlainTextEdit::textChanged, this, [this]()
{
timerF2->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogArc::DeployFormulaTextEdit);
connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogArc::DeployF1TextEdit);
@ -106,19 +128,19 @@ DialogArc::DialogArc(const VContainer *data, const quint32 &toolId, QWidget *par
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::DeployF1TextEdit()
{
DeployFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
DeployFormula(this, ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::DeployF2TextEdit()
{
DeployFormula(ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
DeployFormula(this, ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
}
//---------------------------------------------------------------------------------------------------------------------
@ -300,40 +322,6 @@ void DialogArc::closeEvent(QCloseEvent *event)
DialogTool::closeEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RadiusChanged after change formula of radius calculate value and show result
*/
void DialogArc::RadiusChanged()
{
labelEditFormula = ui->labelEditRadius;
labelResultCalculation = ui->labelResultRadius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagRadius, ui->plainTextEditFormula, timerRadius, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief F1Changed after change formula of first angle calculate value and show result
*/
void DialogArc::F1Changed()
{
labelEditFormula = ui->labelEditF1;
labelResultCalculation = ui->labelResultF1;
ValFormulaChanged(flagF1, ui->plainTextEditF1, timerF1, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief F2Changed after change formula of second angle calculate value and show result
*/
void DialogArc::F2Changed()
{
labelEditFormula = ui->labelEditF2;
labelResultCalculation = ui->labelResultF2;
ValFormulaChanged(flagF2, ui->plainTextEditF2, timerF2, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArc::FXRadius()
{
@ -376,32 +364,25 @@ void DialogArc::FXF2()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief CheckState if all is right enable button ok
*/
void DialogArc::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagRadius && flagF1 && flagF2);
SCASSERT(bApply != nullptr)
bApply->setEnabled(flagRadius && flagF1 && flagF2);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief EvalRadius calculate value of radius
*/
void DialogArc::EvalRadius()
{
labelEditFormula = ui->labelEditRadius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius = Eval(ui->plainTextEditFormula->toPlainText(), flagRadius, ui->labelResultRadius, postfix);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditRadius;
formulaData.labelResult = ui->labelResultRadius;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius = Eval(formulaData, flagRadius);
if (radius < 0)
{
flagRadius = false;
ChangeColor(labelEditFormula, Qt::red);
ChangeColor(ui->labelEditRadius, errorColor);
ui->labelResultRadius->setText(tr("Error"));
ui->labelResultRadius->setToolTip(tr("Radius can't be negative"));
@ -415,11 +396,21 @@ void DialogArc::EvalRadius()
*/
void DialogArc::EvalF()
{
labelEditFormula = ui->labelEditF1;
angleF1 = Eval(ui->plainTextEditF1->toPlainText(), flagF1, ui->labelResultF1, degreeSymbol, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditF1->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditF1;
formulaData.labelResult = ui->labelResultF1;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
labelEditFormula = ui->labelEditF2;
angleF2 = Eval(ui->plainTextEditF2->toPlainText(), flagF2, ui->labelResultF2, degreeSymbol, false);
angleF1 = Eval(formulaData, flagF1);
formulaData.formula = ui->plainTextEditF2->toPlainText();
formulaData.labelEditFormula = ui->labelEditF2;
formulaData.labelResult = ui->labelResultF2;
angleF2 = Eval(formulaData, flagF2);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -50,7 +50,7 @@ class DialogArc : public DialogTool
{
Q_OBJECT
public:
DialogArc(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogArc(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogArc() override;
quint32 GetCenter() const;
@ -81,21 +81,19 @@ public slots:
void DeployFormulaTextEdit();
void DeployF1TextEdit();
void DeployF2TextEdit();
void RadiusChanged();
void F1Changed();
void F2Changed();
void FXRadius();
void FXF1();
void FXF2();
void FXRadius();
void FXF1();
void FXF2();
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
/**
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogArc)
@ -141,4 +139,10 @@ private:
void EvalF();
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogArc::IsValid() const
{
return flagRadius && flagF1 && flagF2;
}
#endif // DIALOGARC_H

View File

@ -40,6 +40,7 @@
#include "../ifc/xml/vdomdocument.h"
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../../visualization/path/vistoolarcwithlength.h"
#include "../support/dialogeditwrongformula.h"
#include "../vmisc/vabstractapplication.h"
@ -48,15 +49,25 @@
#include "ui_dialogarcwithlength.h"
//---------------------------------------------------------------------------------------------------------------------
DialogArcWithLength::DialogArcWithLength(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogArcWithLength), flagRadius(false), flagF1(false),
flagLength(false), timerRadius(nullptr), timerF1(nullptr), timerLength(nullptr), radius(QString()), f1(QString()),
length(QString()),formulaBaseHeightRadius(0), formulaBaseHeightF1(0), formulaBaseHeightLength(0), angleF1(INT_MIN)
DialogArcWithLength::DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogArcWithLength),
flagRadius(false),
flagF1(false),
flagLength(false),
timerRadius(new QTimer(this)),
timerF1(new QTimer(this)),
timerLength(new QTimer(this)),
radius(),
f1(),
length(),
formulaBaseHeightRadius(0),
formulaBaseHeightF1(0),
formulaBaseHeightLength(0)
{
ui->setupUi(this);
plainTextEditFormula = ui->plainTextEditRadius;
this->formulaBaseHeightLength = ui->plainTextEditRadius->height();
this->formulaBaseHeightRadius = ui->plainTextEditRadius->height();
this->formulaBaseHeightF1 = ui->plainTextEditF1->height();
this->formulaBaseHeightLength = ui->plainTextEditLength->height();
@ -64,13 +75,13 @@ DialogArcWithLength::DialogArcWithLength(const VContainer *data, const quint32 &
ui->plainTextEditF1->installEventFilter(this);
ui->plainTextEditLength->installEventFilter(this);
timerRadius = new QTimer(this);
timerRadius->setSingleShot(true);
connect(timerRadius, &QTimer::timeout, this, &DialogArcWithLength::Radius);
timerF1 = new QTimer(this);
timerF1->setSingleShot(true);
connect(timerF1, &QTimer::timeout, this, &DialogArcWithLength::EvalF);
timerLength = new QTimer(this);
timerLength->setSingleShot(true);
connect(timerLength, &QTimer::timeout, this, &DialogArcWithLength::Length);
InitOkCancelApply(ui);
@ -81,15 +92,24 @@ DialogArcWithLength::DialogArcWithLength(const VContainer *data, const quint32 &
ui->doubleSpinBoxApproximationScale->setMaximum(maxCurveApproximationScale);
CheckState();
connect(ui->toolButtonExprRadius, &QPushButton::clicked, this, &DialogArcWithLength::FXRadius);
connect(ui->toolButtonExprF1, &QPushButton::clicked, this, &DialogArcWithLength::FXF1);
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogArcWithLength::FXLength);
connect(ui->plainTextEditRadius, &QPlainTextEdit::textChanged, this, &DialogArcWithLength::RadiusChanged);
connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, &DialogArcWithLength::F1Changed);
connect(ui->plainTextEditLength, &QPlainTextEdit::textChanged, this, &DialogArcWithLength::LengthChanged);
connect(ui->plainTextEditRadius, &QPlainTextEdit::textChanged, this, [this]()
{
timerRadius->start(formulaTimerTimeout);
});
connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, [this]()
{
timerF1->start(formulaTimerTimeout);
});
connect(ui->plainTextEditLength, &QPlainTextEdit::textChanged, this, [this]()
{
timerLength->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLengthRadius, &QPushButton::clicked, this, &DialogArcWithLength::DeployRadiusTextEdit);
connect(ui->pushButtonGrowLengthF1, &QPushButton::clicked, this, &DialogArcWithLength::DeployF1TextEdit);
@ -249,45 +269,19 @@ void DialogArcWithLength::ChosenObject(quint32 id, const SceneObject &type)
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::DeployRadiusTextEdit()
{
DeployFormula(ui->plainTextEditRadius, ui->pushButtonGrowLengthArcLength, formulaBaseHeightRadius);
DeployFormula(this, ui->plainTextEditRadius, ui->pushButtonGrowLengthArcLength, formulaBaseHeightRadius);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::DeployF1TextEdit()
{
DeployFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
DeployFormula(this, ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::DeployLengthTextEdit()
{
DeployFormula(ui->plainTextEditLength, ui->pushButtonGrowLengthArcLength, formulaBaseHeightLength);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::RadiusChanged()
{
labelEditFormula = ui->labelEditRadius;
labelResultCalculation = ui->labelResultRadius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagRadius, ui->plainTextEditRadius, timerRadius, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::F1Changed()
{
labelEditFormula = ui->labelEditF1;
labelResultCalculation = ui->labelResultF1;
ValFormulaChanged(flagF1, ui->plainTextEditF1, timerF1, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::LengthChanged()
{
labelEditFormula = ui->labelEditLength;
labelResultCalculation = ui->labelResultLength;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagLength, ui->plainTextEditLength, timerLength, postfix);
DeployFormula(this, ui->plainTextEditLength, ui->pushButtonGrowLengthArcLength, formulaBaseHeightLength);
}
//---------------------------------------------------------------------------------------------------------------------
@ -332,18 +326,6 @@ void DialogArcWithLength::FXLength()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagRadius && flagF1 && flagLength);
// In case dialog hasn't apply button
if ( bApply != nullptr)
{
bApply->setEnabled(bOk->isEnabled());
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::ShowVisualization()
{
@ -380,42 +362,40 @@ void DialogArcWithLength::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::Radius()
{
labelEditFormula = ui->labelEditRadius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius = Eval(ui->plainTextEditRadius->toPlainText(), flagRadius, ui->labelResultRadius, postfix);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditRadius->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditRadius;
formulaData.labelResult = ui->labelResultRadius;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkLessThanZero = true;
if (radius < 0)
{
flagRadius = false;
ChangeColor(labelEditFormula, Qt::red);
ui->labelResultRadius->setText(tr("Error"));
ui->labelResultRadius->setToolTip(tr("Radius can't be negative"));
DialogArcWithLength::CheckState();
}
Eval(formulaData, flagRadius);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::Length()
{
labelEditFormula = ui->labelEditLength;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal length = Eval(ui->plainTextEditLength->toPlainText(), flagLength, ui->labelResultLength, postfix);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditLength->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditLength;
formulaData.labelResult = ui->labelResultLength;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
if (qFuzzyIsNull(length))
{
flagLength = false;
ChangeColor(labelEditFormula, Qt::red);
ui->labelResultLength->setText(tr("Error"));
ui->labelResultLength->setToolTip(tr("Length can't be equal 0"));
DialogArcWithLength::CheckState();
}
Eval(formulaData, flagLength);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogArcWithLength::EvalF()
{
labelEditFormula = ui->labelEditF1;
angleF1 = Eval(ui->plainTextEditF1->toPlainText(), flagF1, ui->labelResultF1, degreeSymbol, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditF1->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditF1;
formulaData.labelResult = ui->labelResultF1;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, flagF1);
}

View File

@ -48,7 +48,7 @@ class DialogArcWithLength : public DialogTool
Q_OBJECT
public:
DialogArcWithLength(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogArcWithLength(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
~DialogArcWithLength();
quint32 GetCenter() const;
@ -80,22 +80,18 @@ public slots:
void DeployF1TextEdit();
void DeployLengthTextEdit();
void RadiusChanged();
void F1Changed();
void LengthChanged();
void FXRadius();
void FXF1();
void FXLength();
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
/**
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogArcWithLength)
@ -130,11 +126,15 @@ private:
int formulaBaseHeightF1;
int formulaBaseHeightLength;
qreal angleF1;
void Radius();
void Length();
void EvalF();
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogArcWithLength::IsValid() const
{
return flagRadius && flagF1 && flagLength;
}
#endif // DIALOGARCWITHLENGTH_H

View File

@ -37,6 +37,7 @@
#include <QPointer>
#include <QPushButton>
#include <QSet>
#include <QTimer>
#include <QToolButton>
#include "../../visualization/line/vistoolbisector.h"
@ -47,6 +48,7 @@
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/vcommonsettings.h"
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "ui_dialogbisector.h"
//---------------------------------------------------------------------------------------------------------------------
@ -55,22 +57,29 @@
* @param data container with data
* @param parent parent widget
*/
DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogBisector), formula(QString()), formulaBaseHeight(0)
DialogBisector::DialogBisector(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogBisector),
formula(),
pointName(),
formulaBaseHeight(0),
timerFormula(new QTimer(this)),
flagFormula(false),
flagError(true),
flagName(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogBisector::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
@ -79,8 +88,15 @@ DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QW
FillComboBoxLineColors(ui->comboBoxLineColor);
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogBisector::FXLength);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogBisector::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogBisector::FormulaTextChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogBisector::DeployFormulaTextEdit);
connect(ui->comboBoxFirstPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogBisector::PointNameChanged);
@ -92,12 +108,6 @@ DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QW
vis = new VisToolBisector(data);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::FormulaTextChanged()
{
this->FormulaChangedPlainText();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::PointNameChanged()
{
@ -106,7 +116,7 @@ void DialogBisector::PointNameChanged()
set.insert(getCurrentObjectId(ui->comboBoxSecondPoint));
set.insert(getCurrentObjectId(ui->comboBoxThirdPoint));
QColor color = okColor;
QColor color;
if (set.size() != 3)
{
flagError = false;
@ -115,7 +125,7 @@ void DialogBisector::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelFirstPoint, color);
ChangeColor(ui->labelSecondPoint, color);
@ -137,6 +147,20 @@ void DialogBisector::FXLength()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::EvalFormula()
{
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::ShowVisualization()
{
@ -146,7 +170,7 @@ void DialogBisector::ShowVisualization()
//---------------------------------------------------------------------------------------------------------------------
void DialogBisector::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -155,6 +179,12 @@ DialogBisector::~DialogBisector()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogBisector::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.

View File

@ -51,9 +51,10 @@ class DialogBisector : public DialogTool
Q_OBJECT
public:
DialogBisector(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogBisector(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogBisector() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetTypeLine() const;
@ -79,12 +80,10 @@ public slots:
* @brief DeployFormulaTextEdit grow or shrink formula input
*/
void DeployFormulaTextEdit();
/**
* @brief FormulaTextChanged when formula text changes for validation and calc
*/
void FormulaTextChanged();
virtual void PointNameChanged() override;
void FXLength();
void EvalFormula();
protected:
virtual void ShowVisualization() override;
/**
@ -92,6 +91,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogBisector)
@ -99,10 +99,23 @@ private:
Ui::DialogBisector *ui;
/** @brief formula formula */
QString formula;
QString formula;
QString pointName;
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
QTimer *timerFormula;
bool flagFormula;
bool flagError;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogBisector::IsValid() const
{
return flagFormula && flagError && flagName;
}
#endif // DIALOGBISECTOR_H

View File

@ -44,11 +44,12 @@
#include "ui_dialogcubicbezier.h"
//---------------------------------------------------------------------------------------------------------------------
DialogCubicBezier::DialogCubicBezier(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogCubicBezier::DialogCubicBezier(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogCubicBezier),
spl(),
newDuplicate(-1)
newDuplicate(-1),
flagError(false)
{
ui->setupUi(this);
InitOkCancelApply(ui);
@ -62,8 +63,6 @@ DialogCubicBezier::DialogCubicBezier(const VContainer *data, const quint32 &tool
ui->doubleSpinBoxApproximationScale->setMaximum(maxCurveApproximationScale);
DialogTool::CheckState();
connect(ui->comboBoxP1, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogCubicBezier::PointNameChanged);
connect(ui->comboBoxP2, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -174,7 +173,7 @@ void DialogCubicBezier::ChosenObject(quint32 id, const SceneObject &type)
//---------------------------------------------------------------------------------------------------------------------
void DialogCubicBezier::PointNameChanged()
{
QColor color = okColor;
QColor color;
if (getCurrentObjectId(ui->comboBoxP1) == getCurrentObjectId(ui->comboBoxP4))
{
flagError = false;
@ -185,7 +184,7 @@ void DialogCubicBezier::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
if (getCurrentObjectId(ui->comboBoxP1) == spl.GetP1().id() &&
getCurrentObjectId(ui->comboBoxP4) == spl.GetP4().id())

View File

@ -52,7 +52,7 @@ class DialogCubicBezier : public DialogTool
Q_OBJECT
public:
explicit DialogCubicBezier(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
explicit DialogCubicBezier(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogCubicBezier();
VCubicBezier GetSpline() const;
@ -66,6 +66,7 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogCubicBezier)
Ui::DialogCubicBezier *ui;
@ -75,10 +76,18 @@ private:
qint32 newDuplicate;
bool flagError;
const QSharedPointer<VPointF> GetP1() const;
const QSharedPointer<VPointF> GetP2() const;
const QSharedPointer<VPointF> GetP3() const;
const QSharedPointer<VPointF> GetP4() const;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogCubicBezier::IsValid() const
{
return flagError;
}
#endif // DIALOGCUBICBEZIER_H

View File

@ -58,11 +58,12 @@
class QWidget;
//---------------------------------------------------------------------------------------------------------------------
DialogCubicBezierPath::DialogCubicBezierPath(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogCubicBezierPath::DialogCubicBezierPath(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogCubicBezierPath),
path(),
newDuplicate(-1)
newDuplicate(-1),
flagError(false)
{
ui->setupUi(this);
@ -223,7 +224,7 @@ void DialogCubicBezierPath::currentPointChanged(int index)
DataPoint(*point);
item->setData(Qt::UserRole, QVariant::fromValue(*point));
QColor color = okColor;
QColor color;
if (not IsPathValid())
{
flagError = false;
@ -234,7 +235,7 @@ void DialogCubicBezierPath::currentPointChanged(int index)
else
{
flagError = true;
color = okColor;
color = OkColor(this);
auto first = qvariant_cast<VPointF>(ui->listWidget->item(0)->data(Qt::UserRole));
auto last = qvariant_cast<VPointF>(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole));

View File

@ -51,7 +51,7 @@ class DialogCubicBezierPath : public DialogTool
Q_OBJECT
public:
explicit DialogCubicBezierPath(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
explicit DialogCubicBezierPath(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogCubicBezierPath();
VCubicBezierPath GetPath() const;
@ -62,6 +62,7 @@ public slots:
protected:
virtual void ShowVisualization() override;
virtual void SaveData() override;
virtual bool IsValid() const final;
private slots:
void PointChanged(int row);
void currentPointChanged(int index);
@ -75,6 +76,8 @@ private:
qint32 newDuplicate;
bool flagError;
void NewItem(const VPointF &point);
void DataPoint(const VPointF &p);
void SavePath();
@ -83,4 +86,10 @@ private:
VCubicBezierPath ExtractPath() const;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogCubicBezierPath::IsValid() const
{
return flagError;
}
#endif // DIALOGCUBICBEZIERPATH_H

View File

@ -54,26 +54,28 @@
#include "ui_dialogcurveintersectaxis.h"
//---------------------------------------------------------------------------------------------------------------------
DialogCurveIntersectAxis::DialogCurveIntersectAxis(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogCurveIntersectAxis::DialogCurveIntersectAxis(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogCurveIntersectAxis),
formulaAngle(),
formulaBaseHeightAngle(0),
m_firstRelease(false)
pointName(),
m_firstRelease(false),
timerFormula(new QTimer(this)),
flagFormula(false),
flagName(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeightAngle = ui->plainTextEditFormula->height();
formulaBaseHeightAngle = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxAxisPoint);
FillComboBoxCurves(ui->comboBoxCurve);
@ -81,8 +83,15 @@ DialogCurveIntersectAxis::DialogCurveIntersectAxis(const VContainer *data, const
FillComboBoxLineColors(ui->comboBoxLineColor);
connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogCurveIntersectAxis::FXAngle);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCurveIntersectAxis::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCurveIntersectAxis::AngleTextChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLengthAngle, &QPushButton::clicked, this, &DialogCurveIntersectAxis::DeployAngleTextEdit);
connect(timerFormula, &QTimer::timeout, this, &DialogCurveIntersectAxis::EvalAngle);
@ -95,6 +104,12 @@ DialogCurveIntersectAxis::~DialogCurveIntersectAxis()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogCurveIntersectAxis::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCurveIntersectAxis::SetPointName(const QString &value)
{
@ -147,7 +162,7 @@ quint32 DialogCurveIntersectAxis::GetBasePointId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCurveIntersectAxis::SetBasePointId(const quint32 &value)
void DialogCurveIntersectAxis::SetBasePointId(quint32 value)
{
setCurrentPointId(ui->comboBoxAxisPoint, value);
@ -163,7 +178,7 @@ quint32 DialogCurveIntersectAxis::getCurveId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCurveIntersectAxis::setCurveId(const quint32 &value)
void DialogCurveIntersectAxis::setCurveId(quint32 value)
{
setCurrentCurveId(ui->comboBoxCurve, value);
@ -269,19 +284,21 @@ void DialogCurveIntersectAxis::ChosenObject(quint32 id, const SceneObject &type)
//---------------------------------------------------------------------------------------------------------------------
void DialogCurveIntersectAxis::EvalAngle()
{
Eval(ui->plainTextEditFormula->toPlainText(), flagError, ui->labelResultCalculation, degreeSymbol, false);
}
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
//---------------------------------------------------------------------------------------------------------------------
void DialogCurveIntersectAxis::AngleTextChanged()
{
ValFormulaChanged(flagError, ui->plainTextEditFormula, timerFormula, degreeSymbol);
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCurveIntersectAxis::DeployAngleTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -48,9 +48,10 @@ class DialogCurveIntersectAxis : public DialogTool
Q_OBJECT
public:
DialogCurveIntersectAxis(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogCurveIntersectAxis(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogCurveIntersectAxis() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetTypeLine() const;
@ -60,10 +61,10 @@ public:
void SetAngle(const QString &value);
quint32 GetBasePointId() const;
void SetBasePointId(const quint32 &value);
void SetBasePointId(quint32 value);
quint32 getCurveId() const;
void setCurveId(const quint32 &value);
void setCurveId(quint32 value);
QString GetLineColor() const;
void SetLineColor(const QString &value);
@ -72,7 +73,6 @@ public:
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
void EvalAngle();
void AngleTextChanged();
void DeployAngleTextEdit();
void FXAngle();
protected:
@ -82,6 +82,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogCurveIntersectAxis)
Ui::DialogCurveIntersectAxis *ui;
@ -89,7 +90,20 @@ private:
QString formulaAngle;
int formulaBaseHeightAngle;
QString pointName;
bool m_firstRelease;
QTimer *timerFormula;
bool flagFormula;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogCurveIntersectAxis::IsValid() const
{
return flagFormula && flagName;
}
#endif // DIALOGCURVEINTERSECTAXIS_H

View File

@ -33,9 +33,11 @@
#include <QPlainTextEdit>
#include <QPointer>
#include <QPushButton>
#include <QTimer>
#include <QToolButton>
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../../visualization/path/vistoolcutarc.h"
#include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h"
@ -51,39 +53,46 @@
* @param data container with data
* @param parent parent widget
*/
DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent)
: DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), formula(QString()), formulaBaseHeight(0)
DialogCutArc::DialogCutArc(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogCutArc),
formula(),
pointName(),
formulaBaseHeight(0),
timerFormula(new QTimer(this)),
flagFormula(false),
flagName(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogCutArc::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxArcs(ui->comboBoxArc);
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutArc::FXLength);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutArc::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutArc::FormulaTextChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutArc::DeployFormulaTextEdit);
vis = new VisToolCutArc(data);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::FormulaTextChanged()
{
this->FormulaChangedPlainText();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::FXLength()
{
@ -98,6 +107,20 @@ void DialogCutArc::FXLength()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::EvalFormula()
{
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::ShowVisualization()
{
@ -107,7 +130,7 @@ void DialogCutArc::ShowVisualization()
//---------------------------------------------------------------------------------------------------------------------
void DialogCutArc::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -116,6 +139,12 @@ DialogCutArc::~DialogCutArc()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogCutArc::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
@ -165,7 +194,7 @@ void DialogCutArc::closeEvent(QCloseEvent *event)
* @brief setArcId set id of arc
* @param value id
*/
void DialogCutArc::setArcId(const quint32 &value)
void DialogCutArc::setArcId(quint32 value)
{
setCurrentArcId(ui->comboBoxArc, value);

View File

@ -51,27 +51,26 @@ class DialogCutArc : public DialogTool
Q_OBJECT
public:
DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogCutArc(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogCutArc() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetFormula() const;
void SetFormula(const QString &value);
quint32 getArcId() const;
void setArcId(const quint32 &value);
void setArcId(quint32 value);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
/**
* @brief DeployFormulaTextEdit grow or shrink formula input
*/
void DeployFormulaTextEdit();
/**
* @brief FormulaTextChanged when formula text changes for validation and calc
*/
void FormulaTextChanged();
void FXLength();
void EvalFormula();
protected:
virtual void ShowVisualization() override;
/**
@ -79,16 +78,29 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogCutArc)
/** @brief ui keeps information about user interface */
Ui::DialogCutArc *ui;
/** @brief formula string with formula */
QString formula;
QString formula;
QString pointName;
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
QTimer *timerFormula;
bool flagFormula;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogCutArc::IsValid() const
{
return flagFormula && flagName;
}
#endif // DIALOGCUTARC_H

View File

@ -33,9 +33,11 @@
#include <QPlainTextEdit>
#include <QPointer>
#include <QPushButton>
#include <QTimer>
#include <QToolButton>
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../../visualization/path/vistoolcutspline.h"
#include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h"
@ -51,28 +53,41 @@
* @param data container with data
* @param parent parent widget
*/
DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), formula(QString()), formulaBaseHeight(0)
DialogCutSpline::DialogCutSpline(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogCutSpline),
formula(),
formulaBaseHeight(0),
pointName(),
timerFormula(new QTimer(this)),
flagFormula(false),
flagName(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogCutSpline::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxSplines(ui->comboBoxSpline);
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutSpline::FXLength);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSpline::FormulaChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit);
vis = new VisToolCutSpline(data);
@ -84,6 +99,12 @@ DialogCutSpline::~DialogCutSpline()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogCutSpline::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetPointName set name of point
@ -123,7 +144,7 @@ void DialogCutSpline::SetFormula(const QString &value)
* @brief setSplineId set id spline
* @param value id
*/
void DialogCutSpline::setSplineId(const quint32 &value)
void DialogCutSpline::setSplineId(quint32 value)
{
setCurrentSplineId(ui->comboBoxSpline, value);
@ -179,7 +200,7 @@ void DialogCutSpline::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -196,6 +217,20 @@ void DialogCutSpline::FXLength()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::EvalFormula()
{
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSpline::ShowVisualization()
{

View File

@ -50,16 +50,17 @@ class DialogCutSpline : public DialogTool
{
Q_OBJECT
public:
DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogCutSpline(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogCutSpline() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetFormula() const;
void SetFormula(const QString &value);
quint32 getSplineId() const;
void setSplineId(const quint32 &value);
void setSplineId(quint32 value);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
/**
@ -67,6 +68,7 @@ public slots:
*/
void DeployFormulaTextEdit();
void FXLength();
void EvalFormula();
protected:
virtual void ShowVisualization() override;
/**
@ -74,6 +76,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogCutSpline)
@ -81,10 +84,23 @@ private:
Ui::DialogCutSpline *ui;
/** @brief formula string with formula */
QString formula;
QString formula;
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
int formulaBaseHeight;
QString pointName;
QTimer *timerFormula;
bool flagFormula;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogCutSpline::IsValid() const
{
return flagFormula && flagName;
}
#endif // DIALOGCUTSPLINE_H

View File

@ -33,9 +33,11 @@
#include <QPlainTextEdit>
#include <QPointer>
#include <QPushButton>
#include <QTimer>
#include <QToolButton>
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../../visualization/path/vistoolcutsplinepath.h"
#include "../../visualization/visualization.h"
#include "../ifc/xml/vabstractpattern.h"
@ -51,28 +53,41 @@
* @param data container with data
* @param parent parent widget
*/
DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), formula(QString()), formulaBaseHeight(0)
DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogCutSplinePath),
formula(),
pointName(),
formulaBaseHeight(0),
timerFormula(new QTimer(this)),
flagFormula(false),
flagName(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogCutSplinePath::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxSplinesPath(ui->comboBoxSplinePath);
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogCutSplinePath::FXLength);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSplinePath::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSplinePath::FormulaChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSplinePath::DeployFormulaTextEdit);
vis = new VisToolCutSplinePath(data);
@ -84,6 +99,12 @@ DialogCutSplinePath::~DialogCutSplinePath()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogCutSplinePath::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetPointName set name of point
@ -123,7 +144,7 @@ void DialogCutSplinePath::SetFormula(const QString &value)
* @brief setSplineId set id spline
* @param value id
*/
void DialogCutSplinePath::setSplinePathId(const quint32 &value)
void DialogCutSplinePath::setSplinePathId(quint32 value)
{
setCurrentSplinePathId(ui->comboBoxSplinePath, value);
@ -179,7 +200,7 @@ void DialogCutSplinePath::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSplinePath::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -196,6 +217,20 @@ void DialogCutSplinePath::FXLength()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSplinePath::EvalFormula()
{
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogCutSplinePath::ShowVisualization()
{

View File

@ -50,16 +50,17 @@ class DialogCutSplinePath : public DialogTool
{
Q_OBJECT
public:
DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogCutSplinePath(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogCutSplinePath() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetFormula() const;
void SetFormula(const QString &value);
quint32 getSplinePathId() const;
void setSplinePathId(const quint32 &value);
void setSplinePathId(quint32 value);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
/**
@ -67,6 +68,7 @@ public slots:
*/
void DeployFormulaTextEdit();
void FXLength();
void EvalFormula();
protected:
virtual void ShowVisualization() override;
/**
@ -74,6 +76,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogCutSplinePath)
@ -81,10 +84,22 @@ private:
Ui::DialogCutSplinePath *ui;
/** @brief formula string with formula */
QString formula;
QString formula;
QString pointName;
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
QTimer *timerFormula;
bool flagFormula;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogCutSplinePath::IsValid() const
{
return flagFormula;
}
#endif // DIALOGCUTSPLINEPATH_H

View File

@ -54,7 +54,7 @@
* @param data container with data
* @param parent parent widget
*/
DialogEllipticalArc::DialogEllipticalArc(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogEllipticalArc::DialogEllipticalArc(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogEllipticalArc),
flagRadius1(false),
@ -62,11 +62,11 @@ DialogEllipticalArc::DialogEllipticalArc(const VContainer *data, const quint32 &
flagF1(false),
flagF2(false),
flagRotationAngle(false),
timerRadius1(nullptr),
timerRadius2(nullptr),
timerF1(nullptr),
timerF2(nullptr),
timerRotationAngle(nullptr),
timerRadius1(new QTimer(this)),
timerRadius2(new QTimer(this)),
timerF1(new QTimer(this)),
timerF2(new QTimer(this)),
timerRotationAngle(new QTimer(this)),
radius1(),
radius2(),
f1(),
@ -95,19 +95,19 @@ DialogEllipticalArc::DialogEllipticalArc(const VContainer *data, const quint32 &
ui->plainTextEditF2->installEventFilter(this);
ui->plainTextEditRotationAngle->installEventFilter(this);
timerRadius1 = new QTimer(this);
timerRadius1->setSingleShot(true);
connect(timerRadius1, &QTimer::timeout, this, &DialogEllipticalArc::EvalRadiuses);
timerRadius2 = new QTimer(this);
timerRadius2->setSingleShot(true);
connect(timerRadius2, &QTimer::timeout, this, &DialogEllipticalArc::EvalRadiuses);
timerF1 = new QTimer(this);
timerF1->setSingleShot(true);
connect(timerF1, &QTimer::timeout, this, &DialogEllipticalArc::EvalAngles);
timerF2 = new QTimer(this);
timerF2->setSingleShot(true);
connect(timerF2, &QTimer::timeout, this, &DialogEllipticalArc::EvalAngles);
timerRotationAngle = new QTimer(this);
timerRotationAngle->setSingleShot(true);
connect(timerRotationAngle, &QTimer::timeout, this, &DialogEllipticalArc::EvalAngles);
InitOkCancelApply(ui);
@ -116,20 +116,36 @@ DialogEllipticalArc::DialogEllipticalArc(const VContainer *data, const quint32 &
FillComboBoxLineColors(ui->comboBoxColor);
FillComboBoxTypeLine(ui->comboBoxPenStyle, CurvePenStylesPics());
CheckState();
connect(ui->toolButtonExprRadius1, &QPushButton::clicked, this, &DialogEllipticalArc::FXRadius1);
connect(ui->toolButtonExprRadius2, &QPushButton::clicked, this, &DialogEllipticalArc::FXRadius2);
connect(ui->toolButtonExprF1, &QPushButton::clicked, this, &DialogEllipticalArc::FXF1);
connect(ui->toolButtonExprF2, &QPushButton::clicked, this, &DialogEllipticalArc::FXF2);
connect(ui->toolButtonExprRotationAngle, &QPushButton::clicked, this, &DialogEllipticalArc::FXRotationAngle);
connect(ui->plainTextEditRadius1, &QPlainTextEdit::textChanged, this, &DialogEllipticalArc::Radius1Changed);
connect(ui->plainTextEditRadius2, &QPlainTextEdit::textChanged, this, &DialogEllipticalArc::Radius2Changed);
connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, &DialogEllipticalArc::F1Changed);
connect(ui->plainTextEditF2, &QPlainTextEdit::textChanged, this, &DialogEllipticalArc::F2Changed);
connect(ui->plainTextEditRotationAngle, &QPlainTextEdit::textChanged,
this, &DialogEllipticalArc::RotationAngleChanged);
connect(ui->plainTextEditRadius1, &QPlainTextEdit::textChanged, this, [this]()
{
timerRadius1->start(formulaTimerTimeout);
});
connect(ui->plainTextEditRadius2, &QPlainTextEdit::textChanged, this, [this]()
{
timerRadius2->start(formulaTimerTimeout);
});
connect(ui->plainTextEditF1, &QPlainTextEdit::textChanged, this, [this]()
{
timerF1->start(formulaTimerTimeout);
});
connect(ui->plainTextEditF2, &QPlainTextEdit::textChanged, this, [this]()
{
timerF2->start(formulaTimerTimeout);
});
connect(ui->plainTextEditRotationAngle, &QPlainTextEdit::textChanged, this, [this]()
{
timerRotationAngle->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLengthRadius1, &QPushButton::clicked, this, &DialogEllipticalArc::DeployRadius1TextEdit);
connect(ui->pushButtonGrowLengthRadius2, &QPushButton::clicked, this, &DialogEllipticalArc::DeployRadius2TextEdit);
@ -366,31 +382,21 @@ void DialogEllipticalArc::SetColor(const QString &value)
*/
void DialogEllipticalArc::EvalRadiuses()
{
labelEditFormula = ui->labelEditRadius1;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius_1 = Eval(ui->plainTextEditRadius1->toPlainText(), flagRadius1, ui->labelResultRadius1, postfix);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditRadius1->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditRadius1;
formulaData.labelResult = ui->labelResultRadius1;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkLessThanZero = true;
if (radius_1 < 0)
{
flagRadius1 = false;
ChangeColor(labelEditFormula, Qt::red);
ui->labelResultRadius1->setText(tr("Error"));
ui->labelResultRadius1->setToolTip(tr("Radius can't be negative"));
Eval(formulaData, flagRadius1);
DialogEllipticalArc::CheckState();
}
formulaData.formula = ui->plainTextEditRadius2->toPlainText();
formulaData.labelEditFormula = ui->labelEditRadius2;
formulaData.labelResult = ui->labelResultRadius2;
labelEditFormula = ui->labelEditRadius2;
const qreal radius_2 = Eval(ui->plainTextEditRadius2->toPlainText(), flagRadius2, ui->labelResultRadius2, postfix);
if (radius_2 < 0)
{
flagRadius2 = false;
ChangeColor(labelEditFormula, Qt::red);
ui->labelResultRadius2->setText(tr("Error"));
ui->labelResultRadius2->setToolTip(tr("Radius can't be negative"));
DialogEllipticalArc::CheckState();
}
Eval(formulaData, flagRadius2);
}
//---------------------------------------------------------------------------------------------------------------------
@ -399,15 +405,27 @@ void DialogEllipticalArc::EvalRadiuses()
*/
void DialogEllipticalArc::EvalAngles()
{
labelEditFormula = ui->labelEditF1;
angleF1 = Eval(ui->plainTextEditF1->toPlainText(), flagF1, ui->labelResultF1, degreeSymbol, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditF1->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditF1;
formulaData.labelResult = ui->labelResultF1;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
labelEditFormula = ui->labelEditF2;
angleF2 = Eval(ui->plainTextEditF2->toPlainText(), flagF2, ui->labelResultF2, degreeSymbol, false);
angleF1 = Eval(formulaData, flagF1);
labelEditFormula = ui->labelEditRotationAngle;
angleRotation = Eval(ui->plainTextEditRotationAngle->toPlainText(), flagRotationAngle,
ui->labelResultRotationAngle, degreeSymbol, false);
formulaData.formula = ui->plainTextEditF2->toPlainText();
formulaData.labelEditFormula = ui->labelEditF2;
formulaData.labelResult = ui->labelResultF2;
angleF2 = Eval(formulaData, flagF2);
formulaData.formula = ui->plainTextEditRotationAngle->toPlainText();
formulaData.labelEditFormula = ui->labelEditRotationAngle;
formulaData.labelResult = ui->labelResultRotationAngle;
angleRotation = Eval(formulaData, flagRotationAngle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -480,91 +498,34 @@ void DialogEllipticalArc::FXRotationAngle()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Radius1Changed after change formula of radius1 calculate value and show result
*/
void DialogEllipticalArc::Radius1Changed()
{
labelEditFormula = ui->labelEditRadius1;
labelResultCalculation = ui->labelResultRadius1;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagRadius1, ui->plainTextEditRadius1, timerRadius1, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Radius2Changed after change formula of radius2 calculate value and show result
*/
void DialogEllipticalArc::Radius2Changed()
{
labelEditFormula = ui->labelEditRadius2;
labelResultCalculation = ui->labelResultRadius2;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagRadius2, ui->plainTextEditRadius2, timerRadius2, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief F1Changed after change formula of first angle calculate value and show result
*/
void DialogEllipticalArc::F1Changed()
{
labelEditFormula = ui->labelEditF1;
labelResultCalculation = ui->labelResultF1;
ValFormulaChanged(flagF1, ui->plainTextEditF1, timerF1, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief F2Changed after change formula of second angle calculate value and show result
*/
void DialogEllipticalArc::F2Changed()
{
labelEditFormula = ui->labelEditF2;
labelResultCalculation = ui->labelResultF2;
ValFormulaChanged(flagF2, ui->plainTextEditF2, timerF2, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief RotationAngleChanged after change formula of rotation angle calculate value and show result
*/
void DialogEllipticalArc::RotationAngleChanged()
{
labelEditFormula = ui->labelEditRotationAngle;
labelResultCalculation = ui->labelResultF2;
ValFormulaChanged(flagRotationAngle, ui->plainTextEditRotationAngle, timerRotationAngle, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEllipticalArc::DeployRadius1TextEdit()
{
DeployFormula(ui->plainTextEditRadius1, ui->pushButtonGrowLengthRadius1, formulaBaseHeightRadius1);
DeployFormula(this, ui->plainTextEditRadius1, ui->pushButtonGrowLengthRadius1, formulaBaseHeightRadius1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEllipticalArc::DeployRadius2TextEdit()
{
DeployFormula(ui->plainTextEditRadius2, ui->pushButtonGrowLengthRadius2, formulaBaseHeightRadius2);
DeployFormula(this, ui->plainTextEditRadius2, ui->pushButtonGrowLengthRadius2, formulaBaseHeightRadius2);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEllipticalArc::DeployF1TextEdit()
{
DeployFormula(ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
DeployFormula(this, ui->plainTextEditF1, ui->pushButtonGrowLengthF1, formulaBaseHeightF1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEllipticalArc::DeployF2TextEdit()
{
DeployFormula(ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
DeployFormula(this, ui->plainTextEditF2, ui->pushButtonGrowLengthF2, formulaBaseHeightF2);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEllipticalArc::DeployRotationAngleTextEdit()
{
DeployFormula(ui->plainTextEditRotationAngle, ui->pushButtonGrowLengthRotationAngle,formulaBaseHeightRotationAngle);
DeployFormula(this, ui->plainTextEditRotationAngle, ui->pushButtonGrowLengthRotationAngle,formulaBaseHeightRotationAngle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -590,18 +551,6 @@ void DialogEllipticalArc::ChosenObject(quint32 id, const SceneObject &type)
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief CheckState if all is right enable button ok
*/
void DialogEllipticalArc::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagRadius1 && flagRadius2 && flagF1 && flagF2 && flagRotationAngle);
SCASSERT(bApply != nullptr)
bApply->setEnabled(flagRadius1 && flagRadius2 && flagF1 && flagF2 && flagRotationAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEllipticalArc::ShowVisualization()
{

View File

@ -47,7 +47,7 @@ class DialogEllipticalArc : public DialogTool
{
Q_OBJECT
public:
DialogEllipticalArc(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogEllipticalArc(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogEllipticalArc() override;
quint32 GetCenter() const;
@ -85,12 +85,6 @@ public slots:
void DeployF2TextEdit();
void DeployRotationAngleTextEdit();
void Radius1Changed();
void Radius2Changed();
void F1Changed();
void F2Changed();
void RotationAngleChanged();
void FXRadius1();
void FXRadius2();
void FXF1();
@ -98,13 +92,13 @@ public slots:
void FXRotationAngle();
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
/**
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogEllipticalArc)
@ -172,4 +166,10 @@ private:
void EvalAngles();
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogEllipticalArc::IsValid() const
{
return flagRadius1 && flagRadius2 && flagF1 && flagF2 && flagRotationAngle;
}
#endif // DIALOGELLIPTICALARC_H

View File

@ -61,22 +61,29 @@
* @param data container with data
* @param parent parent widget
*/
DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogEndLine::DialogEndLine(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogEndLine),
formulaLength(),
formulaAngle(),
formulaBaseHeight(0),
formulaBaseHeightAngle(0),
m_firstRelease(false)
pointName(),
m_firstRelease(false),
timerFormulaLength(new QTimer(this)),
timerFormulaAngle(new QTimer(this)),
flagFormula(false),
flagError(false),
flagName(true)
{
ui->setupUi(this);
timerFormulaLength->setSingleShot(true);
timerFormulaAngle->setSingleShot(true);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
this->formulaBaseHeightAngle = ui->plainTextEditAngle->height();
@ -85,7 +92,6 @@ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWid
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxBasePoint);
FillComboBoxTypeLine(ui->comboBoxLineType, LineStylesPics());
@ -94,15 +100,27 @@ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWid
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogEndLine::FXLength);
connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogEndLine::FXAngle);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged);
connect(ui->plainTextEditAngle, &QPlainTextEdit::textChanged, this, &DialogEndLine::AngleTextChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormulaLength->start(formulaTimerTimeout);
});
connect(ui->plainTextEditAngle, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormulaAngle->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit);
connect(ui->pushButtonGrowLengthAngle, &QPushButton::clicked, this, &DialogEndLine::DeployAngleTextEdit);
connect(timerFormula, &QTimer::timeout, this, &DialogEndLine::EvalAngle);
connect(timerFormulaLength, &QTimer::timeout, this, &DialogEndLine::EvalLength);
connect(timerFormulaAngle, &QTimer::timeout, this, &DialogEndLine::EvalAngle);
vis = new VisToolEndLine(data);
}
@ -113,35 +131,41 @@ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWid
*/
void DialogEndLine::EvalAngle()
{
labelEditFormula = ui->labelEditAngle;
Eval(ui->plainTextEditAngle->toPlainText(), flagError, ui->labelResultCalculationAngle, degreeSymbol, false);
labelEditFormula = ui->labelEditFormula;
FormulaData formulaData;
formulaData.formula = ui->plainTextEditAngle->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditAngle;
formulaData.labelResult = ui->labelResultCalculationAngle;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, flagError);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::FormulaTextChanged()
void DialogEndLine::EvalLength()
{
this->FormulaChangedPlainText();
}
FormulaData formulaData;
formulaData.formula = ui->plainTextEditAngle->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkLessThanZero = true;
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::AngleTextChanged()
{
labelEditFormula = ui->labelEditAngle;
ValFormulaChanged(flagError, ui->plainTextEditAngle, timerFormula, degreeSymbol);
labelEditFormula = ui->labelEditFormula;
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogEndLine::DeployAngleTextEdit()
{
DeployFormula(ui->plainTextEditAngle, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle);
DeployFormula(this, ui->plainTextEditAngle, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -329,7 +353,7 @@ void DialogEndLine::ShowDialog(bool click)
this->SetAngle(line->Angle());//Show in dialog angle what user choose
this->SetFormula(line->Length());
emit ToolTip(QString());
timerFormula->start();
timerFormulaLength->start();
this->show();
}
}
@ -371,6 +395,12 @@ DialogEndLine::~DialogEndLine()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogEndLine::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetTypeLine return type of line

View File

@ -50,9 +50,10 @@ class DialogEndLine : public DialogTool
{
Q_OBJECT
public:
DialogEndLine(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogEndLine(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogEndLine() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetTypeLine() const;
@ -73,17 +74,12 @@ public:
virtual void ShowDialog(bool click) override;
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
/**
* @brief DeployFormulaTextEdit grow or shrink formula input
*/
void DeployFormulaTextEdit();
/**
* @brief FormulaTextChanged when formula text changes for validation and calc
*/
void FormulaTextChanged();
void EvalLength();
void EvalAngle();
void AngleTextChanged();
/** @brief DeployFormulaTextEdit grow or shrink formula input */
void DeployFormulaTextEdit();
void DeployAngleTextEdit();
void FXAngle();
@ -95,6 +91,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogEndLine)
@ -102,16 +99,31 @@ private:
Ui::DialogEndLine *ui;
/** @brief formula formula */
QString formulaLength;
QString formulaLength;
/** @brief angle angle of line */
QString formulaAngle;
QString formulaAngle;
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
int formulaBaseHeightAngle;
int formulaBaseHeight;
int formulaBaseHeightAngle;
QString pointName;
bool m_firstRelease;
QTimer *timerFormulaLength;
QTimer *timerFormulaAngle;
bool flagFormula;
bool flagError;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogEndLine::IsValid() const
{
return flagFormula && flagError && flagName;
}
#endif // DIALOGENDLINE_H

View File

@ -59,12 +59,14 @@
#include "ui_dialogflippingbyaxis.h"
//---------------------------------------------------------------------------------------------------------------------
DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogFlippingByAxis),
objects(),
stage1(true),
m_suffix()
m_suffix(),
flagName(false),
flagError(false)
{
ui->setupUi(this);
@ -75,9 +77,6 @@ DialogFlippingByAxis::DialogFlippingByAxis(const VContainer *data, const quint32
FillComboBoxPoints(ui->comboBoxOriginPoint);
FillComboBoxAxisType(ui->comboBoxAxisType);
flagName = true;
CheckState();
connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogFlippingByAxis::SuffixChanged);
connect(ui->comboBoxOriginPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogFlippingByAxis::PointChanged);
@ -244,7 +243,7 @@ void DialogFlippingByAxis::SuffixChanged()
if (suffix.isEmpty())
{
flagName = false;
ChangeColor(ui->labelSuffix, Qt::red);
ChangeColor(ui->labelSuffix, errorColor);
CheckState();
return;
}
@ -260,7 +259,7 @@ void DialogFlippingByAxis::SuffixChanged()
if (not rx.match(name).hasMatch() || not data->IsUnique(name))
{
flagName = false;
ChangeColor(ui->labelSuffix, Qt::red);
ChangeColor(ui->labelSuffix, errorColor);
CheckState();
return;
}
@ -269,20 +268,11 @@ void DialogFlippingByAxis::SuffixChanged()
}
flagName = true;
ChangeColor(ui->labelSuffix, okColor);
ChangeColor(ui->labelSuffix, OkColor(this));
}
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagError && flagName);
SCASSERT(bApply != nullptr)
bApply->setEnabled(bOk->isEnabled());
}
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::ShowVisualization()
{
@ -306,7 +296,7 @@ void DialogFlippingByAxis::SaveData()
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByAxis::PointChanged()
{
QColor color = okColor;
QColor color;
if (objects.contains(getCurrentObjectId(ui->comboBoxOriginPoint)))
{
flagError = false;
@ -315,7 +305,7 @@ void DialogFlippingByAxis::PointChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelOriginPoint, color);
CheckState();

View File

@ -51,7 +51,7 @@ class DialogFlippingByAxis : public DialogTool
Q_OBJECT
public:
explicit DialogFlippingByAxis(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
explicit DialogFlippingByAxis(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogFlippingByAxis();
quint32 GetOriginPointId() const;
@ -75,11 +75,11 @@ private slots:
void SuffixChanged();
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
/** @brief SaveData Put dialog data in local variables */
virtual void SaveData() override;
virtual bool IsValid() const final;
private slots:
void PointChanged();
@ -95,7 +95,16 @@ private:
QString m_suffix;
bool flagName;
bool flagError;
static void FillComboBoxAxisType(QComboBox *box);
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogFlippingByAxis::IsValid() const
{
return flagError && flagName;
}
#endif // DIALOGFLIPPINGBYAXIS_H

View File

@ -59,12 +59,14 @@
#include "ui_dialogflippingbyline.h"
//---------------------------------------------------------------------------------------------------------------------
DialogFlippingByLine::DialogFlippingByLine(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogFlippingByLine::DialogFlippingByLine(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogFlippingByLine),
objects(),
stage1(true),
m_suffix()
m_suffix(),
flagName(false),
flagError(false)
{
ui->setupUi(this);
@ -75,9 +77,6 @@ DialogFlippingByLine::DialogFlippingByLine(const VContainer *data, const quint32
FillComboBoxPoints(ui->comboBoxFirstLinePoint);
FillComboBoxPoints(ui->comboBoxSecondLinePoint);
flagName = true;
CheckState();
connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogFlippingByLine::SuffixChanged);
connect(ui->comboBoxFirstLinePoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogFlippingByLine::PointChanged);
@ -271,7 +270,7 @@ void DialogFlippingByLine::SuffixChanged()
if (suffix.isEmpty())
{
flagName = false;
ChangeColor(ui->labelSuffix, Qt::red);
ChangeColor(ui->labelSuffix, errorColor);
CheckState();
return;
}
@ -287,7 +286,7 @@ void DialogFlippingByLine::SuffixChanged()
if (not rx.match(name).hasMatch() || not data->IsUnique(name))
{
flagName = false;
ChangeColor(ui->labelSuffix, Qt::red);
ChangeColor(ui->labelSuffix, errorColor);
CheckState();
return;
}
@ -296,20 +295,11 @@ void DialogFlippingByLine::SuffixChanged()
}
flagName = true;
ChangeColor(ui->labelSuffix, okColor);
ChangeColor(ui->labelSuffix, OkColor(this));
}
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByLine::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagError && flagName);
SCASSERT(bApply != nullptr)
bApply->setEnabled(bOk->isEnabled());
}
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByLine::ShowVisualization()
{
@ -333,7 +323,7 @@ void DialogFlippingByLine::SaveData()
//---------------------------------------------------------------------------------------------------------------------
void DialogFlippingByLine::PointChanged()
{
QColor color = okColor;
QColor color = OkColor(this);
flagError = true;
ChangeColor(ui->labelFirstLinePoint, color);
ChangeColor(ui->labelSecondLinePoint, color);

View File

@ -51,7 +51,7 @@ class DialogFlippingByLine : public DialogTool
Q_OBJECT
public:
explicit DialogFlippingByLine(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
explicit DialogFlippingByLine(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogFlippingByLine();
quint32 GetFirstLinePointId() const;
@ -75,11 +75,11 @@ private slots:
void SuffixChanged();
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
/** @brief SaveData Put dialog data in local variables */
virtual void SaveData() override;
virtual bool IsValid() const final;
private slots:
void PointChanged();
@ -94,6 +94,15 @@ private:
bool stage1;
QString m_suffix;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogFlippingByLine::IsValid() const
{
return flagError && flagName;
}
#endif // DIALOGFLIPPINGBYLINE_H

View File

@ -33,14 +33,14 @@
#include "ui_dialoggroup.h"
//---------------------------------------------------------------------------------------------------------------------
DialogGroup::DialogGroup(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogGroup::DialogGroup(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogGroup),
group()
group(),
flagName(false)
{
ui->setupUi(this);
InitOkCancel(ui);
DialogTool::CheckState();
connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogGroup::NameChanged);
}

View File

@ -48,7 +48,7 @@ class DialogGroup : public DialogTool
Q_OBJECT
public:
explicit DialogGroup(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
explicit DialogGroup(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
~DialogGroup();
void SetName(const QString &name);
@ -61,6 +61,9 @@ public:
public slots:
virtual void SelectedObject(bool selected, quint32 object, quint32 tool) override;
protected:
virtual bool IsValid() const final;
private slots:
void NameChanged();
@ -68,6 +71,13 @@ private:
Q_DISABLE_COPY(DialogGroup)
Ui::DialogGroup *ui;
QMap<quint32, quint32> group;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogGroup::IsValid() const
{
return flagName;
}
#endif // DIALOGGROUP_H

View File

@ -57,17 +57,19 @@
* @param data container with data
* @param parent parent widget
*/
DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogHeight)
DialogHeight::DialogHeight(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogHeight),
pointName(),
flagError(true),
flagName(true)
{
ui->setupUi(this);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui);
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxBasePoint);
FillComboBoxPoints(ui->comboBoxP1Line);
@ -75,7 +77,11 @@ DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidge
FillComboBoxTypeLine(ui->comboBoxLineType, LineStylesPics());
FillComboBoxLineColors(ui->comboBoxLineColor);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogHeight::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->comboBoxBasePoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogHeight::PointNameChanged);
connect(ui->comboBoxP1Line, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -92,6 +98,12 @@ DialogHeight::~DialogHeight()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogHeight::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetPointName set name of point
@ -260,7 +272,7 @@ void DialogHeight::PointNameChanged()
const QPointF p1Line = static_cast<QPointF>(*data->GeometricObject<VPointF>(p1LineId));
const QPointF p2Line = static_cast<QPointF>(*data->GeometricObject<VPointF>(p2LineId));
QColor color = okColor;
QColor color;
if (set.size() != 3 || VGObject::ClosestPoint(QLineF(p1Line, p2Line), basePoint) == QPointF())
{
flagError = false;
@ -269,7 +281,7 @@ void DialogHeight::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelBasePoint, color);
ChangeColor(ui->labelFirstLinePoint, color);

View File

@ -50,9 +50,10 @@ class DialogHeight : public DialogTool
{
Q_OBJECT
public:
DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogHeight(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogHeight() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetTypeLine() const;
@ -78,11 +79,23 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogHeight)
/** @brief ui keeps information about user interface */
Ui::DialogHeight *ui;
QString pointName;
bool flagError;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogHeight::IsValid() const
{
return flagError && flagName;
}
#endif // DIALOGHEIGHT_H

View File

@ -48,8 +48,10 @@
* @param data container with data
* @param parent parent widget
*/
DialogLine::DialogLine(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogLine)
DialogLine::DialogLine(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogLine),
flagError(true)
{
ui->setupUi(this);
InitOkCancelApply(ui);
@ -83,7 +85,7 @@ DialogLine::~DialogLine()
* @brief SetSecondPoint set id second point
* @param value id
*/
void DialogLine::SetSecondPoint(const quint32 &value)
void DialogLine::SetSecondPoint(quint32 value)
{
setCurrentPointId(ui->comboBoxSecondPoint, value);
@ -120,7 +122,7 @@ void DialogLine::SetLineColor(const QString &value)
* @brief SetFirstPoint set id first point
* @param value id
*/
void DialogLine::SetFirstPoint(const quint32 &value)
void DialogLine::SetFirstPoint(quint32 value)
{
setCurrentPointId(ui->comboBoxFirstPoint, value);
@ -132,7 +134,7 @@ void DialogLine::SetFirstPoint(const quint32 &value)
//---------------------------------------------------------------------------------------------------------------------
void DialogLine::PointNameChanged()
{
QColor color = okColor;
QColor color;
if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint))
{
flagError = false;
@ -141,7 +143,7 @@ void DialogLine::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelFirstPoint, color);
ChangeColor(ui->labelSecondPoint, color);

View File

@ -50,14 +50,14 @@ class DialogLine : public DialogTool
{
Q_OBJECT
public:
DialogLine(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogLine(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogLine() override;
quint32 GetFirstPoint() const;
void SetFirstPoint(const quint32 &value);
void SetFirstPoint(quint32 value);
quint32 GetSecondPoint() const;
void SetSecondPoint(const quint32 &value);
void SetSecondPoint(quint32 value);
QString GetTypeLine() const;
void SetTypeLine(const QString &value);
@ -73,11 +73,20 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogLine)
/** @brief ui keeps information about user interface */
Ui::DialogLine *ui;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogLine::IsValid() const
{
return flagError;
}
#endif // DIALOGLINE_H

View File

@ -56,8 +56,13 @@
* @param data container with data
* @param parent parent widget
*/
DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersect), flagPoint(true)
DialogLineIntersect::DialogLineIntersect(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogLineIntersect),
pointName(),
flagError(true),
flagPoint(true),
flagName(true)
{
ui->setupUi(this);
@ -66,14 +71,17 @@ DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 &
number = 0;
InitOkCancelApply(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
FillComboBoxPoints(ui->comboBoxP1Line1);
FillComboBoxPoints(ui->comboBoxP2Line1);
FillComboBoxPoints(ui->comboBoxP1Line2);
FillComboBoxPoints(ui->comboBoxP2Line2);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogLineIntersect::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->comboBoxP1Line1, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogLineIntersect::PointNameChanged);
connect(ui->comboBoxP2Line1, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -229,7 +237,7 @@ void DialogLineIntersect::PointNameChanged()
QPointF fPoint;
QLineF::IntersectType intersect = line1.intersect(line2, &fPoint);
QColor color = okColor;
QColor color;
if (set.size() < 3 || intersect == QLineF::NoIntersection)
{
flagError = false;
@ -238,7 +246,7 @@ void DialogLineIntersect::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelP1Line1, color);
ChangeColor(ui->labelP2Line1, color);
@ -253,16 +261,6 @@ void DialogLineIntersect::ShowVisualization()
AddVisualization<VisToolLineIntersect>();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief CheckState check state of dialog. Enable or disable button ok.
*/
void DialogLineIntersect::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagName && flagPoint);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief CheckIntersecion check intersection of points
@ -294,13 +292,19 @@ bool DialogLineIntersect::CheckIntersecion()
* @brief SetP2Line2 set id second point of second line
* @param value id
*/
void DialogLineIntersect::SetP2Line2(const quint32 &value)
void DialogLineIntersect::SetP2Line2(quint32 value)
{
setCurrentPointId(ui->comboBoxP2Line2, value);
VisToolLineIntersect *line = qobject_cast<VisToolLineIntersect *>(vis);
SCASSERT(line != nullptr)
line->setLine2P2Id(value);
line->setLine2P2Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogLineIntersect::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
@ -308,7 +312,7 @@ void DialogLineIntersect::SetP2Line2(const quint32 &value)
* @brief SetP1Line2 set id first point of second line
* @param value id
*/
void DialogLineIntersect::SetP1Line2(const quint32 &value)
void DialogLineIntersect::SetP1Line2(quint32 value)
{
setCurrentPointId(ui->comboBoxP1Line2, value);
@ -322,7 +326,7 @@ void DialogLineIntersect::SetP1Line2(const quint32 &value)
* @brief SetP2Line1 set id second point of first line
* @param value id
*/
void DialogLineIntersect::SetP2Line1(const quint32 &value)
void DialogLineIntersect::SetP2Line1(quint32 value)
{
setCurrentPointId(ui->comboBoxP2Line1, value);
@ -336,7 +340,7 @@ void DialogLineIntersect::SetP2Line1(const quint32 &value)
* @brief SetP1Line1 set id first point of first line
* @param value id
*/
void DialogLineIntersect::SetP1Line1(const quint32 &value)
void DialogLineIntersect::SetP1Line1(quint32 value)
{
setCurrentPointId(ui->comboBoxP1Line1, value);

View File

@ -50,21 +50,22 @@ class DialogLineIntersect : public DialogTool
{
Q_OBJECT
public:
DialogLineIntersect(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogLineIntersect(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogLineIntersect() override;
quint32 GetP1Line1() const;
void SetP1Line1(const quint32 &value);
void SetP1Line1(quint32 value);
quint32 GetP2Line1() const;
void SetP2Line1(const quint32 &value);
void SetP2Line1(quint32 value);
quint32 GetP1Line2() const;
void SetP1Line2(const quint32 &value);
void SetP1Line2(quint32 value);
quint32 GetP2Line2() const;
void SetP2Line2(const quint32 &value);
void SetP2Line2(quint32 value);
QString GetPointName() const;
void SetPointName(const QString &value);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
@ -76,17 +77,29 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogLineIntersect)
/** @brief ui keeps information about user interface */
Ui::DialogLineIntersect *ui;
/** @brief flagPoint keep state of point */
bool flagPoint;
QString pointName;
bool flagError;
/** @brief flagPoint keep state of point */
bool flagPoint;
bool flagName;
virtual void CheckState() final;
bool CheckIntersecion();
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogLineIntersect::IsValid() const
{
return flagName && flagError && flagPoint;
}
#endif // DIALOGLINEINTERSECT_H

View File

@ -59,26 +59,29 @@
#include "ui_dialoglineintersectaxis.h"
//---------------------------------------------------------------------------------------------------------------------
DialogLineIntersectAxis::DialogLineIntersectAxis(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogLineIntersectAxis::DialogLineIntersectAxis(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogLineIntersectAxis),
formulaAngle(),
formulaBaseHeightAngle(0),
m_firstRelease(false)
pointName(),
m_firstRelease(false),
timerFormula(new QTimer(this)),
flagFormula(false),
flagError(true),
flagName(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeightAngle = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxAxisPoint);
FillComboBoxPoints(ui->comboBoxFirstLinePoint);
@ -87,8 +90,15 @@ DialogLineIntersectAxis::DialogLineIntersectAxis(const VContainer *data, const q
FillComboBoxLineColors(ui->comboBoxLineColor);
connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogLineIntersectAxis::FXAngle);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogLineIntersectAxis::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogLineIntersectAxis::AngleTextChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLengthAngle, &QPushButton::clicked, this, &DialogLineIntersectAxis::DeployAngleTextEdit);
connect(timerFormula, &QTimer::timeout, this, &DialogLineIntersectAxis::EvalAngle);
connect(ui->comboBoxFirstLinePoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -107,6 +117,12 @@ DialogLineIntersectAxis::~DialogLineIntersectAxis()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogLineIntersectAxis::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLineIntersectAxis::SetPointName(const QString &value)
{
@ -159,7 +175,7 @@ quint32 DialogLineIntersectAxis::GetBasePointId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLineIntersectAxis::SetBasePointId(const quint32 &value)
void DialogLineIntersectAxis::SetBasePointId(quint32 value)
{
setCurrentPointId(ui->comboBoxAxisPoint, value);
@ -175,7 +191,7 @@ quint32 DialogLineIntersectAxis::GetFirstPointId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLineIntersectAxis::SetFirstPointId(const quint32 &value)
void DialogLineIntersectAxis::SetFirstPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxFirstLinePoint, value);
@ -191,7 +207,7 @@ quint32 DialogLineIntersectAxis::GetSecondPointId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLineIntersectAxis::SetSecondPointId(const quint32 &value)
void DialogLineIntersectAxis::SetSecondPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxSecondLinePoint, value);
@ -311,19 +327,21 @@ void DialogLineIntersectAxis::ChosenObject(quint32 id, const SceneObject &type)
//---------------------------------------------------------------------------------------------------------------------
void DialogLineIntersectAxis::EvalAngle()
{
Eval(ui->plainTextEditFormula->toPlainText(), flagError, ui->labelResultCalculation, degreeSymbol, false);
}
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
//---------------------------------------------------------------------------------------------------------------------
void DialogLineIntersectAxis::AngleTextChanged()
{
ValFormulaChanged(flagError, ui->plainTextEditFormula, timerFormula, degreeSymbol);
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLineIntersectAxis::DeployAngleTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -334,7 +352,7 @@ void DialogLineIntersectAxis::PointNameChanged()
set.insert(getCurrentObjectId(ui->comboBoxSecondLinePoint));
set.insert(getCurrentObjectId(ui->comboBoxAxisPoint));
QColor color = okColor;
QColor color;
if (set.size() != 3)
{
flagError = false;
@ -343,7 +361,7 @@ void DialogLineIntersectAxis::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelFirstLinePoint, color);
ChangeColor(ui->labelSecondLinePoint, color);

View File

@ -48,9 +48,10 @@ class DialogLineIntersectAxis : public DialogTool
Q_OBJECT
public:
DialogLineIntersectAxis(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogLineIntersectAxis(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogLineIntersectAxis() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetTypeLine() const;
@ -60,13 +61,13 @@ public:
void SetAngle(const QString &value);
quint32 GetBasePointId() const;
void SetBasePointId(const quint32 &value);
void SetBasePointId(quint32 value);
quint32 GetFirstPointId() const;
void SetFirstPointId(const quint32 &value);
void SetFirstPointId(quint32 value);
quint32 GetSecondPointId() const;
void SetSecondPointId(const quint32 &value);
void SetSecondPointId(quint32 value);
QString GetLineColor() const;
void SetLineColor(const QString &value);
@ -75,7 +76,6 @@ public:
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
void EvalAngle();
void AngleTextChanged();
void DeployAngleTextEdit();
virtual void PointNameChanged() override;
void FXAngle();
@ -86,6 +86,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogLineIntersectAxis)
Ui::DialogLineIntersectAxis *ui;
@ -93,7 +94,21 @@ private:
QString formulaAngle;
int formulaBaseHeightAngle;
QString pointName;
bool m_firstRelease;
QTimer *timerFormula;
bool flagFormula;
bool flagError;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogLineIntersectAxis::IsValid() const
{
return flagFormula && flagName;
}
#endif // DIALOGLINEINTERSECTAXIS_H

View File

@ -67,12 +67,9 @@
DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogMove),
flagAngle(false),
flagRotationAngle(false),
flagLength(false),
timerAngle(nullptr),
timerRotationAngle(nullptr),
timerLength(nullptr),
timerAngle(new QTimer(this)),
timerRotationAngle(new QTimer(this)),
timerLength(new QTimer(this)),
formulaAngle(),
formulaRotationAngle(),
formulaLength(),
@ -83,7 +80,11 @@ DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent)
stage1(true),
stage2(false),
m_suffix(),
optionalRotationOrigin(false)
optionalRotationOrigin(false),
flagAngle(false),
flagRotationAngle(false),
flagLength(false),
flagName(false)
{
ui->setupUi(this);
@ -98,13 +99,13 @@ DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent)
ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix());
timerAngle = new QTimer(this);
timerAngle->setSingleShot(true);
connect(timerAngle, &QTimer::timeout, this, &DialogMove::EvalAngle);
timerRotationAngle = new QTimer(this);
timerRotationAngle->setSingleShot(true);
connect(timerRotationAngle, &QTimer::timeout, this, &DialogMove::EvalRotationAngle);
timerLength = new QTimer(this);
timerLength->setSingleShot(true);
connect(timerLength, &QTimer::timeout, this, &DialogMove::EvalLength);
InitOkCancelApply(ui);
@ -115,16 +116,25 @@ DialogMove::DialogMove(const VContainer *data, quint32 toolId, QWidget *parent)
ui->comboBoxRotationOriginPoint->addItem(tr("Center point"), NULL_ID);
ui->comboBoxRotationOriginPoint->blockSignals(false);
flagName = true;
CheckState();
connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogMove::SuffixChanged);
connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogMove::FXAngle);
connect(ui->toolButtonExprRotationAngle, &QPushButton::clicked, this, &DialogMove::FXRotationAngle);
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogMove::FXLength);
connect(ui->plainTextEditAngle, &QPlainTextEdit::textChanged, this, &DialogMove::AngleChanged);
connect(ui->plainTextEditRotationAngle, &QPlainTextEdit::textChanged, this, &DialogMove::RotationAngleChanged);
connect(ui->plainTextEditLength, &QPlainTextEdit::textChanged, this, &DialogMove::LengthChanged);
connect(ui->plainTextEditAngle, &QPlainTextEdit::textChanged, this, [this]()
{
timerAngle->start(formulaTimerTimeout);
});
connect(ui->plainTextEditRotationAngle, &QPlainTextEdit::textChanged, this, [this]()
{
timerRotationAngle->start(formulaTimerTimeout);
});
connect(ui->plainTextEditLength, &QPlainTextEdit::textChanged, this, [this]()
{
timerLength->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowAngle, &QPushButton::clicked, this, &DialogMove::DeployAngleTextEdit);
connect(ui->pushButtonGrowRotationAngle, &QPushButton::clicked, this, &DialogMove::DeployRotationAngleTextEdit);
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogMove::DeployLengthTextEdit);
@ -373,43 +383,19 @@ void DialogMove::SelectedObject(bool selected, quint32 object, quint32 tool)
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::DeployAngleTextEdit()
{
DeployFormula(ui->plainTextEditAngle, ui->pushButtonGrowAngle, formulaBaseHeightAngle);
DeployFormula(this, ui->plainTextEditAngle, ui->pushButtonGrowAngle, formulaBaseHeightAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::DeployRotationAngleTextEdit()
{
DeployFormula(ui->plainTextEditRotationAngle, ui->pushButtonGrowRotationAngle, formulaBaseHeightRotationAngle);
DeployFormula(this, ui->plainTextEditRotationAngle, ui->pushButtonGrowRotationAngle, formulaBaseHeightRotationAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::DeployLengthTextEdit()
{
DeployFormula(ui->plainTextEditLength, ui->pushButtonGrowLength, formulaBaseHeightLength);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::AngleChanged()
{
labelEditFormula = ui->labelEditAngle;
labelResultCalculation = ui->labelResultAngle;
ValFormulaChanged(flagAngle, ui->plainTextEditAngle, timerAngle, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::RotationAngleChanged()
{
labelEditFormula = ui->labelEditRotationAngle;
labelResultCalculation = ui->labelResultRotationAngle;
ValFormulaChanged(flagRotationAngle, ui->plainTextEditRotationAngle, timerRotationAngle, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::LengthChanged()
{
labelEditFormula = ui->labelEditLength;
labelResultCalculation = ui->labelResultLength;
ValFormulaChanged(flagLength, ui->plainTextEditLength, timerLength, degreeSymbol);
DeployFormula(this, ui->plainTextEditLength, ui->pushButtonGrowLength, formulaBaseHeightLength);
}
//---------------------------------------------------------------------------------------------------------------------
@ -464,7 +450,7 @@ void DialogMove::SuffixChanged()
if (suffix.isEmpty())
{
flagName = false;
ChangeColor(ui->labelSuffix, Qt::red);
ChangeColor(ui->labelSuffix, errorColor);
CheckState();
return;
}
@ -480,7 +466,7 @@ void DialogMove::SuffixChanged()
if (not rx.match(name).hasMatch() || not data->IsUnique(name))
{
flagName = false;
ChangeColor(ui->labelSuffix, Qt::red);
ChangeColor(ui->labelSuffix, errorColor);
CheckState();
return;
}
@ -489,20 +475,11 @@ void DialogMove::SuffixChanged()
}
flagName = true;
ChangeColor(ui->labelSuffix, okColor);
ChangeColor(ui->labelSuffix, OkColor(this));
}
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagAngle && flagRotationAngle && flagLength && flagName);
SCASSERT(bApply != nullptr)
bApply->setEnabled(bOk->isEnabled());
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::ShowVisualization()
{
@ -540,22 +517,40 @@ void DialogMove::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::EvalAngle()
{
labelEditFormula = ui->labelEditAngle;
Eval(ui->plainTextEditAngle->toPlainText(), flagAngle, ui->labelResultAngle, degreeSymbol, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditAngle->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditAngle;
formulaData.labelResult = ui->labelResultAngle;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, flagAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::EvalRotationAngle()
{
labelEditFormula = ui->labelEditRotationAngle;
Eval(ui->plainTextEditRotationAngle->toPlainText(), flagRotationAngle, ui->labelResultRotationAngle, degreeSymbol,
false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditRotationAngle->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditRotationAngle;
formulaData.labelResult = ui->labelResultRotationAngle;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, flagRotationAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogMove::EvalLength()
{
labelEditFormula = ui->labelEditLength;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
Eval(ui->plainTextEditLength->toPlainText(), flagLength, ui->labelResultLength, postfix);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditLength->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditLength;
formulaData.labelResult = ui->labelResultLength;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
Eval(formulaData, flagLength);
}

View File

@ -82,10 +82,6 @@ private slots:
void DeployRotationAngleTextEdit();
void DeployLengthTextEdit();
void AngleChanged();
void RotationAngleChanged();
void LengthChanged();
void FXAngle();
void FXRotationAngle();
void FXLength();
@ -93,22 +89,17 @@ private slots:
void SuffixChanged();
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
/** @brief SaveData Put dialog data in local variables */
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogMove)
Ui::DialogMove *ui;
/** @brief flagAngle true if value of angle is correct */
bool flagAngle;
bool flagRotationAngle;
bool flagLength;
/** @brief timerAngle timer of check formula of angle */
QTimer *timerAngle;
QTimer *timerRotationAngle;
@ -133,9 +124,21 @@ private:
bool optionalRotationOrigin;
/** @brief flagAngle true if value of angle is correct */
bool flagAngle;
bool flagRotationAngle;
bool flagLength;
bool flagName;
void EvalAngle();
void EvalRotationAngle();
void EvalLength();
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogMove::IsValid() const
{
return flagAngle && flagRotationAngle && flagLength && flagName;
}
#endif // DIALOGMOVING_H

View File

@ -37,6 +37,7 @@
#include <QPlainTextEdit>
#include <QPointer>
#include <QPushButton>
#include <QTimer>
#include <QToolButton>
#include "../vpatterndb/vtranslatevars.h"
@ -56,33 +57,56 @@
* @param data container with data
* @param parent parent widget
*/
DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), formula(QString()), angle(0), formulaBaseHeight(0)
DialogNormal::DialogNormal(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogNormal),
formula(),
angle(0),
formulaBaseHeight(0),
pointName(),
timerFormula(new QTimer(this)),
flagFormula(false),
flagName(true),
flagError(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogNormal::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxTypeLine(ui->comboBoxLineType, LineStylesPics());
FillComboBoxLineColors(ui->comboBoxLineColor);
InitArrow(ui);
connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, [this](){ui->doubleSpinBoxAngle->setValue(270);});
connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, [this](){ui->doubleSpinBoxAngle->setValue(90);});
connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this, [this](){ui->doubleSpinBoxAngle->setValue(180);});
connect(ui->toolButtonArrowRight, &QPushButton::clicked, this, [this](){ui->doubleSpinBoxAngle->setValue(0);});
connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this, [this](){ui->doubleSpinBoxAngle->setValue(135);});
connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this, [this](){ui->doubleSpinBoxAngle->setValue(225);});
connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this, [this](){ui->doubleSpinBoxAngle->setValue(45);});
connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this,
[this](){ui->doubleSpinBoxAngle->setValue(315);});
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogNormal::FXLength);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogNormal::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogNormal::FormulaTextChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogNormal::DeployFormulaTextEdit);
connect(ui->comboBoxFirstPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogNormal::PointNameChanged);
@ -92,16 +116,10 @@ DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidge
vis = new VisToolNormal(data);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::FormulaTextChanged()
{
this->FormulaChangedPlainText();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::PointNameChanged()
{
QColor color = okColor;
QColor color;
if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint))
{
flagError = false;
@ -110,7 +128,7 @@ void DialogNormal::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelFirstPoint, color);
ChangeColor(ui->labelSecondPoint, color);
@ -131,6 +149,19 @@ void DialogNormal::FXLength()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::EvalFormula()
{
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::ShowVisualization()
{
@ -140,7 +171,7 @@ void DialogNormal::ShowVisualization()
//---------------------------------------------------------------------------------------------------------------------
void DialogNormal::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -149,6 +180,12 @@ DialogNormal::~DialogNormal()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogNormal::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.
@ -223,7 +260,7 @@ void DialogNormal::closeEvent(QCloseEvent *event)
* @brief SetSecondPointId set id of second point
* @param value id
*/
void DialogNormal::SetSecondPointId(const quint32 &value)
void DialogNormal::SetSecondPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxSecondPoint, value);
@ -249,7 +286,7 @@ void DialogNormal::SetLineColor(const QString &value)
* @brief SetFirstPointId set id of first point
* @param value id
*/
void DialogNormal::SetFirstPointId(const quint32 &value)
void DialogNormal::SetFirstPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxFirstPoint, value);
@ -263,7 +300,7 @@ void DialogNormal::SetFirstPointId(const quint32 &value)
* @brief SetAngle set aditional angle of normal
* @param value angle in degree
*/
void DialogNormal::SetAngle(const qreal &value)
void DialogNormal::SetAngle(qreal value)
{
angle = value;
ui->doubleSpinBoxAngle->setValue(angle);

View File

@ -50,9 +50,10 @@ class DialogNormal : public DialogTool
{
Q_OBJECT
public:
DialogNormal(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogNormal(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogNormal() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetTypeLine() const;
@ -62,13 +63,13 @@ public:
void SetFormula(const QString &value);
qreal GetAngle() const;
void SetAngle(const qreal &value);
void SetAngle(qreal value);
quint32 GetFirstPointId() const;
void SetFirstPointId(const quint32 &value);
void SetFirstPointId(quint32 value);
quint32 GetSecondPointId() const;
void SetSecondPointId(const quint32 &value);
void SetSecondPointId(quint32 value);
QString GetLineColor() const;
void SetLineColor(const QString &value);
@ -78,12 +79,9 @@ public slots:
* @brief DeployFormulaTextEdit grow or shrink formula input
*/
void DeployFormulaTextEdit();
/**
* @brief FormulaTextChanged when formula text changes for validation and calc
*/
void FormulaTextChanged();
virtual void PointNameChanged() override;
void FXLength();
void EvalFormula();
protected:
virtual void ShowVisualization() override;
/**
@ -91,6 +89,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogNormal)
@ -98,13 +97,27 @@ private:
Ui::DialogNormal *ui;
/** @brief formula formula */
QString formula;
QString formula;
/** @brief angle aditional angle of normal */
qreal angle;
qreal angle;
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
int formulaBaseHeight;
QString pointName;
QTimer *timerFormula;
bool flagFormula;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogNormal::IsValid() const
{
return flagFormula && flagName && flagError;
}
#endif // DIALOGNORMAL_H

View File

@ -39,25 +39,29 @@
#include "ui_dialogpointfromarcandtangent.h"
//---------------------------------------------------------------------------------------------------------------------
DialogPointFromArcAndTangent::DialogPointFromArcAndTangent(const VContainer *data, const quint32 &toolId,
QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointFromArcAndTangent)
DialogPointFromArcAndTangent::DialogPointFromArcAndTangent(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPointFromArcAndTangent),
pointName(),
flagName(true)
{
ui->setupUi(this);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui);
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxTangentPoint);
FillComboBoxArcs(ui->comboBoxArc);
FillComboBoxCrossCirclesPoints(ui->comboBoxResult);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointFromArcAndTangent::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
vis = new VisToolPointFromArcAndTangent(data);
}
@ -68,6 +72,12 @@ DialogPointFromArcAndTangent::~DialogPointFromArcAndTangent()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogPointFromArcAndTangent::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromArcAndTangent::SetPointName(const QString &value)
{
@ -82,7 +92,7 @@ quint32 DialogPointFromArcAndTangent::GetArcId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromArcAndTangent::SetArcId(const quint32 &value)
void DialogPointFromArcAndTangent::SetArcId(quint32 value)
{
setCurrentArcId(ui->comboBoxArc, value);
@ -98,7 +108,7 @@ quint32 DialogPointFromArcAndTangent::GetTangentPointId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromArcAndTangent::SetTangentPointId(const quint32 &value)
void DialogPointFromArcAndTangent::SetTangentPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxTangentPoint, value);
@ -114,7 +124,7 @@ CrossCirclesPoint DialogPointFromArcAndTangent::GetCrossCirclesPoint() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromArcAndTangent::SetCrossCirclesPoint(const CrossCirclesPoint &p)
void DialogPointFromArcAndTangent::SetCrossCirclesPoint(CrossCirclesPoint p)
{
const qint32 index = ui->comboBoxResult->findData(static_cast<int>(p));
if (index != -1)

View File

@ -49,20 +49,20 @@ class DialogPointFromArcAndTangent : public DialogTool
Q_OBJECT
public:
DialogPointFromArcAndTangent(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogPointFromArcAndTangent(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
~DialogPointFromArcAndTangent();
QString GetPointName() const;
void SetPointName(const QString &value);
quint32 GetArcId() const;
void SetArcId(const quint32 &value);
void SetArcId(quint32 value);
quint32 GetTangentPointId() const;
void SetTangentPointId(const quint32 &value);
void SetTangentPointId(quint32 value);
CrossCirclesPoint GetCrossCirclesPoint() const;
void SetCrossCirclesPoint(const CrossCirclesPoint &p);
void SetCrossCirclesPoint(CrossCirclesPoint p);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
@ -73,11 +73,22 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogPointFromArcAndTangent)
Ui::DialogPointFromArcAndTangent *ui;
QString pointName;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPointFromArcAndTangent::IsValid() const
{
return flagName;
}
#endif // DIALOGPOINTFROMARCANDTANGENT_H

View File

@ -42,6 +42,7 @@
#include <Qt>
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../../visualization/visualization.h"
#include "../../visualization/line/vistoolpointfromcircleandtangent.h"
#include "../ifc/xml/vdomdocument.h"
@ -51,19 +52,24 @@
#include "ui_dialogpointfromcircleandtangent.h"
//---------------------------------------------------------------------------------------------------------------------
DialogPointFromCircleAndTangent::DialogPointFromCircleAndTangent(const VContainer *data, const quint32 &toolId,
DialogPointFromCircleAndTangent::DialogPointFromCircleAndTangent(const VContainer *data, quint32 toolId,
QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointFromCircleAndTangent), flagCircleRadius(false),
timerCircleRadius(nullptr), circleRadius(), formulaBaseHeightCircleRadius(0)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPointFromCircleAndTangent),
timerCircleRadius(nullptr),
circleRadius(),
formulaBaseHeightCircleRadius(0),
pointName(),
flagCircleRadius(false),
flagName(true),
flagError(true)
{
ui->setupUi(this);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
plainTextEditFormula = ui->plainTextEditRadius;
this->formulaBaseHeightCircleRadius = ui->plainTextEditRadius->height();
ui->plainTextEditRadius->installEventFilter(this);
@ -72,21 +78,26 @@ DialogPointFromCircleAndTangent::DialogPointFromCircleAndTangent(const VContaine
connect(timerCircleRadius, &QTimer::timeout, this, &DialogPointFromCircleAndTangent::EvalCircleRadius);
InitOkCancelApply(ui);
CheckState();
FillComboBoxPoints(ui->comboBoxCircleCenter);
FillComboBoxPoints(ui->comboBoxTangentPoint);
FillComboBoxCrossCirclesPoints(ui->comboBoxResult);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointFromCircleAndTangent::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->comboBoxCircleCenter, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogPointFromCircleAndTangent::PointChanged);
connect(ui->toolButtonExprRadius, &QPushButton::clicked, this,
&DialogPointFromCircleAndTangent::FXCircleRadius);
connect(ui->plainTextEditRadius, &QPlainTextEdit::textChanged, this,
&DialogPointFromCircleAndTangent::CircleRadiusChanged);
connect(ui->plainTextEditRadius, &QPlainTextEdit::textChanged, this, [this]()
{
timerCircleRadius->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowRadius, &QPushButton::clicked, this,
&DialogPointFromCircleAndTangent::DeployCircleRadiusTextEdit);
@ -100,6 +111,12 @@ DialogPointFromCircleAndTangent::~DialogPointFromCircleAndTangent()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogPointFromCircleAndTangent::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromCircleAndTangent::SetPointName(const QString &value)
{
@ -227,7 +244,7 @@ void DialogPointFromCircleAndTangent::ChosenObject(quint32 id, const SceneObject
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromCircleAndTangent::PointChanged()
{
QColor color = okColor;
QColor color;
if (getCurrentObjectId(ui->comboBoxCircleCenter) == getCurrentObjectId(ui->comboBoxTangentPoint))
{
flagError = false;
@ -236,7 +253,7 @@ void DialogPointFromCircleAndTangent::PointChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelCircleCenter, color);
ChangeColor(ui->labelTangentPoint, color);
@ -246,16 +263,7 @@ void DialogPointFromCircleAndTangent::PointChanged()
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromCircleAndTangent::DeployCircleRadiusTextEdit()
{
DeployFormula(ui->plainTextEditRadius, ui->pushButtonGrowRadius, formulaBaseHeightCircleRadius);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromCircleAndTangent::CircleRadiusChanged()
{
labelEditFormula = ui->labelEditRadius;
labelResultCalculation = ui->labelResultCircleRadius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagCircleRadius, ui->plainTextEditRadius, timerCircleRadius, postfix);
DeployFormula(this, ui->plainTextEditRadius, ui->pushButtonGrowRadius, formulaBaseHeightCircleRadius);
}
//---------------------------------------------------------------------------------------------------------------------
@ -275,15 +283,19 @@ void DialogPointFromCircleAndTangent::FXCircleRadius()
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromCircleAndTangent::EvalCircleRadius()
{
labelEditFormula = ui->labelEditRadius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius = Eval(ui->plainTextEditRadius->toPlainText(), flagCircleRadius,
ui->labelResultCircleRadius, postfix);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditRadius->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditRadius;
formulaData.labelResult = ui->labelResultCircleRadius;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius = Eval(formulaData, flagCircleRadius);
if (radius < 0)
{
flagCircleRadius = false;
ChangeColor(labelEditFormula, Qt::red);
ChangeColor(ui->labelEditRadius, errorColor);
ui->labelResultCircleRadius->setText(tr("Error"));
ui->labelResultCircleRadius->setToolTip(tr("Radius can't be negative"));
@ -318,15 +330,3 @@ void DialogPointFromCircleAndTangent::closeEvent(QCloseEvent *event)
ui->plainTextEditRadius->blockSignals(true);
DialogTool::closeEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointFromCircleAndTangent::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagFormula && flagName && flagError && flagCircleRadius);
// In case dialog hasn't apply button
if ( bApply != nullptr)
{
bApply->setEnabled(bOk->isEnabled());
}
}

View File

@ -49,9 +49,10 @@ class DialogPointFromCircleAndTangent : public DialogTool
Q_OBJECT
public:
DialogPointFromCircleAndTangent(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogPointFromCircleAndTangent(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
~DialogPointFromCircleAndTangent();
QString GetPointName() const;
void SetPointName(const QString &value);
quint32 GetCircleCenterId() const;
@ -71,7 +72,6 @@ public slots:
void PointChanged();
void DeployCircleRadiusTextEdit();
void CircleRadiusChanged();
void FXCircleRadius();
void EvalCircleRadius();
@ -82,17 +82,26 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual void CheckState() final;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogPointFromCircleAndTangent)
Ui::DialogPointFromCircleAndTangent *ui;
bool flagCircleRadius;
QTimer *timerCircleRadius;
QString circleRadius;
int formulaBaseHeightCircleRadius;
QTimer* timerCircleRadius;
QString circleRadius;
int formulaBaseHeightCircleRadius;
QString pointName;
bool flagCircleRadius;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPointFromCircleAndTangent::IsValid() const
{
return flagCircleRadius && flagName && flagError;
}
#endif // DIALOGPOINTFROMCIRCLEANDTANGENT_H

View File

@ -37,9 +37,11 @@
#include <QPointer>
#include <QPushButton>
#include <QSet>
#include <QTimer>
#include <QToolButton>
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../../visualization/visualization.h"
#include "../../visualization/line/vistoolpointofcontact.h"
#include "../ifc/xml/vabstractpattern.h"
@ -55,30 +57,44 @@
* @param data container with data
* @param parent parent widget
*/
DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), radius(QString()), formulaBaseHeight(0)
DialogPointOfContact::DialogPointOfContact(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPointOfContact),
radius(),
formulaBaseHeight(0),
pointName(),
timerFormula(new QTimer(this)),
flagFormula(false),
flagName(true),
flagError(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogPointOfContact::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
FillComboBoxPoints(ui->comboBoxCenter);
connect(ui->toolButtonExprRadius, &QPushButton::clicked, this, &DialogPointOfContact::FXRadius);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfContact::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogPointOfContact::FormulaTextChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogPointOfContact::DeployFormulaTextEdit);
connect(ui->comboBoxFirstPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogPointOfContact::PointNameChanged);
@ -97,9 +113,9 @@ DialogPointOfContact::~DialogPointOfContact()
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::FormulaTextChanged()
QString DialogPointOfContact::GetPointName() const
{
this->FormulaChangedPlainText();
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
@ -110,7 +126,7 @@ void DialogPointOfContact::PointNameChanged()
set.insert(getCurrentObjectId(ui->comboBoxSecondPoint));
set.insert(getCurrentObjectId(ui->comboBoxCenter));
QColor color = okColor;
QColor color;
if (set.size() != 3)
{
flagError = false;
@ -119,7 +135,7 @@ void DialogPointOfContact::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelFirstPoint, color);
ChangeColor(ui->labelSecondPoint, color);
@ -141,6 +157,19 @@ void DialogPointOfContact::FXRadius()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::EvalFormula()
{
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::ShowVisualization()
{
@ -150,7 +179,7 @@ void DialogPointOfContact::ShowVisualization()
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfContact::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -243,7 +272,7 @@ void DialogPointOfContact::closeEvent(QCloseEvent *event)
* @brief SetSecondPoint set id second point
* @param value id
*/
void DialogPointOfContact::SetSecondPoint(const quint32 &value)
void DialogPointOfContact::SetSecondPoint(quint32 value)
{
setCurrentPointId(ui->comboBoxSecondPoint, value);
@ -257,7 +286,7 @@ void DialogPointOfContact::SetSecondPoint(const quint32 &value)
* @brief SetFirstPoint set id first point
* @param value id
*/
void DialogPointOfContact::SetFirstPoint(const quint32 &value)
void DialogPointOfContact::SetFirstPoint(quint32 value)
{
setCurrentPointId(ui->comboBoxFirstPoint, value);
@ -271,7 +300,7 @@ void DialogPointOfContact::SetFirstPoint(const quint32 &value)
* @brief SetCenter set id of center point
* @param value id
*/
void DialogPointOfContact::setCenter(const quint32 &value)
void DialogPointOfContact::setCenter(quint32 value)
{
setCurrentPointId(ui->comboBoxCenter, value);

View File

@ -51,34 +51,32 @@ class DialogPointOfContact : public DialogTool
{
Q_OBJECT
public:
DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogPointOfContact(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogPointOfContact() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString getRadius() const;
void setRadius(const QString &value);
quint32 getCenter() const;
void setCenter(const quint32 &value);
void setCenter(quint32 value);
quint32 GetFirstPoint() const;
void SetFirstPoint(const quint32 &value);
void SetFirstPoint(quint32 value);
quint32 GetSecondPoint() const;
void SetSecondPoint(const quint32 &value);
void SetSecondPoint(quint32 value);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
/**
* @brief DeployFormulaTextEdit grow or shrink formula input
*/
void DeployFormulaTextEdit();
/**
* @brief FormulaTextChanged when formula text changes for validation and calc
*/
void FormulaTextChanged();
virtual void PointNameChanged() override;
void FXRadius();
void EvalFormula();
protected:
virtual void ShowVisualization() override;
/**
@ -86,6 +84,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogPointOfContact)
@ -93,10 +92,24 @@ private:
Ui::DialogPointOfContact *ui;
/** @brief radius radius of arc */
QString radius;
QString radius;
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
int formulaBaseHeight;
QString pointName;
QTimer *timerFormula;
bool flagFormula;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPointOfContact::IsValid() const
{
return flagFormula && flagName && flagError;
}
#endif // DIALOGPOINTOFCONTACT_H

View File

@ -48,23 +48,29 @@
* @param data container with data
* @param parent parent widget
*/
DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection)
DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPointOfIntersection),
pointName(),
flagName(true),
flagError(true)
{
ui->setupUi(this);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui);
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfIntersection::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->comboBoxFirstPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogPointOfIntersection::PointNameChanged);
connect(ui->comboBoxSecondPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -80,12 +86,18 @@ DialogPointOfIntersection::~DialogPointOfIntersection()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogPointOfIntersection::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetSecondPointId set id of second point
* @param value id
*/
void DialogPointOfIntersection::SetSecondPointId(const quint32 &value)
void DialogPointOfIntersection::SetSecondPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxSecondPoint, value);
@ -154,7 +166,7 @@ void DialogPointOfIntersection::SaveData()
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersection::PointNameChanged()
{
QColor color = okColor;
QColor color;
if (getCurrentObjectId(ui->comboBoxFirstPoint) == getCurrentObjectId(ui->comboBoxSecondPoint))
{
flagError = false;
@ -163,7 +175,7 @@ void DialogPointOfIntersection::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelFirstPoint, color);
ChangeColor(ui->labelSecondPoint, color);
@ -181,7 +193,7 @@ void DialogPointOfIntersection::ShowVisualization()
* @brief SetFirstPointId set id of first point
* @param value id
*/
void DialogPointOfIntersection::SetFirstPointId(const quint32 &value)
void DialogPointOfIntersection::SetFirstPointId(quint32 value)
{
setCurrentPointId(ui->comboBoxFirstPoint, value);

View File

@ -50,16 +50,17 @@ class DialogPointOfIntersection : public DialogTool
{
Q_OBJECT
public:
DialogPointOfIntersection(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogPointOfIntersection(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogPointOfIntersection() override;
QString GetPointName() const;
void SetPointName(const QString &value);
quint32 GetFirstPointId() const;
void SetFirstPointId(const quint32 &value);
void SetFirstPointId(quint32 value);
quint32 GetSecondPointId() const;
void SetSecondPointId(const quint32 &value);
void SetSecondPointId(quint32 value);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
virtual void PointNameChanged() override;
@ -69,11 +70,23 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogPointOfIntersection)
/** @brief ui keeps information about user interface */
Ui::DialogPointOfIntersection *ui;
QString pointName;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPointOfIntersection::IsValid() const
{
return flagName && flagError;
}
#endif // DIALOGPOINTOFINTERSECTION_H

View File

@ -41,25 +41,30 @@
#include "ui_dialogpointofintersectionarcs.h"
//---------------------------------------------------------------------------------------------------------------------
DialogPointOfIntersectionArcs::DialogPointOfIntersectionArcs(const VContainer *data, const quint32 &toolId,
QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersectionArcs)
DialogPointOfIntersectionArcs::DialogPointOfIntersectionArcs(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPointOfIntersectionArcs),
pointName(),
flagName(true),
flagError(true)
{
ui->setupUi(this);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui);
DialogTool::CheckState();
FillComboBoxArcs(ui->comboBoxArc1);
FillComboBoxArcs(ui->comboBoxArc2);
FillComboBoxCrossCirclesPoints(ui->comboBoxResult);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfIntersectionArcs::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->comboBoxArc1, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogPointOfIntersectionArcs::ArcChanged);
connect(ui->comboBoxArc1, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -74,6 +79,12 @@ DialogPointOfIntersectionArcs::~DialogPointOfIntersectionArcs()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogPointOfIntersectionArcs::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionArcs::SetPointName(const QString &value)
{
@ -88,7 +99,7 @@ quint32 DialogPointOfIntersectionArcs::GetFirstArcId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionArcs::SetFirstArcId(const quint32 &value)
void DialogPointOfIntersectionArcs::SetFirstArcId(quint32 value)
{
setCurrentArcId(ui->comboBoxArc1, value);
@ -104,7 +115,7 @@ quint32 DialogPointOfIntersectionArcs::GetSecondArcId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionArcs::SetSecondArcId(const quint32 &value)
void DialogPointOfIntersectionArcs::SetSecondArcId(quint32 value)
{
setCurrentArcId(ui->comboBoxArc2, value);
@ -120,7 +131,7 @@ CrossCirclesPoint DialogPointOfIntersectionArcs::GetCrossArcPoint() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionArcs::SetCrossArcPoint(const CrossCirclesPoint &p)
void DialogPointOfIntersectionArcs::SetCrossArcPoint(CrossCirclesPoint p)
{
const qint32 index = ui->comboBoxResult->findData(static_cast<int>(p));
if (index != -1)
@ -175,7 +186,7 @@ void DialogPointOfIntersectionArcs::ChosenObject(quint32 id, const SceneObject &
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionArcs::ArcChanged()
{
QColor color = okColor;
QColor color;
if (getCurrentObjectId(ui->comboBoxArc1) == getCurrentObjectId(ui->comboBoxArc2))
{
flagError = false;
@ -184,7 +195,7 @@ void DialogPointOfIntersectionArcs::ArcChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelArc1, color);
ChangeColor(ui->labelArc2, color);

View File

@ -49,19 +49,20 @@ class DialogPointOfIntersectionArcs : public DialogTool
Q_OBJECT
public:
DialogPointOfIntersectionArcs(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogPointOfIntersectionArcs(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogPointOfIntersectionArcs() override;
QString GetPointName() const;
void SetPointName(const QString &value);
quint32 GetFirstArcId() const;
void SetFirstArcId(const quint32 &value);
void SetFirstArcId(quint32 value);
quint32 GetSecondArcId() const;
void SetSecondArcId(const quint32 &value);
void SetSecondArcId(quint32 value);
CrossCirclesPoint GetCrossArcPoint() const;
void SetCrossArcPoint(const CrossCirclesPoint &p);
void SetCrossArcPoint(CrossCirclesPoint p);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
@ -73,11 +74,23 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogPointOfIntersectionArcs)
Ui::DialogPointOfIntersectionArcs *ui;
QString pointName;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPointOfIntersectionArcs::IsValid() const
{
return flagName && flagError;
}
#endif // DIALOGPOINTOFINTERSECTIONARCS_H

View File

@ -42,6 +42,7 @@
#include <Qt>
#include "../vpatterndb/vtranslatevars.h"
#include "../vpatterndb/vcontainer.h"
#include "../../visualization/visualization.h"
#include "../../visualization/line/vistoolpointofintersectioncircles.h"
#include "../ifc/xml/vdomdocument.h"
@ -51,40 +52,51 @@
#include "ui_dialogpointofintersectioncircles.h"
//---------------------------------------------------------------------------------------------------------------------
DialogPointOfIntersectionCircles::DialogPointOfIntersectionCircles(const VContainer *data, const quint32 &toolId,
DialogPointOfIntersectionCircles::DialogPointOfIntersectionCircles(const VContainer *data, quint32 toolId,
QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersectionCircles), flagCircle1Radius(false),
flagCircle2Radius(false), timerCircle1Radius(nullptr), timerCircle2Radius(nullptr), circle1Radius(),
circle2Radius(), formulaBaseHeightCircle1Radius(0), formulaBaseHeightCircle2Radius(0)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPointOfIntersectionCircles),
timerCircle1Radius(new QTimer(this)),
timerCircle2Radius(new QTimer(this)),
circle1Radius(),
circle2Radius(),
formulaBaseHeightCircle1Radius(0),
formulaBaseHeightCircle2Radius(0),
pointName(),
flagCircle1Radius(false),
flagCircle2Radius(false),
flagName(true),
flagError(true)
{
ui->setupUi(this);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
plainTextEditFormula = ui->plainTextEditCircle1Radius;
this->formulaBaseHeightCircle1Radius = ui->plainTextEditCircle1Radius->height();
this->formulaBaseHeightCircle2Radius = ui->plainTextEditCircle2Radius->height();
ui->plainTextEditCircle1Radius->installEventFilter(this);
ui->plainTextEditCircle2Radius->installEventFilter(this);
timerCircle1Radius = new QTimer(this);
timerCircle1Radius->setSingleShot(true);
connect(timerCircle1Radius, &QTimer::timeout, this, &DialogPointOfIntersectionCircles::EvalCircle1Radius);
timerCircle2Radius = new QTimer(this);
timerCircle2Radius->setSingleShot(true);
connect(timerCircle2Radius, &QTimer::timeout, this, &DialogPointOfIntersectionCircles::EvalCircle2Radius);
InitOkCancelApply(ui);
CheckState();
FillComboBoxPoints(ui->comboBoxCircle1Center);
FillComboBoxPoints(ui->comboBoxCircle2Center);
FillComboBoxCrossCirclesPoints(ui->comboBoxResult);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfIntersectionCircles::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->comboBoxCircle1Center, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogPointOfIntersectionCircles::PointChanged);
connect(ui->comboBoxCircle2Center, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -95,10 +107,15 @@ DialogPointOfIntersectionCircles::DialogPointOfIntersectionCircles(const VContai
connect(ui->toolButtonExprCircle2Radius, &QPushButton::clicked, this,
&DialogPointOfIntersectionCircles::FXCircle2Radius);
connect(ui->plainTextEditCircle1Radius, &QPlainTextEdit::textChanged, this,
&DialogPointOfIntersectionCircles::Circle1RadiusChanged);
connect(ui->plainTextEditCircle2Radius, &QPlainTextEdit::textChanged, this,
&DialogPointOfIntersectionCircles::Circle2RadiusChanged);
connect(ui->plainTextEditCircle1Radius, &QPlainTextEdit::textChanged, this, [this]()
{
timerCircle1Radius->start(formulaTimerTimeout);
});
connect(ui->plainTextEditCircle2Radius, &QPlainTextEdit::textChanged, this, [this]()
{
timerCircle2Radius->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowCircle1Radius, &QPushButton::clicked, this,
&DialogPointOfIntersectionCircles::DeployCircle1RadiusTextEdit);
@ -114,6 +131,12 @@ DialogPointOfIntersectionCircles::~DialogPointOfIntersectionCircles()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogPointOfIntersectionCircles::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCircles::SetPointName(const QString &value)
{
@ -266,7 +289,7 @@ void DialogPointOfIntersectionCircles::ChosenObject(quint32 id, const SceneObjec
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCircles::PointChanged()
{
QColor color = okColor;
QColor color;
if (getCurrentObjectId(ui->comboBoxCircle1Center) == getCurrentObjectId(ui->comboBoxCircle2Center))
{
flagError = false;
@ -275,7 +298,7 @@ void DialogPointOfIntersectionCircles::PointChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelCircle1Center, color);
ChangeColor(ui->labelCircle1Center, color);
@ -285,31 +308,13 @@ void DialogPointOfIntersectionCircles::PointChanged()
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCircles::DeployCircle1RadiusTextEdit()
{
DeployFormula(ui->plainTextEditCircle1Radius, ui->pushButtonGrowCircle1Radius, formulaBaseHeightCircle1Radius);
DeployFormula(this, ui->plainTextEditCircle1Radius, ui->pushButtonGrowCircle1Radius, formulaBaseHeightCircle1Radius);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCircles::DeployCircle2RadiusTextEdit()
{
DeployFormula(ui->plainTextEditCircle2Radius, ui->pushButtonGrowCircle2Radius, formulaBaseHeightCircle2Radius);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCircles::Circle1RadiusChanged()
{
labelEditFormula = ui->labelEditCircle1Radius;
labelResultCalculation = ui->labelResultCircle1Radius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagCircle1Radius, ui->plainTextEditCircle1Radius, timerCircle1Radius, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCircles::Circle2RadiusChanged()
{
labelEditFormula = ui->labelEditCircle2Radius;
labelResultCalculation = ui->labelResultCircle2Radius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagCircle2Radius, ui->plainTextEditCircle2Radius, timerCircle2Radius, postfix);
DeployFormula(this, ui->plainTextEditCircle2Radius, ui->pushButtonGrowCircle2Radius, formulaBaseHeightCircle2Radius);
}
//---------------------------------------------------------------------------------------------------------------------
@ -343,15 +348,19 @@ void DialogPointOfIntersectionCircles::FXCircle2Radius()
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCircles::EvalCircle1Radius()
{
labelEditFormula = ui->labelEditCircle1Radius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius = Eval(ui->plainTextEditCircle1Radius->toPlainText(), flagCircle1Radius,
ui->labelResultCircle1Radius, postfix);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditCircle1Radius->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditCircle1Radius;
formulaData.labelResult = ui->labelResultCircle1Radius;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius = Eval(formulaData, flagCircle1Radius);
if (radius < 0)
{
flagCircle2Radius = false;
ChangeColor(labelEditFormula, Qt::red);
ChangeColor(ui->labelEditCircle1Radius, errorColor);
ui->labelResultCircle1Radius->setText(tr("Error"));
ui->labelResultCircle1Radius->setToolTip(tr("Radius can't be negative"));
@ -362,15 +371,19 @@ void DialogPointOfIntersectionCircles::EvalCircle1Radius()
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCircles::EvalCircle2Radius()
{
labelEditFormula = ui->labelEditCircle2Radius;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius = Eval(ui->plainTextEditCircle2Radius->toPlainText(), flagCircle2Radius,
ui->labelResultCircle2Radius, postfix);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditCircle2Radius->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditCircle2Radius;
formulaData.labelResult = ui->labelResultCircle1Radius;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal radius = Eval(formulaData, flagCircle2Radius);
if (radius < 0)
{
flagCircle2Radius = false;
ChangeColor(labelEditFormula, Qt::red);
ChangeColor(ui->labelEditCircle2Radius, errorColor);
ui->labelResultCircle2Radius->setText(tr("Error"));
ui->labelResultCircle2Radius->setToolTip(tr("Radius can't be negative"));
@ -407,15 +420,3 @@ void DialogPointOfIntersectionCircles::closeEvent(QCloseEvent *event)
ui->plainTextEditCircle2Radius->blockSignals(true);
DialogTool::closeEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCircles::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagFormula && flagName && flagError && flagCircle1Radius && flagCircle2Radius);
// In case dialog hasn't apply button
if ( bApply != nullptr)
{
bApply->setEnabled(bOk->isEnabled());
}
}

View File

@ -49,9 +49,10 @@ class DialogPointOfIntersectionCircles : public DialogTool
Q_OBJECT
public:
DialogPointOfIntersectionCircles(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogPointOfIntersectionCircles(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogPointOfIntersectionCircles() override;
QString GetPointName() const;
void SetPointName(const QString &value);
quint32 GetFirstCircleCenterId() const;
@ -76,9 +77,6 @@ public slots:
void DeployCircle1RadiusTextEdit();
void DeployCircle2RadiusTextEdit();
void Circle1RadiusChanged();
void Circle2RadiusChanged();
void FXCircle1Radius();
void FXCircle2Radius();
@ -92,24 +90,34 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual void CheckState() final;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogPointOfIntersectionCircles)
Ui::DialogPointOfIntersectionCircles *ui;
bool flagCircle1Radius;
bool flagCircle2Radius;
QTimer *timerCircle1Radius;
QTimer *timerCircle2Radius;
QTimer *timerCircle1Radius;
QTimer *timerCircle2Radius;
QString circle1Radius;
QString circle2Radius;
QString circle1Radius;
QString circle2Radius;
int formulaBaseHeightCircle1Radius;
int formulaBaseHeightCircle2Radius;
int formulaBaseHeightCircle1Radius;
int formulaBaseHeightCircle2Radius;
QString pointName;
bool flagCircle1Radius;
bool flagCircle2Radius;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPointOfIntersectionCircles::IsValid() const
{
return flagCircle1Radius && flagCircle2Radius && flagName && flagError;
}
#endif // DIALOGPOINTOFINTERSECTIONCIRCLES_H

View File

@ -42,27 +42,32 @@
#include "ui_dialogpointofintersectioncurves.h"
//---------------------------------------------------------------------------------------------------------------------
DialogPointOfIntersectionCurves::DialogPointOfIntersectionCurves(const VContainer *data, const quint32 &toolId,
DialogPointOfIntersectionCurves::DialogPointOfIntersectionCurves(const VContainer *data, quint32 toolId,
QWidget *parent)
:DialogTool(data, toolId, parent),
ui(new Ui::DialogPointOfIntersectionCurves)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPointOfIntersectionCurves),
pointName(),
flagName(false),
flagError(false)
{
ui->setupUi(this);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui);
CheckState();
FillComboBoxCurves(ui->comboBoxCurve1);
FillComboBoxCurves(ui->comboBoxCurve2);
FillComboBoxVCrossCurvesPoint(ui->comboBoxVCorrection);
FillComboBoxHCrossCurvesPoint(ui->comboBoxHCorrection);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogPointOfIntersectionCurves::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->comboBoxCurve1, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogPointOfIntersectionCurves::CurveChanged);
connect(ui->comboBoxCurve2, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -77,6 +82,12 @@ DialogPointOfIntersectionCurves::~DialogPointOfIntersectionCurves()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogPointOfIntersectionCurves::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCurves::SetPointName(const QString &value)
{
@ -91,7 +102,7 @@ quint32 DialogPointOfIntersectionCurves::GetFirstCurveId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCurves::SetFirstCurveId(const quint32 &value)
void DialogPointOfIntersectionCurves::SetFirstCurveId(quint32 value)
{
setCurrentCurveId(ui->comboBoxCurve1, value);
@ -107,7 +118,7 @@ quint32 DialogPointOfIntersectionCurves::GetSecondCurveId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCurves::SetSecondCurveId(const quint32 &value)
void DialogPointOfIntersectionCurves::SetSecondCurveId(quint32 value)
{
setCurrentCurveId(ui->comboBoxCurve2, value);
@ -123,7 +134,7 @@ VCrossCurvesPoint DialogPointOfIntersectionCurves::GetVCrossPoint() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCurves::SetVCrossPoint(const VCrossCurvesPoint &vP)
void DialogPointOfIntersectionCurves::SetVCrossPoint(VCrossCurvesPoint vP)
{
auto index = ui->comboBoxVCorrection->findData(static_cast<int>(vP));
if (index != -1)
@ -143,7 +154,7 @@ HCrossCurvesPoint DialogPointOfIntersectionCurves::GetHCrossPoint() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCurves::SetHCrossPoint(const HCrossCurvesPoint &hP)
void DialogPointOfIntersectionCurves::SetHCrossPoint(HCrossCurvesPoint hP)
{
auto index = ui->comboBoxHCorrection->findData(static_cast<int>(hP));
if (index != -1)
@ -219,22 +230,10 @@ void DialogPointOfIntersectionCurves::SaveData()
point->RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCurves::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagName && flagError);
// In case dialog hasn't apply button
if ( bApply != nullptr)
{
bApply->setEnabled(bOk->isEnabled());
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPointOfIntersectionCurves::CurveChanged()
{
QColor color = okColor;
QColor color;
if (getCurrentObjectId(ui->comboBoxCurve1) == getCurrentObjectId(ui->comboBoxCurve2))
{
flagError = false;
@ -243,7 +242,7 @@ void DialogPointOfIntersectionCurves::CurveChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelCurve1, color);
ChangeColor(ui->labelCurve2, color);

View File

@ -48,22 +48,23 @@ class DialogPointOfIntersectionCurves : public DialogTool
Q_OBJECT
public:
explicit DialogPointOfIntersectionCurves(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
explicit DialogPointOfIntersectionCurves(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogPointOfIntersectionCurves() override;
QString GetPointName() const;
void SetPointName(const QString &value);
quint32 GetFirstCurveId() const;
void SetFirstCurveId(const quint32 &value);
void SetFirstCurveId(quint32 value);
quint32 GetSecondCurveId() const;
void SetSecondCurveId(const quint32 &value);
void SetSecondCurveId(quint32 value);
VCrossCurvesPoint GetVCrossPoint() const;
void SetVCrossPoint(const VCrossCurvesPoint &vP);
void SetVCrossPoint(VCrossCurvesPoint vP);
HCrossCurvesPoint GetHCrossPoint() const;
void SetHCrossPoint(const HCrossCurvesPoint &hP);
void SetHCrossPoint(HCrossCurvesPoint hP);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
@ -75,7 +76,7 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual void CheckState() final;
virtual bool IsValid() const final;
private slots:
void CurveChanged();
@ -84,6 +85,17 @@ private:
Q_DISABLE_COPY(DialogPointOfIntersectionCurves)
Ui::DialogPointOfIntersectionCurves *ui;
QString pointName;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPointOfIntersectionCurves::IsValid() const
{
return flagName && flagError;
}
#endif // DIALOGPOINTOFINTERSECTIONCURVES_H

View File

@ -64,17 +64,19 @@
#include "ui_dialogrotation.h"
//---------------------------------------------------------------------------------------------------------------------
DialogRotation::DialogRotation(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogRotation::DialogRotation(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogRotation),
flagAngle(false),
timerAngle(nullptr),
timerAngle(new QTimer(this)),
formulaAngle(),
formulaBaseHeightAngle(0),
objects(),
stage1(true),
m_suffix(),
m_firstRelease(false)
m_firstRelease(false),
flagAngle(false),
flagName(false),
flagError(false)
{
ui->setupUi(this);
@ -83,19 +85,19 @@ DialogRotation::DialogRotation(const VContainer *data, const quint32 &toolId, QW
ui->lineEditSuffix->setText(qApp->getCurrentDocument()->GenerateSuffix());
timerAngle = new QTimer(this);
timerAngle->setSingleShot(true);
connect(timerAngle, &QTimer::timeout, this, &DialogRotation::EvalAngle);
InitOkCancelApply(ui);
FillComboBoxPoints(ui->comboBoxOriginPoint);
flagName = true;
CheckState();
connect(ui->lineEditSuffix, &QLineEdit::textChanged, this, &DialogRotation::SuffixChanged);
connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogRotation::FXAngle);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogRotation::AngleChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerAngle->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogRotation::DeployAngleTextEdit);
connect(ui->comboBoxOriginPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogRotation::PointChanged);
@ -116,7 +118,7 @@ quint32 DialogRotation::GetOrigPointId() const
}
//---------------------------------------------------------------------------------------------------------------------
void DialogRotation::SetOrigPointId(const quint32 &value)
void DialogRotation::SetOrigPointId(quint32 value)
{
ChangeCurrentData(ui->comboBoxOriginPoint, value);
VisToolRotation *operation = qobject_cast<VisToolRotation *>(vis);
@ -291,15 +293,7 @@ void DialogRotation::SelectedObject(bool selected, quint32 object, quint32 tool)
//---------------------------------------------------------------------------------------------------------------------
void DialogRotation::DeployAngleTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeightAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogRotation::AngleChanged()
{
labelEditFormula = ui->labelEditAngle;
labelResultCalculation = ui->labelResultAngle;
ValFormulaChanged(flagAngle, ui->plainTextEditFormula, timerAngle, degreeSymbol);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeightAngle);
}
//---------------------------------------------------------------------------------------------------------------------
@ -326,7 +320,7 @@ void DialogRotation::SuffixChanged()
if (suffix.isEmpty())
{
flagName = false;
ChangeColor(ui->labelSuffix, Qt::red);
ChangeColor(ui->labelSuffix, errorColor);
CheckState();
return;
}
@ -342,7 +336,7 @@ void DialogRotation::SuffixChanged()
if (not rx.match(name).hasMatch() || not data->IsUnique(name))
{
flagName = false;
ChangeColor(ui->labelSuffix, Qt::red);
ChangeColor(ui->labelSuffix, errorColor);
CheckState();
return;
}
@ -351,20 +345,11 @@ void DialogRotation::SuffixChanged()
}
flagName = true;
ChangeColor(ui->labelSuffix, okColor);
ChangeColor(ui->labelSuffix, OkColor(this));
}
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogRotation::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagAngle && flagName && flagError);
SCASSERT(bApply != nullptr)
bApply->setEnabled(bOk->isEnabled());
}
//---------------------------------------------------------------------------------------------------------------------
void DialogRotation::ShowVisualization()
{
@ -396,7 +381,7 @@ void DialogRotation::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogRotation::PointChanged()
{
QColor color = okColor;
QColor color;
if (objects.contains(getCurrentObjectId(ui->comboBoxOriginPoint)))
{
flagError = false;
@ -405,7 +390,7 @@ void DialogRotation::PointChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelOriginPoint, color);
CheckState();
@ -414,6 +399,13 @@ void DialogRotation::PointChanged()
//---------------------------------------------------------------------------------------------------------------------
void DialogRotation::EvalAngle()
{
labelEditFormula = ui->labelEditAngle;
Eval(ui->plainTextEditFormula->toPlainText(), flagAngle, ui->labelResultAngle, degreeSymbol, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditAngle;
formulaData.labelResult = ui->labelResultAngle;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, flagAngle);
}

View File

@ -49,11 +49,11 @@ class DialogRotation : public DialogTool
{
Q_OBJECT
public:
explicit DialogRotation(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
explicit DialogRotation(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogRotation();
quint32 GetOrigPointId() const;
void SetOrigPointId(const quint32 &value);
void SetOrigPointId(quint32 value);
QString GetAngle() const;
void SetAngle(const QString &value);
@ -72,17 +72,17 @@ public slots:
private slots:
/** @brief DeployAngleTextEdit grow or shrink formula input */
void DeployAngleTextEdit();
void AngleChanged();
void FXAngle();
void SuffixChanged();
void EvalAngle();
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
/** @brief SaveData Put dialog data in local variables */
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private slots:
void PointChanged();
@ -91,9 +91,6 @@ private:
Q_DISABLE_COPY(DialogRotation)
Ui::DialogRotation *ui;
/** @brief flagAngle true if value of angle is correct */
bool flagAngle;
/** @brief timerAngle timer of check formula of angle */
QTimer *timerAngle;
@ -111,7 +108,16 @@ private:
bool m_firstRelease;
void EvalAngle();
/** @brief flagAngle true if value of angle is correct */
bool flagAngle;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogRotation::IsValid() const
{
return flagAngle && flagName && flagError;
}
#endif // DIALOGROTATION_H

View File

@ -37,6 +37,7 @@
#include <QPointer>
#include <QPushButton>
#include <QSet>
#include <QTimer>
#include <QToolButton>
#include "../vpatterndb/vtranslatevars.h"
@ -56,23 +57,29 @@
* @param data container with data
* @param parent parent widget
*/
DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogShoulderPoint), formula(QString()),
formulaBaseHeight(0)
DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogShoulderPoint),
formula(),
formulaBaseHeight(0),
timerFormula(new QTimer(this)),
pointName(),
flagFormula(false),
flagName(true),
flagError(true)
{
ui->setupUi(this);
timerFormula->setSingleShot(true);
connect(timerFormula, &QTimer::timeout, this, &DialogShoulderPoint::EvalFormula);
ui->lineEditNamePoint->setClearButtonEnabled(true);
InitFormulaUI(ui);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
this->formulaBaseHeight = ui->plainTextEditFormula->height();
formulaBaseHeight = ui->plainTextEditFormula->height();
ui->plainTextEditFormula->installEventFilter(this);
InitOkCancelApply(ui);
flagFormula = false;
DialogTool::CheckState();
FillComboBoxTypeLine(ui->comboBoxLineType, LineStylesPics());
FillComboBoxPoints(ui->comboBoxP1Line);
@ -81,8 +88,15 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 &
FillComboBoxLineColors(ui->comboBoxLineColor);
connect(ui->toolButtonExprLength, &QPushButton::clicked, this, &DialogShoulderPoint::FXLength);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogShoulderPoint::NamePointChanged);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogShoulderPoint::FormulaTextChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, [this]()
{
timerFormula->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogShoulderPoint::DeployFormulaTextEdit);
connect(ui->comboBoxP1Line, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogShoulderPoint::PointNameChanged);
@ -94,12 +108,6 @@ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 &
vis = new VisToolShoulderPoint(data);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::FormulaTextChanged()
{
this->FormulaChangedPlainText();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::PointNameChanged()
{
@ -108,7 +116,7 @@ void DialogShoulderPoint::PointNameChanged()
set.insert(getCurrentObjectId(ui->comboBoxP2Line));
set.insert(getCurrentObjectId(ui->comboBoxP3));
QColor color = okColor;
QColor color;
if (set.size() != 3)
{
flagError = false;
@ -117,7 +125,7 @@ void DialogShoulderPoint::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelFirstPoint, color);
ChangeColor(ui->labelSecondPoint, color);
@ -139,6 +147,19 @@ void DialogShoulderPoint::FXLength()
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::EvalFormula()
{
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormula->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormula;
formulaData.labelResult = ui->labelResultCalculation;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
Eval(formulaData, flagFormula);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::ShowVisualization()
{
@ -148,7 +169,7 @@ void DialogShoulderPoint::ShowVisualization()
//---------------------------------------------------------------------------------------------------------------------
void DialogShoulderPoint::DeployFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
DeployFormula(this, ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -157,6 +178,12 @@ DialogShoulderPoint::~DialogShoulderPoint()
delete ui;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogShoulderPoint::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong.

View File

@ -50,9 +50,10 @@ class DialogShoulderPoint : public DialogTool
{
Q_OBJECT
public:
DialogShoulderPoint(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogShoulderPoint(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogShoulderPoint() override;
QString GetPointName() const;
void SetPointName(const QString &value);
QString GetTypeLine() const;
@ -78,12 +79,9 @@ public slots:
* @brief DeployFormulaTextEdit grow or shrink formula input
*/
void DeployFormulaTextEdit();
/**
* @brief FormulaTextChanged when formula text changes for validation and calc
*/
void FormulaTextChanged();
virtual void PointNameChanged() override;
void FXLength();
void EvalFormula();
protected:
virtual void ShowVisualization() override;
/**
@ -91,6 +89,7 @@ protected:
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogShoulderPoint)
@ -98,10 +97,24 @@ private:
Ui::DialogShoulderPoint *ui;
/** @brief formula formula */
QString formula;
QString formula;
/** @brief formulaBaseHeight base height defined by dialogui */
int formulaBaseHeight;
int formulaBaseHeight;
QTimer *timerFormula;
QString pointName;
bool flagFormula;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogShoulderPoint::IsValid() const
{
return flagFormula && flagName && flagError;
}
#endif // DIALOGSHOULDERPOINT_H

View File

@ -42,8 +42,12 @@
* @param data container with data
* @param parent parent widget
*/
DialogSinglePoint::DialogSinglePoint(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogSinglePoint), point(QPointF())
DialogSinglePoint::DialogSinglePoint(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogSinglePoint),
point(),
pointName(),
flagName(true)
{
ui->setupUi(this);
@ -51,13 +55,13 @@ DialogSinglePoint::DialogSinglePoint(const VContainer *data, const quint32 &tool
ui->doubleSpinBoxX->setRange(0, qApp->fromPixel(SceneSize));
ui->doubleSpinBoxY->setRange(0, qApp->fromPixel(SceneSize));
labelEditNamePoint = ui->labelEditName;
InitOkCancel(ui);
flagName = true;
DialogTool::CheckState();
connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogTool::NamePointChanged);
connect(ui->lineEditName, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditName, ui->labelEditName, pointName, this->data, flagName);
CheckState();
});
}
//---------------------------------------------------------------------------------------------------------------------
@ -118,3 +122,9 @@ QPointF DialogSinglePoint::GetPoint() const
{
return point;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogSinglePoint::GetPointName() const
{
return pointName;
}

View File

@ -50,12 +50,14 @@ class DialogSinglePoint : public DialogTool
{
Q_OBJECT
public:
DialogSinglePoint(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogSinglePoint(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogSinglePoint() override;
void SetData(const QString &name, const QPointF &point);
QPointF GetPoint()const;
QString GetPointName() const;
public slots:
void mousePress(const QPointF &scenePos);
protected:
@ -63,6 +65,7 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogSinglePoint)
@ -70,7 +73,17 @@ private:
Ui::DialogSinglePoint *ui;
/** @brief point data of point */
QPointF point;
QPointF point;
QString pointName;
bool flagName;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogSinglePoint::IsValid() const
{
return flagName;
}
#endif // DIALOGSINGLEPOINT_H

View File

@ -63,7 +63,7 @@
* @param data container with data
* @param parent parent widget
*/
DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogSpline::DialogSpline(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogSpline),
spl(),
@ -79,12 +79,11 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge
flagAngle1(false),
flagAngle2(false),
flagLength1(false),
flagLength2(false)
flagLength2(false),
flagError(false)
{
ui->setupUi(this);
plainTextEditFormula = ui->plainTextEditAngle1F;
formulaBaseHeightAngle1 = ui->plainTextEditAngle1F->height();
formulaBaseHeightAngle2 = ui->plainTextEditAngle2F->height();
formulaBaseHeightLength1 = ui->plainTextEditLength1F->height();
@ -95,6 +94,11 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge
ui->plainTextEditLength1F->installEventFilter(this);
ui->plainTextEditLength2F->installEventFilter(this);
timerAngle1->setSingleShot(true);
timerAngle2->setSingleShot(true);
timerLength1->setSingleShot(true);
timerLength2->setSingleShot(true);
connect(timerAngle1, &QTimer::timeout, this, &DialogSpline::EvalAngle1);
connect(timerAngle2, &QTimer::timeout, this, &DialogSpline::EvalAngle2);
connect(timerLength1, &QTimer::timeout, this, &DialogSpline::EvalLength1);
@ -109,8 +113,6 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge
ui->doubleSpinBoxApproximationScale->setMaximum(maxCurveApproximationScale);
CheckState();
connect(ui->comboBoxP1, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogSpline::PointNameChanged);
connect(ui->comboBoxP4, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -121,10 +123,25 @@ DialogSpline::DialogSpline(const VContainer *data, const quint32 &toolId, QWidge
connect(ui->toolButtonExprLength1, &QPushButton::clicked, this, &DialogSpline::FXLength1);
connect(ui->toolButtonExprLength2, &QPushButton::clicked, this, &DialogSpline::FXLength2);
connect(ui->plainTextEditAngle1F, &QPlainTextEdit::textChanged, this, &DialogSpline::Angle1Changed);
connect(ui->plainTextEditAngle2F, &QPlainTextEdit::textChanged, this, &DialogSpline::Angle2Changed);
connect(ui->plainTextEditLength1F, &QPlainTextEdit::textChanged, this, &DialogSpline::Length1Changed);
connect(ui->plainTextEditLength2F, &QPlainTextEdit::textChanged, this, &DialogSpline::Length2Changed);
connect(ui->plainTextEditAngle1F, &QPlainTextEdit::textChanged, this, [this]()
{
timerAngle1->start(formulaTimerTimeout);
});
connect(ui->plainTextEditAngle2F, &QPlainTextEdit::textChanged, this, [this]()
{
timerAngle2->start(formulaTimerTimeout);
});
connect(ui->plainTextEditLength1F, &QPlainTextEdit::textChanged, this, [this]()
{
timerLength1->start(formulaTimerTimeout);
});
connect(ui->plainTextEditLength2F, &QPlainTextEdit::textChanged, this, [this]()
{
timerLength2->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowAngle1, &QPushButton::clicked, this, &DialogSpline::DeployAngle1TextEdit);
connect(ui->pushButtonGrowAngle2, &QPushButton::clicked, this, &DialogSpline::DeployAngle2TextEdit);
@ -229,59 +246,25 @@ void DialogSpline::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::DeployAngle1TextEdit()
{
DeployFormula(ui->plainTextEditAngle1F, ui->pushButtonGrowAngle1, formulaBaseHeightAngle1);
DeployFormula(this, ui->plainTextEditAngle1F, ui->pushButtonGrowAngle1, formulaBaseHeightAngle1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::DeployAngle2TextEdit()
{
DeployFormula(ui->plainTextEditAngle2F, ui->pushButtonGrowAngle2, formulaBaseHeightAngle2);
DeployFormula(this, ui->plainTextEditAngle2F, ui->pushButtonGrowAngle2, formulaBaseHeightAngle2);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::DeployLength1TextEdit()
{
DeployFormula(ui->plainTextEditLength1F, ui->pushButtonGrowLength1, formulaBaseHeightLength1);
DeployFormula(this, ui->plainTextEditLength1F, ui->pushButtonGrowLength1, formulaBaseHeightLength1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::DeployLength2TextEdit()
{
DeployFormula(ui->plainTextEditLength2F, ui->pushButtonGrowLength2, formulaBaseHeightLength2);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::Angle1Changed()
{
labelEditFormula = ui->labelEditAngle1;
labelResultCalculation = ui->labelResultAngle1;
ValFormulaChanged(flagAngle1, ui->plainTextEditAngle1F, timerAngle1, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::Angle2Changed()
{
labelEditFormula = ui->labelEditAngle2;
labelResultCalculation = ui->labelResultAngle2;
ValFormulaChanged(flagAngle2, ui->plainTextEditAngle2F, timerAngle2, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::Length1Changed()
{
labelEditFormula = ui->labelEditLength1;
labelResultCalculation = ui->labelResultLength1;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagLength1, ui->plainTextEditLength1F, timerLength1, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::Length2Changed()
{
labelEditFormula = ui->labelEditLength2;
labelResultCalculation = ui->labelResultLength2;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagLength2, ui->plainTextEditLength2F, timerLength2, postfix);
DeployFormula(this, ui->plainTextEditLength2F, ui->pushButtonGrowLength2, formulaBaseHeightLength2);
}
//---------------------------------------------------------------------------------------------------------------------
@ -391,53 +374,59 @@ const QSharedPointer<VPointF> DialogSpline::GetP4() const
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::EvalAngle1()
{
labelEditFormula = ui->labelEditAngle1;
Eval(ui->plainTextEditAngle1F->toPlainText(), flagAngle1, ui->labelResultAngle1, degreeSymbol, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditAngle1F->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditAngle1;
formulaData.labelResult = ui->labelResultAngle1;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, flagAngle1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::EvalAngle2()
{
labelEditFormula = ui->labelEditAngle2;
Eval(ui->plainTextEditAngle2F->toPlainText(), flagAngle2, ui->labelResultAngle2, degreeSymbol, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditAngle2F->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditAngle2;
formulaData.labelResult = ui->labelResultAngle2;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, flagAngle2);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::EvalLength1()
{
labelEditFormula = ui->labelEditLength1;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal length1 = Eval(ui->plainTextEditLength1F->toPlainText(), flagLength1, ui->labelResultLength1, postfix,
false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditLength1F->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditLength1;
formulaData.labelResult = ui->labelResultLength1;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
if (length1 < 0)
{
flagLength1 = false;
ChangeColor(labelEditFormula, Qt::red);
ui->labelResultLength1->setText(tr("Error") + " (" + postfix + ")");
ui->labelResultLength1->setToolTip(tr("Length can't be negative"));
DialogSpline::CheckState();
}
Eval(formulaData, flagLength1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::EvalLength2()
{
labelEditFormula = ui->labelEditLength2;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal length2 = Eval(ui->plainTextEditLength2F->toPlainText(), flagLength2, ui->labelResultLength2, postfix,
false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditLength2F->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditLength2;
formulaData.labelResult = ui->labelResultLength2;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
if (length2 < 0)
{
flagLength2 = false;
ChangeColor(labelEditFormula, Qt::red);
ui->labelResultLength2->setText(tr("Error") + " (" + postfix + ")");
ui->labelResultLength2->setToolTip(tr("Length can't be negative"));
DialogSpline::CheckState();
}
Eval(formulaData, flagLength2);
}
//---------------------------------------------------------------------------------------------------------------------
@ -477,7 +466,7 @@ void DialogSpline::PointNameChanged()
set.insert(getCurrentObjectId(ui->comboBoxP1));
set.insert(getCurrentObjectId(ui->comboBoxP4));
QColor color = okColor;
QColor color;
if (getCurrentObjectId(ui->comboBoxP1) == getCurrentObjectId(ui->comboBoxP4))
{
flagError = false;
@ -488,7 +477,7 @@ void DialogSpline::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
if (getCurrentObjectId(ui->comboBoxP1) == spl.GetP1().id() &&
getCurrentObjectId(ui->comboBoxP4) == spl.GetP4().id())
@ -548,18 +537,6 @@ void DialogSpline::ShowDialog(bool click)
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagAngle1 && flagAngle2 && flagLength1 && flagLength2 && flagError);
// In case dialog hasn't apply button
if ( bApply != nullptr)
{
bApply->setEnabled(bOk->isEnabled());
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSpline::ShowVisualization()
{

View File

@ -54,7 +54,7 @@ class DialogSpline : public DialogTool
{
Q_OBJECT
public:
DialogSpline(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogSpline(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogSpline() override;
VSpline GetSpline() const;
@ -65,28 +65,28 @@ public slots:
virtual void PointNameChanged() override;
virtual void ShowDialog(bool click) override;
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
/**
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private slots:
void DeployAngle1TextEdit();
void DeployAngle2TextEdit();
void DeployLength1TextEdit();
void DeployLength2TextEdit();
void Angle1Changed();
void Angle2Changed();
void Length1Changed();
void Length2Changed();
void FXAngle1();
void FXAngle2();
void FXLength1();
void FXLength2();
void EvalAngle1();
void EvalAngle2();
void EvalLength1();
void EvalLength2();
private:
Q_DISABLE_COPY(DialogSpline)
@ -115,16 +115,18 @@ private:
bool flagAngle2;
bool flagLength1;
bool flagLength2;
bool flagError;
const QSharedPointer<VPointF> GetP1() const;
const QSharedPointer<VPointF> GetP4() const;
void EvalAngle1();
void EvalAngle2();
void EvalLength1();
void EvalLength2();
VSpline CurrentSpline() const;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogSpline::IsValid() const
{
return flagAngle1 && flagAngle2 && flagLength1 && flagLength2 && flagError;
}
#endif // DIALOGSPLINE_H

View File

@ -70,7 +70,7 @@
* @param data container with data
* @param parent parent widget
*/
DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogSplinePath::DialogSplinePath(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogSplinePath),
path(),
@ -82,12 +82,11 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId
flagAngle1(),
flagAngle2(),
flagLength1(),
flagLength2()
flagLength2(),
flagError(false)
{
ui->setupUi(this);
plainTextEditFormula = ui->plainTextEditAngle1F;
formulaBaseHeightAngle1 = ui->plainTextEditAngle1F->height();
formulaBaseHeightAngle2 = ui->plainTextEditAngle2F->height();
formulaBaseHeightLength1 = ui->plainTextEditLength1F->height();
@ -172,6 +171,8 @@ void DialogSplinePath::SetPath(const VSplinePath &value)
SCASSERT(visPath != nullptr)
visPath->setPath(path);
ui->listWidget->blockSignals(false);
flagError = IsPathValid();
}
//---------------------------------------------------------------------------------------------------------------------
@ -234,29 +235,6 @@ void DialogSplinePath::SaveData()
visPath->RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::CheckState()
{
SCASSERT(bOk != nullptr)
bool fAngle1 = true, fAngle2 = true, fLength1 = true, fLength2 = true;
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
{
fAngle1 = fAngle1 && flagAngle1.at(i);
fAngle2 = fAngle2 && flagAngle2.at(i);
fLength1 = fLength1 && flagLength1.at(i);
fLength2 = fLength2 && flagLength2.at(i);
}
bOk->setEnabled(fAngle1 && fAngle2 && fLength1 && fLength2 && flagError);
// In case dialog hasn't apply button
if (bApply != nullptr)
{
bApply->setEnabled(bOk->isEnabled());
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::closeEvent(QCloseEvent *event)
{
@ -270,25 +248,25 @@ void DialogSplinePath::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::DeployAngle1TextEdit()
{
DeployFormula(ui->plainTextEditAngle1F, ui->pushButtonGrowAngle1, formulaBaseHeightAngle1);
DeployFormula(this, ui->plainTextEditAngle1F, ui->pushButtonGrowAngle1, formulaBaseHeightAngle1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::DeployAngle2TextEdit()
{
DeployFormula(ui->plainTextEditAngle2F, ui->pushButtonGrowAngle2, formulaBaseHeightAngle2);
DeployFormula(this, ui->plainTextEditAngle2F, ui->pushButtonGrowAngle2, formulaBaseHeightAngle2);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::DeployLength1TextEdit()
{
DeployFormula(ui->plainTextEditLength1F, ui->pushButtonGrowLength1, formulaBaseHeightLength1);
DeployFormula(this, ui->plainTextEditLength1F, ui->pushButtonGrowLength1, formulaBaseHeightLength1);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSplinePath::DeployLength2TextEdit()
{
DeployFormula(ui->plainTextEditLength2F, ui->pushButtonGrowLength2, formulaBaseHeightLength2);
DeployFormula(this, ui->plainTextEditLength2F, ui->pushButtonGrowLength2, formulaBaseHeightLength2);
}
//---------------------------------------------------------------------------------------------------------------------
@ -518,8 +496,15 @@ void DialogSplinePath::EvalAngle1()
return;
}
labelEditFormula = ui->labelEditAngle1;
Eval(ui->plainTextEditAngle1F->toPlainText(), flagAngle1[row], ui->labelResultAngle1, degreeSymbol, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditAngle1F->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditAngle1;
formulaData.labelResult = ui->labelResultAngle1;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, flagAngle1[row]);
QListWidgetItem *item = ui->listWidget->item(row);
SCASSERT(item != nullptr)
@ -537,8 +522,15 @@ void DialogSplinePath::EvalAngle2()
return;
}
labelEditFormula = ui->labelEditAngle2;
Eval(ui->plainTextEditAngle2F->toPlainText(), flagAngle2[row], ui->labelResultAngle2, degreeSymbol, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditAngle2F->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditAngle2;
formulaData.labelResult = ui->labelResultAngle2;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, flagAngle2[row]);
QListWidgetItem *item = ui->listWidget->item(row);
SCASSERT(item != nullptr)
@ -556,20 +548,16 @@ void DialogSplinePath::EvalLength1()
return;
}
labelEditFormula = ui->labelEditLength1;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal length1 = Eval(ui->plainTextEditLength1F->toPlainText(), flagLength1[row], ui->labelResultLength1,
postfix, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditLength1F->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditLength1;
formulaData.labelResult = ui->labelResultLength1;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
if (length1 < 0)
{
flagLength1[row] = false;
ChangeColor(labelEditFormula, Qt::red);
ui->labelResultLength1->setText(tr("Error") + QLatin1String(" (") + postfix + QLatin1String(")"));
ui->labelResultLength1->setToolTip(tr("Length can't be negative"));
CheckState();
}
Eval(formulaData, flagLength1[row]);
QListWidgetItem *item = ui->listWidget->item(row);
SCASSERT(item != nullptr)
@ -587,20 +575,16 @@ void DialogSplinePath::EvalLength2()
return;
}
labelEditFormula = ui->labelEditLength2;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const qreal length2 = Eval(ui->plainTextEditLength2F->toPlainText(), flagLength2[row], ui->labelResultLength2,
postfix, false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditLength2F->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditLength2;
formulaData.labelResult = ui->labelResultLength2;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
if (length2 < 0)
{
flagLength2[row] = false;
ChangeColor(labelEditFormula, Qt::red);
ui->labelResultLength2->setText(tr("Error") + QLatin1String(" (") + postfix + QLatin1String(")"));
ui->labelResultLength2->setToolTip(tr("Length can't be negative"));
CheckState();
}
Eval(formulaData, flagLength2[row]);
QListWidgetItem *item = ui->listWidget->item(row);
SCASSERT(item != nullptr)
@ -641,7 +625,7 @@ void DialogSplinePath::currentPointChanged(int index)
item->setData(Qt::UserRole, QVariant::fromValue(p));
ShowPointIssue(p.P().name());
QColor color = okColor;
QColor color;
if (not IsPathValid())
{
flagError = false;
@ -652,7 +636,7 @@ void DialogSplinePath::currentPointChanged(int index)
else
{
flagError = true;
color = okColor;
color = OkColor(this);
auto first = qvariant_cast<VSplinePoint>(ui->listWidget->item(0)->data(Qt::UserRole));
auto last = qvariant_cast<VSplinePoint>(ui->listWidget->item(ui->listWidget->count()-1)->data(Qt::UserRole));
@ -758,7 +742,7 @@ void DialogSplinePath::DataPoint(const VSplinePoint &p)
ui->toolButtonExprAngle1->setEnabled(false);
ui->labelResultAngle1->setText(emptyRes);
ui->labelResultAngle1->setToolTip(tr("Value"));
ChangeColor(ui->labelEditAngle1, okColor);
ChangeColor(ui->labelEditAngle1, OkColor(this));
ui->plainTextEditAngle1F->blockSignals(true);
ui->plainTextEditAngle1F->setPlainText(field);
ui->plainTextEditAngle1F->setEnabled(false);
@ -767,7 +751,7 @@ void DialogSplinePath::DataPoint(const VSplinePoint &p)
ui->toolButtonExprLength1->setEnabled(false);
ui->labelResultLength1->setText(emptyRes);
ui->labelResultLength1->setToolTip(tr("Value"));
ChangeColor(ui->labelEditLength1, okColor);
ChangeColor(ui->labelEditLength1, OkColor(this));
ui->plainTextEditLength1F->blockSignals(true);
ui->plainTextEditLength1F->setPlainText(field);
ui->plainTextEditLength1F->setEnabled(false);
@ -795,7 +779,7 @@ void DialogSplinePath::DataPoint(const VSplinePoint &p)
ui->toolButtonExprAngle2->setEnabled(false);
ui->labelResultAngle2->setText(emptyRes);
ui->labelResultAngle2->setToolTip(tr("Value"));
ChangeColor(ui->labelEditAngle2, okColor);
ChangeColor(ui->labelEditAngle2, OkColor(this));
ui->plainTextEditAngle2F->blockSignals(true);
ui->plainTextEditAngle2F->setPlainText(field);
ui->plainTextEditAngle2F->setEnabled(false);
@ -804,7 +788,7 @@ void DialogSplinePath::DataPoint(const VSplinePoint &p)
ui->toolButtonExprLength2->setEnabled(false);
ui->labelResultLength2->setText(emptyRes);
ui->labelResultLength2->setToolTip(tr("Value"));
ChangeColor(ui->labelEditLength2, okColor);
ChangeColor(ui->labelEditLength2, OkColor(this));
ui->plainTextEditLength2F->blockSignals(true);
ui->plainTextEditLength2F->setPlainText(field);
ui->plainTextEditLength2F->setEnabled(false);
@ -930,3 +914,19 @@ void DialogSplinePath::ShowPointIssue(const QString &pName)
item->setText(pName + QLatin1String("(!)"));
}
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogSplinePath::IsValid() const
{
bool fAngle1 = true, fAngle2 = true, fLength1 = true, fLength2 = true;
for (qint32 i = 0; i < ui->listWidget->count(); ++i)
{
fAngle1 = fAngle1 && flagAngle1.at(i);
fAngle2 = fAngle2 && flagAngle2.at(i);
fLength1 = fLength1 && flagLength1.at(i);
fLength2 = fLength2 && flagLength2.at(i);
}
return fAngle1 && fAngle2 && fLength1 && fLength2 && flagError;
}

View File

@ -53,7 +53,7 @@ class DialogSplinePath : public DialogTool
{
Q_OBJECT
public:
DialogSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogSplinePath(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogSplinePath() override;
VSplinePath GetPath() const;
@ -65,8 +65,8 @@ public slots:
protected:
virtual void ShowVisualization() override;
virtual void SaveData() override;
virtual void CheckState() final;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private slots:
void PointChanged(int row);
void currentPointChanged(int index);
@ -107,6 +107,7 @@ private:
QVector<bool> flagAngle2;
QVector<bool> flagLength1;
QVector<bool> flagLength2;
bool flagError;
void EvalAngle1();
void EvalAngle2();

View File

@ -77,8 +77,6 @@ template <class T> class QSharedPointer;
Q_LOGGING_CATEGORY(vDialog, "v.dialog")
#define DIALOG_MAX_FORMULA_HEIGHT 80
namespace
{
//---------------------------------------------------------------------------------------------------------------------
@ -153,32 +151,19 @@ bool DoubleCurve(const VPieceNode &firstNode, const VPieceNode &secondNode, cons
* @param data container with data
* @param parent parent widget
*/
DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogTool::DialogTool(const VContainer *data, quint32 toolId, QWidget *parent)
: QDialog(parent),
data(data),
isInitialized(false),
flagName(true),
flagFormula(true),
flagError(true),
timerFormula(new QTimer(this)),
bOk(nullptr),
bApply(nullptr),
spinBoxAngle(nullptr),
plainTextEditFormula(nullptr),
labelResultCalculation(nullptr),
labelEditNamePoint(nullptr),
labelEditFormula(nullptr),
okColor(this->palette().color(QPalette::Active, QPalette::WindowText)),
errorColor(Qt::red),
associatedTool(nullptr),
toolId(toolId),
prepare(false),
pointName(),
number(0),
vis(nullptr)
{
SCASSERT(data != nullptr)
connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula);
}
//---------------------------------------------------------------------------------------------------------------------
@ -226,6 +211,8 @@ void DialogTool::showEvent(QShowEvent *event)
isInitialized = true;//first show windows are held
ShowVisualization();
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
@ -261,13 +248,13 @@ void DialogTool::FillComboBoxPiecesList(QComboBox *box, const QVector<quint32> &
* @brief FillComboBoxPoints fill comboBox list of points
* @param box comboBox
*/
void DialogTool::FillComboBoxPoints(QComboBox *box, FillComboBox rule, const quint32 &ch1, const quint32 &ch2) const
void DialogTool::FillComboBoxPoints(QComboBox *box, FillComboBox rule, quint32 ch1, quint32 ch2) const
{
FillCombo<VPointF>(box, GOType::Point, rule, ch1, ch2);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::FillComboBoxArcs(QComboBox *box, FillComboBox rule, const quint32 &ch1, const quint32 &ch2) const
void DialogTool::FillComboBoxArcs(QComboBox *box, FillComboBox rule, quint32 ch1, quint32 ch2) const
{
FillCombo<VAbstractCurve>(box, GOType::Arc, rule, ch1, ch2);
}
@ -448,43 +435,16 @@ void DialogTool::ChangeCurrentData(QComboBox *box, const QVariant &value) const
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const
{
SCASSERT(plainTextEdit != nullptr)
QTextCursor cursor = plainTextEdit->textCursor();
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
plainTextEdit->setTextCursor(cursor);
}
//---------------------------------------------------------------------------------------------------------------------
bool DialogTool::eventFilter(QObject *object, QEvent *event)
{
if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(object))
const bool fitered = FilterObject(object, event);
if (fitered)
{
if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
{
if (qApp->Settings()->GetOsSeparator())
{
plainTextEdit->insertPlainText(QLocale().decimalPoint());
}
else
{
plainTextEdit->insertPlainText(QLocale::c().decimalPoint());
}
return true;
}
}
return fitered;
}
else
{
// pass the event on to the parent class
return QDialog::eventFilter(object, event);
}
return false;// pass the event to the widget
return QDialog::eventFilter(object, event);
}
//---------------------------------------------------------------------------------------------------------------------
@ -831,146 +791,14 @@ bool DialogTool::IsSplinePath(const QSharedPointer<VGObject> &obj) const
return obj->getType() == GOType::SplinePath || obj->getType() == GOType::CubicBezierPath;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ValFormulaChanged handle change formula
* @param flag flag state of formula
* @param edit LineEdit
* @param timer timer of formula
*/
void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer, const QString& postfix)
{
SCASSERT(edit != nullptr)
SCASSERT(timer != nullptr)
SCASSERT(labelEditFormula != nullptr)
SCASSERT(labelResultCalculation != nullptr)
if (edit->text().isEmpty())
{
flag = false;
CheckState();
ChangeColor(labelEditFormula, Qt::red);
if (postfix.isEmpty())
{
labelResultCalculation->setText(tr("Error"));
}
else
{
labelResultCalculation->setText(tr("Error") + " (" + postfix + ")");
}
labelResultCalculation->setToolTip(tr("Empty field"));
return;
}
timer->start(1000);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *timer, const QString& postfix)
{
SCASSERT(edit != nullptr)
SCASSERT(timer != nullptr)
SCASSERT(labelEditFormula != nullptr)
SCASSERT(labelResultCalculation != nullptr)
if (edit->toPlainText().isEmpty())
{
flag = false;
CheckState();
ChangeColor(labelEditFormula, Qt::red);
if (postfix.isEmpty())
{
labelResultCalculation->setText(tr("Error"));
}
else
{
labelResultCalculation->setText(tr("Error") + " (" + postfix + ")");
}
labelResultCalculation->setToolTip(tr("Empty field"));
return;
}
timer->setSingleShot(true);
timer->start(300);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Eval evaluate formula and show result
* @param text expresion that we parse
* @param flag flag state of eval formula
* @param label label for signal error
* @param postfix unit name
* @param checkZero true - if formula can't be equal zero
* @param formulaData options to control parsing
*/
qreal DialogTool::Eval(const QString &text, bool &flag, QLabel *label, const QString& postfix, bool checkZero,
bool checkLessThanZero)
qreal DialogTool::Eval(const FormulaData &formulaData, bool &flag)
{
SCASSERT(label != nullptr)
SCASSERT(labelEditFormula != nullptr)
qreal result = INT_MIN;//Value can be 0, so use max imposible value
if (text.isEmpty())
{
flag = false;
ChangeColor(labelEditFormula, Qt::red);
label->setText(tr("Error") + " (" + postfix + ")");
label->setToolTip(tr("Empty field"));
}
else
{
try
{
// Translate to internal look.
QString formula = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator());
QScopedPointer<Calculator> cal(new Calculator());
result = cal->EvalFormula(data->DataVariables(), formula);
if (qIsInf(result) || qIsNaN(result))
{
flag = false;
ChangeColor(labelEditFormula, Qt::red);
label->setText(tr("Error") + " (" + postfix + ")");
label->setToolTip(tr("Invalid result. Value is infinite or NaN. Please, check your calculations."));
}
else
{
//if result equal 0
if (checkZero && qFuzzyIsNull(result))
{
flag = false;
ChangeColor(labelEditFormula, Qt::red);
label->setText(tr("Error") + " (" + postfix + ")");
label->setToolTip(tr("Value can't be 0"));
}
else if (checkLessThanZero && result < 0)
{
flag = false;
ChangeColor(labelEditFormula, Qt::red);
label->setText(tr("Error") + " (" + postfix + ")");
label->setToolTip(tr("Value can't be less than 0"));
}
else
{
label->setText(qApp->LocaleToString(result) + QChar(QChar::Space) +postfix);
flag = true;
ChangeColor(labelEditFormula, okColor);
label->setToolTip(tr("Value"));
emit ToolTip(QString());
}
}
}
catch (qmu::QmuParserError &e)
{
label->setText(tr("Error") + " (" + postfix + ")");
flag = false;
ChangeColor(labelEditFormula, Qt::red);
emit ToolTip(tr("Parser error: %1").arg(e.GetMsg()));
label->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
qDebug() << "\nMath parser error:\n"
<< "--------------------------------------\n"
<< "Message: " << e.GetMsg() << "\n"
<< "Expression: " << e.GetExpr() << "\n"
<< "--------------------------------------";
}
}
const qreal result = EvalToolFormula(this, formulaData, flag);
CheckState(); // Disable Ok and Apply buttons if something wrong.
return result;
}
@ -1071,45 +899,6 @@ bool DialogTool::SetObject(const quint32 &id, QComboBox *box, const QString &too
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::DeployFormula(QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight)
{
SCASSERT(formula != nullptr)
SCASSERT(buttonGrowLength != nullptr)
const QTextCursor cursor = formula->textCursor();
//Before deploy ned to release dialog size
//I don't know why, but don't need to fixate again.
//A dialog will be lefted fixated. That's what we need.
setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
setMinimumSize(QSize(0, 0));
if (formula->height() < DIALOG_MAX_FORMULA_HEIGHT)
{
formula->setFixedHeight(DIALOG_MAX_FORMULA_HEIGHT);
//Set icon from theme (internal for Windows system)
buttonGrowLength->setIcon(QIcon::fromTheme("go-next",
QIcon(":/icons/win.icon.theme/16x16/actions/go-next.png")));
}
else
{
formula->setFixedHeight(formulaBaseHeight);
//Set icon from theme (internal for Windows system)
buttonGrowLength->setIcon(QIcon::fromTheme("go-down",
QIcon(":/icons/win.icon.theme/16x16/actions/go-down.png")));
}
// I found that after change size of formula field, it was filed for angle formula, field for formula became black.
// This code prevent this.
setUpdatesEnabled(false);
repaint();
setUpdatesEnabled(true);
formula->setFocus();
formula->setTextCursor(cursor);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief FillList fill combobox list
@ -1161,7 +950,7 @@ bool DialogTool::IsSpline(const QSharedPointer<VGObject> &obj) const
void DialogTool::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagFormula && flagName && flagError);
bOk->setEnabled(IsValid());
// In case dialog hasn't apply button
if ( bApply != nullptr)
{
@ -1189,43 +978,6 @@ void DialogTool::SelectedObject(bool selected, quint32 object, quint32 tool)
Q_UNUSED(tool)
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief NamePointChanged check name of point
*/
void DialogTool::NamePointChanged()
{
SCASSERT(labelEditNamePoint != nullptr)
QLineEdit* edit = qobject_cast<QLineEdit*>(sender());
if (edit)
{
QString name = edit->text();
QRegularExpression rx(NameRegExp());
if (name.isEmpty() || (pointName != name && data->IsUnique(name) == false) ||
rx.match(name).hasMatch() == false)
{
flagName = false;
ChangeColor(labelEditNamePoint, Qt::red);
}
else
{
flagName = true;
ChangeColor(labelEditNamePoint, okColor);
}
}
CheckState();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::ChangeColor(QWidget *widget, const QColor &color)
{
SCASSERT(widget != nullptr)
QPalette palette = widget->palette();
palette.setColor(QPalette::Active, widget->foregroundRole(), color);
palette.setColor(QPalette::Inactive, widget->foregroundRole(), color);
widget->setPalette(palette);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief DialogAccepted save data and emit signal about closed dialog.
@ -1252,120 +1004,6 @@ void DialogTool::DialogRejected()
emit DialogClosed(QDialog::Rejected);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief formula check formula
*/
void DialogTool::FormulaChanged()
{
QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(sender());
if (edit)
{
ValFormulaChanged(flagFormula, edit, timerFormula);
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::FormulaChangedPlainText() //-V524
{
QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(sender());
if (edit)
{
ValFormulaChanged(flagFormula, edit, timerFormula);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArrowUp set angle value 90 degree
*/
void DialogTool::ArrowUp()
{
SCASSERT(spinBoxAngle != nullptr)
spinBoxAngle->setValue(90);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArrowDown set angle value 270 degree
*/
void DialogTool::ArrowDown()
{
SCASSERT(spinBoxAngle != nullptr)
spinBoxAngle->setValue(270);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArrowLeft set angle value 180 degree
*/
void DialogTool::ArrowLeft()
{
SCASSERT(spinBoxAngle != nullptr)
spinBoxAngle->setValue(180);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArrowRight set angle value 0 degree
*/
void DialogTool::ArrowRight()
{
SCASSERT(spinBoxAngle != nullptr)
spinBoxAngle->setValue(0);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArrowLeftUp set angle value 135 degree
*/
void DialogTool::ArrowLeftUp()
{
SCASSERT(spinBoxAngle != nullptr)
spinBoxAngle->setValue(135);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArrowLeftDown set angle value 225 degree
*/
void DialogTool::ArrowLeftDown()
{
SCASSERT(spinBoxAngle != nullptr)
spinBoxAngle->setValue(225);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArrowRightUp set angle value 45 degree
*/
void DialogTool::ArrowRightUp()
{
SCASSERT(spinBoxAngle != nullptr)
spinBoxAngle->setValue(45);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ArrowRightDown set angle value 315 degree
*/
void DialogTool::ArrowRightDown()
{
SCASSERT(spinBoxAngle != nullptr)
spinBoxAngle->setValue(315);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief EvalFormula evaluate formula
*/
void DialogTool::EvalFormula()
{
SCASSERT(plainTextEditFormula != nullptr)
SCASSERT(labelResultCalculation != nullptr)
const QString postfix = UnitsToStr(qApp->patternUnit());//Show unit in dialog lable (cm, mm or inch)
Eval(plainTextEditFormula->toPlainText(), flagFormula, labelResultCalculation, postfix, false);
}
//---------------------------------------------------------------------------------------------------------------------
// cppcheck-suppress unusedFunction
quint32 DialogTool::GetToolId() const
@ -1379,12 +1017,6 @@ void DialogTool::SetToolId(const quint32 &value)
toolId = value;
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogTool::getPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTool::ShowDialog(bool click)
{

View File

@ -58,6 +58,7 @@
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/vcommonsettings.h"
#include "../vwidgets/vmaingraphicsscene.h"
#include "../dialogtoolbox.h"
template <class T> class QSharedPointer;
@ -77,7 +78,7 @@ class DialogTool : public QDialog
{
Q_OBJECT
public:
DialogTool(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogTool(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogTool() override;
VAbstractTool* GetAssociatedTool();
@ -90,8 +91,6 @@ public:
quint32 GetToolId() const;
void SetToolId(const quint32 &value);
QString getPointName() const;
static void MoveListRowTop(QListWidget *list);
static void MoveListRowUp(QListWidget *list);
static void MoveListRowDown(QListWidget *list);
@ -114,32 +113,14 @@ signals:
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type);
virtual void SelectedObject(bool selected, quint32 object, quint32 tool);
void NamePointChanged();
virtual void DialogAccepted();
/**
* @brief DialogApply save data and emit signal DialogApplied.
*/
virtual void DialogApply();
virtual void DialogRejected();
void FormulaChanged();
/**
* @brief FormulaChangedPlainText check formula (plain text editor editor)
*/
void FormulaChangedPlainText();
void ArrowUp();
void ArrowDown();
void ArrowLeft();
void ArrowRight();
void ArrowLeftUp();
void ArrowLeftDown();
void ArrowRightUp();
void ArrowRightDown();
virtual void EvalFormula();
virtual void PointNameChanged() {}
protected:
Q_DISABLE_COPY(DialogTool)
/** @brief data container with data */
// cppcheck-suppress duplInheritedMember
const VContainer *data;
@ -147,45 +128,12 @@ protected:
/** @brief isInitialized true if window is initialized */
bool isInitialized;
/** @brief flagName true if name is correct */
bool flagName;
/** @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;
/** @brief bOk button ok */
QPushButton *bOk;
/** @brief bApply button apply */
QPushButton *bApply;
/** @brief spinBoxAngle spinbox for angle */
QDoubleSpinBox *spinBoxAngle;
/** @brief plainTextEditFormula formula */
QPlainTextEdit *plainTextEditFormula;
/** @brief labelResultCalculation label with result of calculation */
QLabel *labelResultCalculation;
/** @brief labelEditNamePoint label used when need show wrong name of point */
QLabel *labelEditNamePoint;
/** @brief labelEditFormula label used when need show wrong formula */
QLabel *labelEditFormula;
const QColor okColor;
const QColor errorColor;
/**
* @brief associatedTool vdrawtool associated with opened dialog.
*/
@ -195,9 +143,6 @@ protected:
/** @brief prepare show if we prepare. Show dialog after finish working with visual part of tool*/
bool prepare;
/** @brief pointName name of point */
QString pointName;
/** @brief number number of handled objects */
qint32 number;
@ -206,12 +151,16 @@ protected:
virtual void closeEvent ( QCloseEvent * event ) override;
virtual void showEvent( QShowEvent *event ) override;
virtual void keyPressEvent(QKeyEvent *event) override;
virtual bool eventFilter(QObject *object, QEvent *event) override;
virtual bool IsValid() const =0;
virtual void CheckState();
void FillComboBoxPiecesList(QComboBox *box, const QVector<quint32> &list);
void FillComboBoxPoints(QComboBox *box, FillComboBox rule = FillComboBox::Whole,
const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const;
quint32 ch1 = NULL_ID, quint32 ch2 = NULL_ID) const;
void FillComboBoxArcs(QComboBox *box, FillComboBox rule = FillComboBox::Whole,
const quint32 &ch1 = NULL_ID, const quint32 &ch2 = NULL_ID)const;
quint32 ch1 = NULL_ID, quint32 ch2 = NULL_ID) const;
void FillComboBoxSplines(QComboBox *box)const;
void FillComboBoxSplinesPath(QComboBox *box)const;
void FillComboBoxCurves(QComboBox *box)const;
@ -221,14 +170,10 @@ protected:
void FillComboBoxVCrossCurvesPoint(QComboBox *box) const;
void FillComboBoxHCrossCurvesPoint(QComboBox *box) const;
virtual void CheckState();
QString GetComboBoxCurrentData(const QComboBox *box, const QString &def)const;
void ChangeCurrentData(QComboBox *box, const QVariant &value) const;
void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer, const QString &postfix = QString());
void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer,
const QString &postfix = QString());
qreal Eval(const QString &text, bool &flag, QLabel *label, const QString &postfix,
bool checkZero = true, bool checkLessThanZero = false);
qreal Eval(const FormulaData &formulaData, bool &flag);
void setCurrentPointId(QComboBox *box, const quint32 &value,
FillComboBox rule = FillComboBox::NoChildren,
@ -246,10 +191,6 @@ protected:
T getCurrentCrossPoint(QComboBox *box) const;
bool SetObject(const quint32 &id, QComboBox *box, const QString &toolTip);
void DeployFormula(QPlainTextEdit *formula, QPushButton *buttonGrowLength, int formulaBaseHeight);
template <typename T>
void InitArrow(T *ui);
template <typename T>
void InitOkCancelApply(T *ui);
@ -257,23 +198,17 @@ protected:
template <typename T>
void InitOkCancel(T *ui);
template <typename T>
void InitFormulaUI(T *ui);
template <typename T>
void AddVisualization();
template <typename T>
QVector<T> GetListInternals(const QListWidget *list) const;
void ChangeColor(QWidget *widget, const QColor &color);
virtual void ShowVisualization() {}
/**
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() {}
void MoveCursorToEnd(QPlainTextEdit *plainTextEdit) const;
virtual bool eventFilter(QObject *object, QEvent *event) override;
quint32 DNumber(const QString &baseName) const;
static int FindNotExcludedNodeDown(QListWidget *listWidget, int candidate);
@ -290,6 +225,7 @@ protected:
void InitNodeAngles(QComboBox *box);
private:
Q_DISABLE_COPY(DialogTool)
void FillList(QComboBox *box, const QMap<QString, quint32> &list)const;
template <typename T>
@ -325,22 +261,6 @@ inline VAbstractTool *DialogTool::GetAssociatedTool()
return this->associatedTool;
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline void DialogTool::InitArrow(T *ui)
{
SCASSERT(ui != nullptr)
spinBoxAngle = ui->doubleSpinBoxAngle;
connect(ui->toolButtonArrowDown, &QPushButton::clicked, this, &DialogTool::ArrowDown);
connect(ui->toolButtonArrowUp, &QPushButton::clicked, this, &DialogTool::ArrowUp);
connect(ui->toolButtonArrowLeft, &QPushButton::clicked, this, &DialogTool::ArrowLeft);
connect(ui->toolButtonArrowRight, &QPushButton::clicked, this, &DialogTool::ArrowRight);
connect(ui->toolButtonArrowLeftUp, &QPushButton::clicked, this, &DialogTool::ArrowLeftUp);
connect(ui->toolButtonArrowLeftDown, &QPushButton::clicked, this, &DialogTool::ArrowLeftDown);
connect(ui->toolButtonArrowRightUp, &QPushButton::clicked, this, &DialogTool::ArrowRightUp);
connect(ui->toolButtonArrowRightDown, &QPushButton::clicked, this, &DialogTool::ArrowRightDown);
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
/**
@ -374,19 +294,6 @@ inline void DialogTool::InitOkCancel(T *ui)
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
/**
* @brief InitFormulaUI initialise ui object for formula fild
* @param ui Dialog container
*/
inline void DialogTool::InitFormulaUI(T *ui)
{
labelResultCalculation = ui->labelResultCalculation;
plainTextEditFormula = ui->plainTextEditFormula;
labelEditFormula = ui->labelEditFormula;
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline void DialogTool::AddVisualization()

View File

@ -48,25 +48,31 @@
* @param data container with data
* @param parent parent widget
*/
DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle)
DialogTriangle::DialogTriangle(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogTriangle),
pointName(),
flagName(false),
flagError(false)
{
ui->setupUi(this);
ui->lineEditNamePoint->setClearButtonEnabled(true);
ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
labelEditNamePoint = ui->labelEditNamePoint;
InitOkCancelApply(ui);
DialogTool::CheckState();
FillComboBoxPoints(ui->comboBoxAxisP1);
FillComboBoxPoints(ui->comboBoxAxisP2);
FillComboBoxPoints(ui->comboBoxFirstPoint);
FillComboBoxPoints(ui->comboBoxSecondPoint);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogTriangle::NamePointChanged);
connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, [this]()
{
CheckPointLabel(this, ui->lineEditNamePoint, ui->labelEditNamePoint, pointName, this->data, flagName);
CheckState();
});
connect(ui->comboBoxFirstPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
this, &DialogTriangle::PointNameChanged);
connect(ui->comboBoxSecondPoint, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
@ -189,7 +195,7 @@ void DialogTriangle::PointNameChanged()
set.insert(getCurrentObjectId(ui->comboBoxAxisP1));
set.insert(getCurrentObjectId(ui->comboBoxAxisP2));
QColor color = okColor;
QColor color;
if (set.size() < 3)//Need tree or more unique points for creation triangle
{
flagError = false;
@ -198,7 +204,7 @@ void DialogTriangle::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelFirstPoint, color);
ChangeColor(ui->labelSecondPoint, color);
@ -235,7 +241,13 @@ void DialogTriangle::SetSecondPointId(const quint32 &value)
VisToolTriangle *line = qobject_cast<VisToolTriangle *>(vis);
SCASSERT(line != nullptr)
line->setHypotenuseP2Id(value);
line->setHypotenuseP2Id(value);
}
//---------------------------------------------------------------------------------------------------------------------
QString DialogTriangle::GetPointName() const
{
return pointName;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -50,7 +50,7 @@ class DialogTriangle : public DialogTool
{
Q_OBJECT
public:
DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogTriangle(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogTriangle() override;
quint32 GetAxisP1Id() const;
@ -65,6 +65,7 @@ public:
quint32 GetSecondPointId() const;
void SetSecondPointId(const quint32 &value);
QString GetPointName() const;
void SetPointName(const QString &value);
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
@ -75,11 +76,23 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogTriangle)
/** @brief ui keeps information about user interface */
Ui::DialogTriangle *ui;
QString pointName;
bool flagName;
bool flagError;
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogTriangle::IsValid() const
{
return flagName && flagError;
}
#endif // DIALOGTRIANGLE_H

View File

@ -50,9 +50,16 @@
#include "ui_dialogtruedarts.h"
//---------------------------------------------------------------------------------------------------------------------
DialogTrueDarts::DialogTrueDarts(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogTrueDarts), d1PointName(), d2PointName(), ch1(NULL_ID),
ch2(NULL_ID), flagName1(true), flagName2(true)
DialogTrueDarts::DialogTrueDarts(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogTrueDarts),
d1PointName(),
d2PointName(),
ch1(NULL_ID),
ch2(NULL_ID),
flagName1(true),
flagName2(true),
flagError(false)
{
ui->setupUi(this);
@ -65,7 +72,6 @@ DialogTrueDarts::DialogTrueDarts(const VContainer *data, const quint32 &toolId,
ui->lineEditSecondNewDartPoint->setText(name2);
InitOkCancelApply(ui);
CheckState();
FillComboBoxs(ch1, ch2);
@ -317,7 +323,7 @@ void DialogTrueDarts::PointNameChanged()
set.insert(getCurrentObjectId(ui->comboBoxSecondDartPoint));
set.insert(getCurrentObjectId(ui->comboBoxThirdDartPoint));
QColor color = okColor;
QColor color;
if (set.size() != 5)
{
flagError = false;
@ -326,7 +332,7 @@ void DialogTrueDarts::PointNameChanged()
else
{
flagError = true;
color = okColor;
color = OkColor(this);
}
ChangeColor(ui->labelFirstBasePoint, color);
ChangeColor(ui->labelSecondBasePoint, color);
@ -371,18 +377,6 @@ void DialogTrueDarts::SaveData()
points->RefreshGeometry();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTrueDarts::CheckState()
{
SCASSERT(bOk != nullptr)
bOk->setEnabled(flagName1 && flagName2 && flagError);
// In case dialog hasn't apply button
if ( bApply != nullptr)
{
bApply->setEnabled(bOk->isEnabled());
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogTrueDarts::NameChanged(QLabel *labelEditNamePoint, const QString &pointD1Name, const QString &pointD2Name,
QLineEdit* secondPointName, bool &flagName)
@ -424,11 +418,11 @@ void DialogTrueDarts::CheckName(QLineEdit *edit, QLabel *labelEditNamePoint, con
|| rx.match(name).hasMatch() == false)
{
flagName = false;
ChangeColor(labelEditNamePoint, Qt::red);
ChangeColor(labelEditNamePoint, errorColor);
}
else
{
flagName = true;
ChangeColor(labelEditNamePoint, okColor);
ChangeColor(labelEditNamePoint, OkColor(this));
}
}

View File

@ -48,7 +48,7 @@ class DialogTrueDarts : public DialogTool
Q_OBJECT
public:
DialogTrueDarts(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogTrueDarts(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
~DialogTrueDarts();
QString GetFirstNewDartPointName();
@ -82,7 +82,7 @@ protected:
* @brief SaveData Put dialog data in local variables
*/
virtual void SaveData() override;
virtual void CheckState() final;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogTrueDarts)
@ -96,6 +96,7 @@ private:
bool flagName1;
bool flagName2;
bool flagError;
void NameChanged(QLabel *labelEditNamePoint, const QString &pointD1Name, const QString &pointD2Name,
QLineEdit *secondPointName, bool &flagName);
@ -106,4 +107,10 @@ private:
QLineEdit *secondPointName, bool &flagName);
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogTrueDarts::IsValid() const
{
return flagName1 && flagName2 && flagError;
}
#endif // DIALOGTRUEDARTS_H

View File

@ -44,9 +44,17 @@
* @param data container with data
* @param parent parent widget
*/
DialogUnionDetails::DialogUnionDetails(const VContainer *data, const quint32 &toolId, QWidget *parent)
:DialogTool(data, toolId, parent), ui(new Ui::DialogUnionDetails), indexD1(0), indexD2(0), d1(NULL_ID), d2(NULL_ID),
numberD(0), numberP(0), p1(NULL_ID), p2(NULL_ID)
DialogUnionDetails::DialogUnionDetails(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogUnionDetails),
indexD1(0),
indexD2(0),
d1(NULL_ID),
d2(NULL_ID),
numberD(0),
numberP(0),
p1(NULL_ID),
p2(NULL_ID)
{
ui->setupUi(this);
InitOkCancel(ui);

View File

@ -50,7 +50,7 @@ class DialogUnionDetails : public DialogTool
{
Q_OBJECT
public:
DialogUnionDetails(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogUnionDetails(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogUnionDetails() override;
quint32 getD1() const;
@ -61,6 +61,8 @@ public:
bool RetainPieces() const;
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
protected:
virtual bool IsValid() const final {return true;}
private:
Q_DISABLE_COPY(DialogUnionDetails)

View File

@ -31,7 +31,7 @@
#include "../../../visualization/path/vistoolduplicatedetail.h"
//---------------------------------------------------------------------------------------------------------------------
DialogDuplicateDetail::DialogDuplicateDetail(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogDuplicateDetail::DialogDuplicateDetail(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogDuplicateDetail),
m_idDetail(NULL_ID),

View File

@ -40,7 +40,7 @@ class DialogDuplicateDetail : public DialogTool
Q_OBJECT
public:
explicit DialogDuplicateDetail(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
explicit DialogDuplicateDetail(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogDuplicateDetail();
quint32 Duplicate() const;
@ -50,6 +50,8 @@ public:
virtual void ShowDialog(bool click) override;
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
protected:
virtual bool IsValid() const final {return true;}
private:
Q_DISABLE_COPY(DialogDuplicateDetail)
Ui::DialogDuplicateDetail *ui;

View File

@ -35,7 +35,8 @@ DialogInsertNode::DialogInsertNode(const VContainer *data, quint32 toolId, QWidg
: DialogTool(data, toolId, parent),
ui(new Ui::DialogInsertNode),
m_node(),
m_flagItem(false)
m_flagItem(false),
m_flagError(false)
{
ui->setupUi(this);
InitOkCancel(ui);
@ -162,26 +163,19 @@ void DialogInsertNode::ChosenObject(quint32 id, const SceneObject &type)
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::CheckState()
{
SCASSERT(bOk != nullptr);
bOk->setEnabled(m_flagItem && flagError);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::CheckPieces()
{
QColor color = okColor;
QColor color;
if (ui->comboBoxPiece->count() <= 0 || ui->comboBoxPiece->currentIndex() == -1)
{
flagError = false;
m_flagError = false;
color = errorColor;
}
else
{
flagError = true;
color = okColor;
m_flagError = true;
color = OkColor(this);
}
ChangeColor(ui->labelPiece, color);
CheckState();
@ -190,8 +184,8 @@ void DialogInsertNode::CheckPieces()
//---------------------------------------------------------------------------------------------------------------------
void DialogInsertNode::CheckItem()
{
QColor color = okColor;
m_flagItem ? color = okColor : color = errorColor;
QColor color;
m_flagItem ? color = OkColor(this) : color = errorColor;
ChangeColor(ui->labelItem, color);
CheckState();
}

View File

@ -57,7 +57,7 @@ public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
protected:
virtual void CheckState() final;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogInsertNode)
@ -65,9 +65,16 @@ private:
VPieceNode m_node;
bool m_flagItem;
bool m_flagError;
void CheckPieces();
void CheckItem();
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogInsertNode::IsValid() const
{
return m_flagItem && m_flagError;
}
#endif // DIALOGINSERTNODE_H

View File

@ -68,7 +68,10 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget
m_formulaBaseVisible(0),
m_flagFormulaBefore(true),
m_flagFormulaAfter(true),
m_flagFormulaVisible(true)
m_flagFormulaVisible(true),
m_flagName(true),//We have default name of piece.
m_flagError(false),
m_flagFormula(false)
{
ui->setupUi(this);
InitOkCancel(ui);
@ -80,9 +83,7 @@ DialogPiecePath::DialogPiecePath(const VContainer *data, quint32 toolId, QWidget
EvalVisible();
flagName = true;//We have default name of piece.
flagError = PathIsValid();
CheckState();
m_flagError = PathIsValid();
vis = new VisToolPiecePath(data);
@ -219,7 +220,7 @@ void DialogPiecePath::CheckState()
SCASSERT(bOk != nullptr);
if (GetType() == PiecePathType::InternalPath)
{
flagFormula = true;
m_flagFormula = true;
m_flagFormulaBefore = true;
m_flagFormulaAfter = true;
}
@ -228,17 +229,16 @@ void DialogPiecePath::CheckState()
m_flagFormulaVisible = true; // Works only for internal paths
if (not m_showMode)
{
flagFormula = true;
m_flagFormula = true;
m_flagFormulaBefore = true;
m_flagFormulaAfter = true;
}
}
bOk->setEnabled(flagName && flagError && flagFormula && m_flagFormulaBefore && m_flagFormulaAfter
&& m_flagFormulaVisible);
bOk->setEnabled(IsValid());
const int tabSeamAllowanceIndex = ui->tabWidget->indexOf(ui->tabSeamAllowance);
if (flagFormula && m_flagFormulaBefore && m_flagFormulaAfter)
if (m_flagFormula && m_flagFormulaBefore && m_flagFormulaAfter)
{
ui->tabWidget->setTabIcon(tabSeamAllowanceIndex, QIcon());
}
@ -391,13 +391,13 @@ void DialogPiecePath::NameChanged()
{
if (ui->lineEditName->text().isEmpty())
{
flagName = false;
ChangeColor(ui->labelName, Qt::red);
m_flagName = false;
ChangeColor(ui->labelName, errorColor);
}
else
{
flagName = true;
ChangeColor(ui->labelName, okColor);
m_flagName = true;
ChangeColor(ui->labelName, OkColor(this));
}
CheckState();
}
@ -736,10 +736,16 @@ void DialogPiecePath::PassmarkShowSecondChanged(int state)
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::EvalWidth()
{
labelEditFormula = ui->labelEditWidth;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const QString formula = ui->plainTextEditFormulaWidth->toPlainText();
m_saWidth = Eval(formula, flagFormula, ui->labelResultWidth, postfix, false, true);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormulaWidth->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditWidth;
formulaData.labelResult = ui->labelResultWidth;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
m_saWidth = Eval(formulaData, m_flagFormula);
if (m_saWidth >= 0)
{
@ -759,14 +765,18 @@ void DialogPiecePath::EvalWidth()
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::EvalWidthBefore()
{
labelEditFormula = ui->labelEditBefore;
if (ui->comboBoxNodes->count() > 0)
{
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
QString formula = ui->plainTextEditFormulaWidthBefore->toPlainText();
Eval(formula, m_flagFormulaBefore, ui->labelResultBefore, postfix, false, true);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormulaWidthBefore->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditBefore;
formulaData.labelResult = ui->labelResultBefore;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
formula = GetFormulaSAWidthBefore();
const QString formula = GetFormulaSAWidthBefore();
if (formula != currentSeamAllowance)
{
ui->pushButtonDefBefore->setEnabled(true);
@ -776,7 +786,7 @@ void DialogPiecePath::EvalWidthBefore()
}
else
{
ChangeColor(labelEditFormula, okColor);
ChangeColor(ui->labelEditBefore, OkColor(this));
ui->labelResultBefore->setText(tr("<Empty>"));
m_flagFormulaBefore = true;
}
@ -785,14 +795,18 @@ void DialogPiecePath::EvalWidthBefore()
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::EvalWidthAfter()
{
labelEditFormula = ui->labelEditAfter;
if (ui->comboBoxNodes->count() > 0)
{
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
QString formula = ui->plainTextEditFormulaWidthAfter->toPlainText();
Eval(formula, m_flagFormulaAfter, ui->labelResultAfter, postfix, false, true);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormulaWidthAfter->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditAfter;
formulaData.labelResult = ui->labelResultAfter;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
formula = GetFormulaSAWidthAfter();
const QString formula = GetFormulaSAWidthAfter();
if (formula != currentSeamAllowance)
{
ui->pushButtonDefAfter->setEnabled(true);
@ -802,7 +816,7 @@ void DialogPiecePath::EvalWidthAfter()
}
else
{
ChangeColor(labelEditFormula, okColor);
ChangeColor(ui->labelEditAfter, OkColor(this));
ui->labelResultAfter->setText(tr("<Empty>"));
m_flagFormulaAfter = true;
}
@ -811,9 +825,16 @@ void DialogPiecePath::EvalWidthAfter()
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::EvalVisible()
{
labelEditFormula = ui->labelEditVisible;
QString formula = ui->plainTextEditFormulaVisible->toPlainText();
Eval(formula, m_flagFormulaVisible, ui->labelResultVisible, QString(), false, true);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormulaVisible->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditVisible;
formulaData.labelResult = ui->labelResultVisible;
formulaData.postfix = QString();
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
Eval(formulaData, m_flagFormulaVisible);
}
//---------------------------------------------------------------------------------------------------------------------
@ -870,63 +891,28 @@ void DialogPiecePath::FXVisible()
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::WidthChanged()
{
labelEditFormula = ui->labelEditWidth;
labelResultCalculation = ui->labelResultWidth;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagFormula, ui->plainTextEditFormulaWidth, m_timerWidth, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::WidthBeforeChanged()
{
labelEditFormula = ui->labelEditBefore;
labelResultCalculation = ui->labelResultBefore;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(m_flagFormulaBefore, ui->plainTextEditFormulaWidthBefore, m_timerWidthBefore, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::WidthAfterChanged()
{
labelEditFormula = ui->labelEditAfter;
labelResultCalculation = ui->labelResultAfter;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(m_flagFormulaAfter, ui->plainTextEditFormulaWidthAfter, m_timerWidthAfter, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::VisibleChanged()
{
labelEditFormula = ui->labelEditVisible;
labelResultCalculation = ui->labelResultVisible;
ValFormulaChanged(m_flagFormulaVisible, ui->plainTextEditFormulaVisible, m_timerVisible, QString());
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::DeployWidthFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormulaWidth, ui->pushButtonGrowWidth, m_formulaBaseWidth);
DeployFormula(this, ui->plainTextEditFormulaWidth, ui->pushButtonGrowWidth, m_formulaBaseWidth);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::DeployWidthBeforeFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormulaWidthBefore, ui->pushButtonGrowWidthBefore, m_formulaBaseWidthBefore);
DeployFormula(this, ui->plainTextEditFormulaWidthBefore, ui->pushButtonGrowWidthBefore, m_formulaBaseWidthBefore);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::DeployWidthAfterFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormulaWidthAfter, ui->pushButtonGrowWidthAfter, m_formulaBaseWidthAfter);
DeployFormula(this, ui->plainTextEditFormulaWidthAfter, ui->pushButtonGrowWidthAfter, m_formulaBaseWidthAfter);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::DeployVisibleFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormulaVisible, ui->pushButtonGrowVisible, m_formulaBaseVisible);
DeployFormula(this, ui->plainTextEditFormulaVisible, ui->pushButtonGrowVisible, m_formulaBaseVisible);
}
//---------------------------------------------------------------------------------------------------------------------
@ -994,7 +980,6 @@ void DialogPiecePath::InitPathTab()
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::InitSeamAllowanceTab()
{
plainTextEditFormula = ui->plainTextEditFormulaWidth;
this->m_formulaBaseWidth = ui->plainTextEditFormulaWidth->height();
this->m_formulaBaseWidthBefore = ui->plainTextEditFormulaWidthBefore->height();
this->m_formulaBaseWidthAfter = ui->plainTextEditFormulaWidthAfter->height();
@ -1003,6 +988,10 @@ void DialogPiecePath::InitSeamAllowanceTab()
ui->plainTextEditFormulaWidthBefore->installEventFilter(this);
ui->plainTextEditFormulaWidthAfter->installEventFilter(this);
m_timerWidth->setSingleShot(true);
m_timerWidthBefore->setSingleShot(true);
m_timerWidthAfter->setSingleShot(true);
connect(m_timerWidth, &QTimer::timeout, this, &DialogPiecePath::EvalWidth);
connect(m_timerWidthBefore, &QTimer::timeout, this, &DialogPiecePath::EvalWidthBefore);
connect(m_timerWidthAfter, &QTimer::timeout, this, &DialogPiecePath::EvalWidthAfter);
@ -1026,11 +1015,20 @@ void DialogPiecePath::InitSeamAllowanceTab()
connect(ui->toolButtonExprBefore, &QPushButton::clicked, this, &DialogPiecePath::FXWidthBefore);
connect(ui->toolButtonExprAfter, &QPushButton::clicked, this, &DialogPiecePath::FXWidthAfter);
connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, &DialogPiecePath::WidthChanged);
connect(ui->plainTextEditFormulaWidthBefore, &QPlainTextEdit::textChanged, this,
&DialogPiecePath::WidthBeforeChanged);
connect(ui->plainTextEditFormulaWidthAfter, &QPlainTextEdit::textChanged, this,
&DialogPiecePath::WidthAfterChanged);
connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, [this]()
{
m_timerWidth->start(formulaTimerTimeout);
});
connect(ui->plainTextEditFormulaWidthBefore, &QPlainTextEdit::textChanged, this, [this]()
{
m_timerWidthBefore->start(formulaTimerTimeout);
});
connect(ui->plainTextEditFormulaWidthAfter, &QPlainTextEdit::textChanged, this, [this]()
{
m_timerWidthAfter->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowWidth, &QPushButton::clicked, this, &DialogPiecePath::DeployWidthFormulaTextEdit);
connect(ui->pushButtonGrowWidthBefore, &QPushButton::clicked,
@ -1061,9 +1059,14 @@ void DialogPiecePath::InitControlTab()
ui->plainTextEditFormulaVisible->installEventFilter(this);
m_timerVisible->setSingleShot(true);
connect(m_timerVisible, &QTimer::timeout, this, &DialogPiecePath::EvalVisible);
connect(ui->toolButtonExprVisible, &QPushButton::clicked, this, &DialogPiecePath::FXVisible);
connect(ui->plainTextEditFormulaVisible, &QPlainTextEdit::textChanged, this, &DialogPiecePath::VisibleChanged);
connect(ui->plainTextEditFormulaVisible, &QPlainTextEdit::textChanged, this, [this]()
{
m_timerVisible->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowVisible, &QPushButton::clicked, this,
&DialogPiecePath::DeployVisibleFormulaTextEdit);
}
@ -1492,7 +1495,7 @@ bool DialogPiecePath::PathIsValid() const
//---------------------------------------------------------------------------------------------------------------------
void DialogPiecePath::ValidObjects(bool value)
{
flagError = value;
m_flagError = value;
CheckState();
}

View File

@ -65,6 +65,7 @@ protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private slots:
void ShowContextMenu(const QPoint &pos);
@ -88,11 +89,6 @@ private slots:
void FXWidthAfter();
void FXVisible();
void WidthChanged();
void WidthBeforeChanged();
void WidthAfterChanged();
void VisibleChanged();
void DeployWidthFormulaTextEdit();
void DeployWidthBeforeFormulaTextEdit();
void DeployWidthAfterFormulaTextEdit();
@ -119,6 +115,9 @@ private:
bool m_flagFormulaBefore;
bool m_flagFormulaAfter;
bool m_flagFormulaVisible;
bool m_flagName;
bool m_flagError;
bool m_flagFormula;
void InitPathTab();
void InitSeamAllowanceTab();
@ -165,6 +164,14 @@ private:
void RefreshPathList(const VPiecePath &path);
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPiecePath::IsValid() const
{
return m_flagName && m_flagError && m_flagFormula && m_flagFormulaBefore && m_flagFormulaAfter
&& m_flagFormulaVisible;
}
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPiecePath::IsShowNotch() const
{
return m_showMode && GetType() == PiecePathType::CustomSeamAllowance;

View File

@ -36,16 +36,14 @@ DialogPin::DialogPin(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPin),
m_showMode(false),
m_flagPoint(false)
m_flagPoint(false),
m_flagError(false)
{
ui->setupUi(this);
InitOkCancel(ui);
FillComboBoxPoints(ui->comboBoxPoint);
flagError = false;
CheckState();
connect(ui->comboBoxPiece, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
{
CheckPieces();
@ -143,13 +141,6 @@ void DialogPin::ChosenObject(quint32 id, const SceneObject &type)
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPin::CheckState()
{
SCASSERT(bOk != nullptr);
bOk->setEnabled(m_flagPoint && flagError);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPin::ShowVisualization()
{
@ -161,16 +152,16 @@ void DialogPin::CheckPieces()
{
if (not m_showMode)
{
QColor color = okColor;
QColor color;
if (ui->comboBoxPiece->count() <= 0 || ui->comboBoxPiece->currentIndex() == -1)
{
flagError = false;
m_flagError = false;
color = errorColor;
}
else
{
flagError = true;
color = okColor;
m_flagError = true;
color = OkColor(this);
}
ChangeColor(ui->labelPiece, color);
CheckState();
@ -180,11 +171,11 @@ void DialogPin::CheckPieces()
//---------------------------------------------------------------------------------------------------------------------
void DialogPin::CheckPoint()
{
QColor color = okColor;
QColor color;
if (ui->comboBoxPoint->currentIndex() != -1)
{
m_flagPoint = true;
color = okColor;
color = OkColor(this);
}
else
{

View File

@ -57,17 +57,24 @@ public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
virtual bool IsValid() const final;
private:
Q_DISABLE_COPY(DialogPin)
Ui::DialogPin *ui;
bool m_showMode;
bool m_flagPoint;
bool m_showMode;
bool m_flagPoint;
bool m_flagError;
void CheckPieces();
void CheckPoint();
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPin::IsValid() const
{
return m_flagPoint && m_flagError;
}
#endif // DIALOGPIN_H

View File

@ -41,11 +41,6 @@ DialogPlaceLabel::DialogPlaceLabel(const VContainer *data, quint32 toolId, QWidg
: DialogTool(data, toolId, parent),
ui(new Ui::DialogPlaceLabel),
m_showMode(false),
m_flagPoint(false),
m_flagWidth(false),
m_flagHeight(false),
m_flagAngle(false),
m_flagFormulaVisible(false),
m_formulaBaseHeightWidth(0),
m_formulaBaseHeightHeight(0),
m_formulaBaseHeightAngle(0),
@ -53,7 +48,13 @@ DialogPlaceLabel::DialogPlaceLabel(const VContainer *data, quint32 toolId, QWidg
timerAngle(new QTimer(this)),
timerWidth(new QTimer(this)),
timerHeight(new QTimer(this)),
m_timerVisible(new QTimer(this))
m_timerVisible(new QTimer(this)),
m_flagPoint(false),
m_flagWidth(false),
m_flagHeight(false),
m_flagAngle(false),
m_flagFormulaVisible(false),
m_flagError(false)
{
ui->setupUi(this);
InitOkCancel(ui);
@ -63,9 +64,6 @@ DialogPlaceLabel::DialogPlaceLabel(const VContainer *data, quint32 toolId, QWidg
EvalVisible();
flagError = false;
CheckState();
connect(ui->comboBoxPiece, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]()
{
CheckPieces();
@ -255,9 +253,9 @@ void DialogPlaceLabel::ChosenObject(quint32 id, const SceneObject &type)
CheckPoint();
prepare = true;
FormulaWidthChanged();
FormulaHeightChanged();
FormulaAngleChanged();
timerWidth->setSingleShot(formulaTimerTimeout);
timerHeight->setSingleShot(formulaTimerTimeout);
timerAngle->setSingleShot(formulaTimerTimeout);
this->setModal(true);
this->show();
@ -266,13 +264,6 @@ void DialogPlaceLabel::ChosenObject(quint32 id, const SceneObject &type)
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::CheckState()
{
SCASSERT(bOk != nullptr);
bOk->setEnabled(m_flagPoint && flagError && m_flagWidth && m_flagHeight && m_flagAngle && m_flagFormulaVisible);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::ShowVisualization()
{
@ -295,93 +286,82 @@ void DialogPlaceLabel::closeEvent(QCloseEvent *event)
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::DeployFormulaWidthEdit()
{
DeployFormula(ui->plainTextEditFormulaWidth, ui->pushButtonGrowWidth, m_formulaBaseHeightWidth);
DeployFormula(this, ui->plainTextEditFormulaWidth, ui->pushButtonGrowWidth, m_formulaBaseHeightWidth);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::DeployFormulaHeightEdit()
{
DeployFormula(ui->plainTextEditFormulaHeight, ui->pushButtonGrowHeight, m_formulaBaseHeightHeight);
DeployFormula(this, ui->plainTextEditFormulaHeight, ui->pushButtonGrowHeight, m_formulaBaseHeightHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::DeployFormulaAngleEdit()
{
DeployFormula(ui->plainTextEditFormulaAngle, ui->pushButtonGrowAngle, m_formulaBaseHeightAngle);
DeployFormula(this, ui->plainTextEditFormulaAngle, ui->pushButtonGrowAngle, m_formulaBaseHeightAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::DeployVisibleFormulaTextEdit()
{
DeployFormula(ui->plainTextEditFormulaVisible, ui->pushButtonGrowVisible, m_formulaBaseVisible);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::FormulaWidthChanged()
{
labelEditFormula = ui->labelEditFormulaWidth;
labelResultCalculation = ui->labelResultCalculationWidth;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(m_flagWidth, ui->plainTextEditFormulaWidth, timerWidth, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::FormulaHeightChanged()
{
labelEditFormula = ui->labelEditFormulaHeight;
labelResultCalculation = ui->labelResultCalculationHeight;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(m_flagHeight, ui->plainTextEditFormulaHeight, timerHeight, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::FormulaAngleChanged()
{
labelEditFormula = ui->labelEditFormulaAngle;
labelResultCalculation = ui->labelResultCalculationAngle;
ValFormulaChanged(m_flagAngle, ui->plainTextEditFormulaAngle, timerAngle, degreeSymbol);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::VisibleChanged()
{
labelEditFormula = ui->labelEditVisible;
labelResultCalculation = ui->labelResultVisible;
ValFormulaChanged(m_flagFormulaVisible, ui->plainTextEditFormulaVisible, m_timerVisible, QString());
DeployFormula(this, ui->plainTextEditFormulaVisible, ui->pushButtonGrowVisible, m_formulaBaseVisible);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::EvalWidth()
{
labelEditFormula = ui->labelEditFormulaWidth;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
Eval(ui->plainTextEditFormulaWidth->toPlainText(), m_flagWidth, ui->labelResultCalculationWidth, postfix, true,
true);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormulaWidth->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormulaWidth;
formulaData.labelResult = ui->labelResultCalculationWidth;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkLessThanZero = true;
Eval(formulaData, m_flagWidth);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::EvalHeight()
{
labelEditFormula = ui->labelEditFormulaHeight;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
Eval(ui->plainTextEditFormulaHeight->toPlainText(), m_flagHeight, ui->labelResultCalculationHeight, postfix, true,
true);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormulaHeight->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormulaHeight;
formulaData.labelResult = ui->labelResultCalculationHeight;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkLessThanZero = true;
Eval(formulaData, m_flagHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::EvalAngle()
{
labelEditFormula = ui->labelEditFormulaAngle;
Eval(ui->plainTextEditFormulaAngle->toPlainText(), m_flagAngle, ui->labelResultCalculationAngle, degreeSymbol,
false);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormulaAngle->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditFormulaAngle;
formulaData.labelResult = ui->labelResultCalculationAngle;
formulaData.postfix = degreeSymbol;
formulaData.checkZero = false;
Eval(formulaData, m_flagAngle);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::EvalVisible()
{
labelEditFormula = ui->labelEditVisible;
QString formula = ui->plainTextEditFormulaVisible->toPlainText();
Eval(formula, m_flagFormulaVisible, ui->labelResultVisible, QString(), false, true);
FormulaData formulaData;
formulaData.formula = ui->plainTextEditFormulaVisible->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = ui->labelEditVisible;
formulaData.labelResult = ui->labelResultVisible;
formulaData.postfix = QString();
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
Eval(formulaData, m_flagFormulaVisible);
}
//---------------------------------------------------------------------------------------------------------------------
@ -456,15 +436,29 @@ void DialogPlaceLabel::InitPlaceLabelTab()
connect(ui->toolButtonExprHeight, &QPushButton::clicked, this, &DialogPlaceLabel::FXHeight);
connect(ui->toolButtonExprAngle, &QPushButton::clicked, this, &DialogPlaceLabel::FXAngle);
connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::FormulaWidthChanged);
connect(ui->plainTextEditFormulaHeight, &QPlainTextEdit::textChanged, this,
&DialogPlaceLabel::FormulaHeightChanged);
connect(ui->plainTextEditFormulaAngle, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::FormulaAngleChanged);
connect(ui->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, [this]()
{
timerWidth->start(formulaTimerTimeout);
});
connect(ui->plainTextEditFormulaHeight, &QPlainTextEdit::textChanged, this, [this]()
{
timerHeight->start(formulaTimerTimeout);
});
connect(ui->plainTextEditFormulaAngle, &QPlainTextEdit::textChanged, this, [this]()
{
timerAngle->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowWidth, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaWidthEdit);
connect(ui->pushButtonGrowHeight, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaHeightEdit);
connect(ui->pushButtonGrowAngle, &QPushButton::clicked, this, &DialogPlaceLabel::DeployFormulaAngleEdit);
timerWidth->setSingleShot(true);
timerHeight->setSingleShot(true);
timerAngle->setSingleShot(true);
connect(timerWidth, &QTimer::timeout, this, &DialogPlaceLabel::EvalWidth);
connect(timerHeight, &QTimer::timeout, this, &DialogPlaceLabel::EvalHeight);
connect(timerAngle, &QTimer::timeout, this, &DialogPlaceLabel::EvalAngle);
@ -477,9 +471,14 @@ void DialogPlaceLabel::InitControlTab()
ui->plainTextEditFormulaVisible->installEventFilter(this);
m_timerVisible->setSingleShot(true);
connect(m_timerVisible, &QTimer::timeout, this, &DialogPlaceLabel::EvalVisible);
connect(ui->toolButtonExprVisible, &QPushButton::clicked, this, &DialogPlaceLabel::FXVisible);
connect(ui->plainTextEditFormulaVisible, &QPlainTextEdit::textChanged, this, &DialogPlaceLabel::VisibleChanged);
connect(ui->plainTextEditFormulaVisible, &QPlainTextEdit::textChanged, this, [this]()
{
m_timerVisible->start(formulaTimerTimeout);
});
connect(ui->pushButtonGrowVisible, &QPushButton::clicked, this,
&DialogPlaceLabel::DeployVisibleFormulaTextEdit);
}
@ -503,16 +502,16 @@ void DialogPlaceLabel::CheckPieces()
{
if (not m_showMode)
{
QColor color = okColor;
QColor color;
if (ui->comboBoxPiece->count() <= 0 || ui->comboBoxPiece->currentIndex() == -1)
{
flagError = false;
m_flagError = false;
color = errorColor;
}
else
{
flagError = true;
color = okColor;
m_flagError = true;
color = OkColor(this);
}
ChangeColor(ui->labelPiece, color);
CheckState();
@ -522,11 +521,11 @@ void DialogPlaceLabel::CheckPieces()
//---------------------------------------------------------------------------------------------------------------------
void DialogPlaceLabel::CheckPoint()
{
QColor color = okColor;
QColor color;
if (ui->comboBoxPoint->currentIndex() != -1)
{
m_flagPoint = true;
color = okColor;
color = OkColor(this);
}
else
{

View File

@ -74,9 +74,9 @@ public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
protected:
virtual void CheckState() final;
virtual void ShowVisualization() override;
virtual void closeEvent(QCloseEvent *event) override;
virtual bool IsValid() const final;
private slots:
void DeployFormulaWidthEdit();
@ -84,11 +84,6 @@ private slots:
void DeployFormulaAngleEdit();
void DeployVisibleFormulaTextEdit();
void FormulaWidthChanged();
void FormulaHeightChanged();
void FormulaAngleChanged();
void VisibleChanged();
void EvalWidth();
void EvalHeight();
void EvalAngle();
@ -103,11 +98,6 @@ private:
Q_DISABLE_COPY(DialogPlaceLabel)
Ui::DialogPlaceLabel *ui;
bool m_showMode;
bool m_flagPoint;
bool m_flagWidth;
bool m_flagHeight;
bool m_flagAngle;
bool m_flagFormulaVisible;
/** @brief formulaBaseHeight base height defined by dialogui */
int m_formulaBaseHeightWidth;
@ -120,6 +110,13 @@ private:
QTimer *timerHeight;
QTimer *m_timerVisible;
bool m_flagPoint;
bool m_flagWidth;
bool m_flagHeight;
bool m_flagAngle;
bool m_flagFormulaVisible;
bool m_flagError;
void InitPlaceLabelTab();
void InitControlTab();
@ -129,4 +126,10 @@ private:
void CheckPoint();
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogPlaceLabel::IsValid() const
{
return m_flagPoint && m_flagError && m_flagWidth && m_flagHeight && m_flagAngle && m_flagFormulaVisible;
}
#endif // DIALOGPLACELABEL_H

View File

@ -48,6 +48,7 @@
#include "../../support/dialogeditlabel.h"
#include "../../../tools/vtoolseamallowance.h"
#include "../vgeometry/vplacelabelitem.h"
#include "../../dialogtoolbox.h"
#include <QMenu>
#include <QTimer>
@ -77,7 +78,7 @@ QString GetFormulaFromUser(QPlainTextEdit *textEdit)
}
//---------------------------------------------------------------------------------------------------------------------
DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const VAbstractPattern *doc, const quint32 &toolId,
DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const VAbstractPattern *doc, quint32 toolId,
QWidget *parent)
: DialogSeamAllowance(data, toolId, parent)
{
@ -86,7 +87,7 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const VAbstract
}
//---------------------------------------------------------------------------------------------------------------------
DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &toolId, QWidget *parent)
DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, quint32 toolId, QWidget *parent)
: DialogTool(data, toolId, parent),
ui(new Ui::DialogSeamAllowance),
uiTabPaths(new Ui::TabPaths),
@ -114,6 +115,8 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &
flagFormulaBefore(true),
flagFormulaAfter(true),
flagMainPathIsValid(true),
flagName(true), //We have default name of piece.
flagFormula(false),
m_bAddMode(true),
m_dialog(),
m_visSpecialPoints(),
@ -128,9 +131,9 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &
m_formulaBaseWidth(0),
m_formulaBaseWidthBefore(0),
m_formulaBaseWidthAfter(0),
m_timerWidth(nullptr),
m_timerWidthBefore(nullptr),
m_timerWidthAfter(nullptr),
m_timerWidth(new QTimer(this)),
m_timerWidthBefore(new QTimer(this)),
m_timerWidthAfter(new QTimer(this)),
m_saWidth(0),
m_templateLines(),
m_undoStack(),
@ -153,10 +156,8 @@ DialogSeamAllowance::DialogSeamAllowance(const VContainer *data, const quint32 &
InitPassmarksTab();
InitPlaceLabelsTab();
flagName = true;//We have default name of piece.
ChangeColor(uiTabPaths->labelEditName, okColor);
ChangeColor(uiTabPaths->labelEditName, OkColor(this));
flagMainPathIsValid = MainPathIsValid();
CheckState();
m_ftb->SetCurrentIndex(TabOrder::Paths);// Show always first tab active on start.
}
@ -177,6 +178,14 @@ DialogSeamAllowance::~DialogSeamAllowance()
delete uiTabLabels;
delete uiTabPaths;
delete ui;
for (auto &command : m_undoStack)
{
if (not command.isNull())
{
delete command;
}
}
}
//---------------------------------------------------------------------------------------------------------------------
@ -308,8 +317,8 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece)
uiTabPaths->checkBoxBuiltIn->setChecked(piece.IsSeamAllowanceBuiltIn());
uiTabPaths->lineEditName->setText(piece.GetName());
const QString width = qApp->TrVars()->FormulaToUser(piece.GetFormulaSAWidth(), qApp->Settings()->GetOsSeparator());
uiTabPaths->plainTextEditFormulaWidth->setPlainText(width);
uiTabPaths->plainTextEditFormulaWidth->setPlainText(
qApp->TrVars()->FormulaToUser(piece.GetFormulaSAWidth(), qApp->Settings()->GetOsSeparator()));
m_saWidth = piece.GetSAWidth();
const VPieceLabelData &ppData = piece.GetPatternPieceData();
@ -471,9 +480,7 @@ void DialogSeamAllowance::SaveData()
void DialogSeamAllowance::CheckState()
{
SCASSERT(bOk != nullptr);
bOk->setEnabled(flagName && flagMainPathIsValid && flagFormula && flagFormulaBefore && flagFormulaAfter
&& (flagGFormulas || flagGPin) && flagDLAngle && (flagDLFormulas || flagDPin) && flagPLAngle
&& (flagPLFormulas || flagPPin));
bOk->setEnabled(IsValid());
// In case dialog hasn't apply button
if ( bApply != nullptr && applyAllowed)
{
@ -581,12 +588,12 @@ void DialogSeamAllowance::NameDetailChanged()
if (edit->text().isEmpty())
{
flagName = false;
ChangeColor(uiTabPaths->labelEditName, Qt::red);
ChangeColor(uiTabPaths->labelEditName, errorColor);
}
else
{
flagName = true;
ChangeColor(uiTabPaths->labelEditName, okColor);
ChangeColor(uiTabPaths->labelEditName, OkColor(this));
}
}
CheckState();
@ -811,9 +818,9 @@ void DialogSeamAllowance::ShowPlaceLabelsContextMenu(const QPoint &pos)
newLabel.SetLabelType(type);
m_newPlaceLabels.insert(labelId, newLabel);
SavePlaceLabelOptions *saveCommand = new SavePlaceLabelOptions(toolId, currentLabel, newLabel,
qApp->getCurrentDocument(),
const_cast<VContainer *>(data), labelId);
QPointer<VUndoCommand> saveCommand =
new SavePlaceLabelOptions(toolId, currentLabel, newLabel, qApp->getCurrentDocument(),
const_cast<VContainer *>(data), labelId);
m_undoStack.append(saveCommand);
UpdateCurrentPlaceLabelRecords();
};
@ -1270,10 +1277,9 @@ void DialogSeamAllowance::PathDialogClosed(int result)
VPiecePath newPath = dialogTool->GetPiecePath();
m_newPaths.insert(dialogTool->GetToolId(), newPath);
SavePiecePathOptions *saveCommand = new SavePiecePathOptions(toolId, currentPath, newPath,
qApp->getCurrentDocument(),
const_cast<VContainer *>(data),
dialogTool->GetToolId());
QPointer<VUndoCommand> saveCommand =
new SavePiecePathOptions(toolId, currentPath, newPath, qApp->getCurrentDocument(),
const_cast<VContainer *>(data), dialogTool->GetToolId());
m_undoStack.append(saveCommand);
UpdateCurrentCustomSARecord();
UpdateCurrentInternalPathRecord();
@ -1323,10 +1329,9 @@ void DialogSeamAllowance::PlaceLabelDialogClosed(int result)
m_newPlaceLabels.insert(dialogTool->GetToolId(), newLabel);
SavePlaceLabelOptions *saveCommand = new SavePlaceLabelOptions(toolId, currentLabel, newLabel,
qApp->getCurrentDocument(),
const_cast<VContainer *>(data),
dialogTool->GetToolId());
QPointer<VUndoCommand> saveCommand =
new SavePlaceLabelOptions(toolId, currentLabel, newLabel, qApp->getCurrentDocument(),
const_cast<VContainer *>(data), dialogTool->GetToolId());
m_undoStack.append(saveCommand);
UpdateCurrentPlaceLabelRecords();
}
@ -1576,13 +1581,13 @@ void DialogSeamAllowance::UpdateGrainlineValues()
else
{
qsVal.setNum(dVal, 'f', 2);
ChangeColor(plbText, okColor);
ChangeColor(plbText, OkColor(this));
}
}
catch (qmu::QmuParserError &e)
{
qsVal = tr("Error");
not flagGPin ? ChangeColor(plbText, Qt::red) : ChangeColor(plbText, okColor);
not flagGPin ? ChangeColor(plbText, errorColor) : ChangeColor(plbText, OkColor(this));
bFormulasOK[i] = false;
plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
}
@ -1658,13 +1663,13 @@ void DialogSeamAllowance::UpdateDetailLabelValues()
else
{
qsVal.setNum(dVal, 'f', 2);
ChangeColor(plbText, okColor);
ChangeColor(plbText, OkColor(this));
}
}
catch (qmu::QmuParserError &e)
{
qsVal = tr("Error");
not flagDPin ? ChangeColor(plbText, Qt::red) : ChangeColor(plbText, okColor);
not flagDPin ? ChangeColor(plbText, errorColor) : ChangeColor(plbText, OkColor(this));
bFormulasOK[i] = false;
plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
}
@ -1743,13 +1748,13 @@ void DialogSeamAllowance::UpdatePatternLabelValues()
else
{
qsVal.setNum(dVal, 'f', 2);
ChangeColor(plbText, okColor);
ChangeColor(plbText, OkColor(this));
}
}
catch (qmu::QmuParserError &e)
{
qsVal = tr("Error");
not flagPPin ? ChangeColor(plbText, Qt::red) : ChangeColor(plbText, okColor);
not flagPPin ? ChangeColor(plbText, errorColor) : ChangeColor(plbText, OkColor(this));
bFormulasOK[i] = false;
plbVal->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
}
@ -1997,49 +2002,51 @@ void DialogSeamAllowance::EditPLFormula()
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployGrainlineRotation()
{
DeployFormula(uiTabGrainline->lineEditRotFormula, uiTabGrainline->pushButtonShowRot, m_iRotBaseHeight);
DeployFormula(this, uiTabGrainline->lineEditRotFormula, uiTabGrainline->pushButtonShowRot, m_iRotBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployGrainlineLength()
{
DeployFormula(uiTabGrainline->lineEditLenFormula, uiTabGrainline->pushButtonShowLen, m_iLenBaseHeight);
DeployFormula(this,uiTabGrainline->lineEditLenFormula, uiTabGrainline->pushButtonShowLen, m_iLenBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployDLWidth()
{
DeployFormula(uiTabLabels->lineEditDLWidthFormula, uiTabLabels->pushButtonShowDLWidth, m_DLWidthBaseHeight);
DeployFormula(this, uiTabLabels->lineEditDLWidthFormula, uiTabLabels->pushButtonShowDLWidth, m_DLWidthBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployDLHeight()
{
DeployFormula(uiTabLabels->lineEditDLHeightFormula, uiTabLabels->pushButtonShowDLHeight, m_DLHeightBaseHeight);
DeployFormula(this, uiTabLabels->lineEditDLHeightFormula, uiTabLabels->pushButtonShowDLHeight,
m_DLHeightBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployDLAngle()
{
DeployFormula(uiTabLabels->lineEditDLAngleFormula, uiTabLabels->pushButtonShowDLAngle, m_DLAngleBaseHeight);
DeployFormula(this, uiTabLabels->lineEditDLAngleFormula, uiTabLabels->pushButtonShowDLAngle, m_DLAngleBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployPLWidth()
{
DeployFormula(uiTabLabels->lineEditPLWidthFormula, uiTabLabels->pushButtonShowPLWidth, m_PLWidthBaseHeight);
DeployFormula(this, uiTabLabels->lineEditPLWidthFormula, uiTabLabels->pushButtonShowPLWidth, m_PLWidthBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployPLHeight()
{
DeployFormula(uiTabLabels->lineEditPLHeightFormula, uiTabLabels->pushButtonShowPLHeight, m_PLHeightBaseHeight);
DeployFormula(this, uiTabLabels->lineEditPLHeightFormula, uiTabLabels->pushButtonShowPLHeight,
m_PLHeightBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployPLAngle()
{
DeployFormula(uiTabLabels->lineEditPLAngleFormula, uiTabLabels->pushButtonShowPLAngle, m_PLAngleBaseHeight);
DeployFormula(this, uiTabLabels->lineEditPLAngleFormula, uiTabLabels->pushButtonShowPLAngle, m_PLAngleBaseHeight);
}
//---------------------------------------------------------------------------------------------------------------------
@ -2064,10 +2071,16 @@ void DialogSeamAllowance::ResetLabelsWarning()
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::EvalWidth()
{
labelEditFormula = uiTabPaths->labelEditWidth;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const QString formula = uiTabPaths->plainTextEditFormulaWidth->toPlainText();
m_saWidth = Eval(formula, flagFormula, uiTabPaths->labelResultWidth, postfix, false, true);
FormulaData formulaData;
formulaData.formula = uiTabPaths->plainTextEditFormulaWidth->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = uiTabPaths->labelEditWidth;
formulaData.labelResult = uiTabPaths->labelResultWidth;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
m_saWidth = Eval(formulaData, flagFormula);
if (m_saWidth >= 0)
{
@ -2089,12 +2102,18 @@ void DialogSeamAllowance::EvalWidthBefore()
{
if (uiTabPaths->checkBoxSeams->isChecked())
{
labelEditFormula = uiTabPaths->labelEditBefore;
if (uiTabPaths->comboBoxNodes->count() > 0)
{
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const QString formula = uiTabPaths->plainTextEditFormulaWidthBefore->toPlainText();
Eval(formula, flagFormulaBefore, uiTabPaths->labelResultBefore, postfix, false, true);
FormulaData formulaData;
formulaData.formula = uiTabPaths->plainTextEditFormulaWidthBefore->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = uiTabPaths->labelEditBefore;
formulaData.labelResult = uiTabPaths->labelResultBefore;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
Eval(formulaData, flagFormulaBefore);
const QString formulaSABefore = GetFormulaFromUser(uiTabPaths->plainTextEditFormulaWidthBefore);
UpdateNodeSABefore(formulaSABefore);
@ -2102,7 +2121,7 @@ void DialogSeamAllowance::EvalWidthBefore()
}
else
{
ChangeColor(labelEditFormula, okColor);
ChangeColor(uiTabPaths->labelEditBefore, OkColor(this));
uiTabPaths->labelResultBefore->setText(tr("<Empty>"));
flagFormulaBefore = true;
}
@ -2114,12 +2133,18 @@ void DialogSeamAllowance::EvalWidthAfter()
{
if (uiTabPaths->checkBoxSeams->isChecked())
{
labelEditFormula = uiTabPaths->labelEditAfter;
if (uiTabPaths->comboBoxNodes->count() > 0)
{
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
const QString formula = uiTabPaths->plainTextEditFormulaWidthAfter->toPlainText();
Eval(formula, flagFormulaAfter, uiTabPaths->labelResultAfter, postfix, false, true);
FormulaData formulaData;
formulaData.formula = uiTabPaths->plainTextEditFormulaWidthAfter->toPlainText();
formulaData.variables = data->DataVariables();
formulaData.labelEditFormula = uiTabPaths->labelEditAfter;
formulaData.labelResult = uiTabPaths->labelResultAfter;
formulaData.postfix = UnitsToStr(qApp->patternUnit(), true);
formulaData.checkZero = false;
formulaData.checkLessThanZero = true;
Eval(formulaData, flagFormulaAfter);
const QString formulaSAAfter = GetFormulaFromUser(uiTabPaths->plainTextEditFormulaWidthAfter);
UpdateNodeSAAfter(formulaSAAfter);
@ -2127,7 +2152,7 @@ void DialogSeamAllowance::EvalWidthAfter()
}
else
{
ChangeColor(labelEditFormula, okColor);
ChangeColor(uiTabPaths->labelEditAfter, OkColor(this));
uiTabPaths->labelResultAfter->setText(tr("<Empty>"));
flagFormulaAfter = true;
}
@ -2137,7 +2162,7 @@ void DialogSeamAllowance::EvalWidthAfter()
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::FXWidth()
{
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
QScopedPointer<DialogEditWrongFormula> dialog(new DialogEditWrongFormula(data, toolId, this));
dialog->setWindowTitle(tr("Edit seam allowance width"));
dialog->SetFormula(GetFormulaSAWidth());
dialog->setCheckLessThanZero(true);
@ -2146,13 +2171,12 @@ void DialogSeamAllowance::FXWidth()
{
SetFormulaSAWidth(dialog->GetFormula());
}
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::FXWidthBefore()
{
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
QScopedPointer<DialogEditWrongFormula> dialog(new DialogEditWrongFormula(data, toolId, this));
dialog->setWindowTitle(tr("Edit seam allowance width before"));
dialog->SetFormula(GetFormulaFromUser(uiTabPaths->plainTextEditFormulaWidthBefore));
dialog->setCheckLessThanZero(true);
@ -2161,13 +2185,12 @@ void DialogSeamAllowance::FXWidthBefore()
{
SetCurrentSABefore(dialog->GetFormula());
}
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::FXWidthAfter()
{
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, this);
QScopedPointer<DialogEditWrongFormula> dialog(new DialogEditWrongFormula(data, toolId, this));
dialog->setWindowTitle(tr("Edit seam allowance width after"));
dialog->SetFormula(GetFormulaFromUser(uiTabPaths->plainTextEditFormulaWidthAfter));
dialog->setCheckLessThanZero(true);
@ -2176,79 +2199,45 @@ void DialogSeamAllowance::FXWidthAfter()
{
SetCurrentSAAfter(dialog->GetFormula());
}
delete dialog;
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::WidthChanged()
{
labelEditFormula = uiTabPaths->labelEditWidth;
labelResultCalculation = uiTabPaths->labelResultWidth;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagFormula, uiTabPaths->plainTextEditFormulaWidth, m_timerWidth, postfix);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::WidthBeforeChanged()
{
if (uiTabPaths->checkBoxSeams->isChecked())
{
labelEditFormula = uiTabPaths->labelEditBefore;
labelResultCalculation = uiTabPaths->labelResultBefore;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagFormulaBefore, uiTabPaths->plainTextEditFormulaWidthBefore, m_timerWidthBefore, postfix);
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::WidthAfterChanged()
{
if (uiTabPaths->checkBoxSeams->isChecked())
{
labelEditFormula = uiTabPaths->labelEditAfter;
labelResultCalculation = uiTabPaths->labelResultAfter;
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
ValFormulaChanged(flagFormulaAfter, uiTabPaths->plainTextEditFormulaWidthAfter, m_timerWidthAfter, postfix);
}
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployWidthFormulaTextEdit()
{
DeployFormula(uiTabPaths->plainTextEditFormulaWidth, uiTabPaths->pushButtonGrowWidth, m_formulaBaseWidth);
DeployFormula(this, uiTabPaths->plainTextEditFormulaWidth, uiTabPaths->pushButtonGrowWidth, m_formulaBaseWidth);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployWidthBeforeFormulaTextEdit()
{
DeployFormula(uiTabPaths->plainTextEditFormulaWidthBefore, uiTabPaths->pushButtonGrowWidthBefore,
DeployFormula(this, uiTabPaths->plainTextEditFormulaWidthBefore, uiTabPaths->pushButtonGrowWidthBefore,
m_formulaBaseWidthBefore);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DeployWidthAfterFormulaTextEdit()
{
DeployFormula(uiTabPaths->plainTextEditFormulaWidthAfter, uiTabPaths->pushButtonGrowWidthAfter,
DeployFormula(this, uiTabPaths->plainTextEditFormulaWidthAfter, uiTabPaths->pushButtonGrowWidthAfter,
m_formulaBaseWidthAfter);
}
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::GrainlinePinPointChanged()
{
QColor color = okColor;
QColor color;
const quint32 topPinId = getCurrentObjectId(uiTabGrainline->comboBoxGrainlineTopPin);
const quint32 bottomPinId = getCurrentObjectId(uiTabGrainline->comboBoxGrainlineBottomPin);
if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)
{
flagGPin = true;
color = okColor;
color = OkColor(this);
ResetGrainlineWarning();
}
else
{
flagGPin = false;
topPinId == NULL_ID && bottomPinId == NULL_ID ? color = okColor : color = errorColor;
topPinId == NULL_ID && bottomPinId == NULL_ID ? color = OkColor(this) : color = errorColor;
if (not flagGFormulas && not flagGPin)
{
@ -2265,13 +2254,13 @@ void DialogSeamAllowance::GrainlinePinPointChanged()
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::DetailPinPointChanged()
{
QColor color = okColor;
QColor color;
const quint32 topPinId = getCurrentObjectId(uiTabLabels->comboBoxDLTopLeftPin);
const quint32 bottomPinId = getCurrentObjectId(uiTabLabels->comboBoxDLBottomRightPin);
if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)
{
flagDPin = true;
color = okColor;
color = OkColor(this);
if (flagPPin)
{
@ -2282,7 +2271,7 @@ void DialogSeamAllowance::DetailPinPointChanged()
else
{
flagDPin = false;
topPinId == NULL_ID && bottomPinId == NULL_ID ? color = okColor : color = errorColor;
topPinId == NULL_ID && bottomPinId == NULL_ID ? color = OkColor(this) : color = errorColor;
m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*');
const QIcon icon = QIcon::fromTheme("dialog-warning",
@ -2299,13 +2288,13 @@ void DialogSeamAllowance::DetailPinPointChanged()
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::PatternPinPointChanged()
{
QColor color = okColor;
QColor color;
const quint32 topPinId = getCurrentObjectId(uiTabLabels->comboBoxPLTopLeftPin);
const quint32 bottomPinId = getCurrentObjectId(uiTabLabels->comboBoxPLBottomRightPin);
if (topPinId != NULL_ID && bottomPinId != NULL_ID && topPinId != bottomPinId)
{
flagPPin = true;
color = okColor;
color = OkColor(this);
if (flagDPin)
{
@ -2316,7 +2305,7 @@ void DialogSeamAllowance::PatternPinPointChanged()
else
{
flagPPin = false;
topPinId == NULL_ID && bottomPinId == NULL_ID ? color = okColor : color = errorColor;
topPinId == NULL_ID && bottomPinId == NULL_ID ? color = OkColor(this) : color = errorColor;
m_ftb->SetTabText(TabOrder::Labels, tr("Labels") + '*');
const QIcon icon = QIcon::fromTheme("dialog-warning",
@ -2765,7 +2754,6 @@ void DialogSeamAllowance::InitMainPathTab()
//---------------------------------------------------------------------------------------------------------------------
void DialogSeamAllowance::InitSeamAllowanceTab()
{
plainTextEditFormula = uiTabPaths->plainTextEditFormulaWidth;
this->m_formulaBaseWidth = uiTabPaths->plainTextEditFormulaWidth->height();
this->m_formulaBaseWidthBefore = uiTabPaths->plainTextEditFormulaWidthBefore->height();
this->m_formulaBaseWidthAfter = uiTabPaths->plainTextEditFormulaWidthAfter->height();
@ -2774,13 +2762,13 @@ void DialogSeamAllowance::InitSeamAllowanceTab()
uiTabPaths->plainTextEditFormulaWidthBefore->installEventFilter(this);
uiTabPaths->plainTextEditFormulaWidthAfter->installEventFilter(this);
m_timerWidth = new QTimer(this);
m_timerWidth->setSingleShot(true);
connect(m_timerWidth, &QTimer::timeout, this, &DialogSeamAllowance::EvalWidth);
m_timerWidthBefore = new QTimer(this);
m_timerWidthBefore->setSingleShot(true);
connect(m_timerWidthBefore, &QTimer::timeout, this, &DialogSeamAllowance::EvalWidthBefore);
m_timerWidthAfter = new QTimer(this);
m_timerWidthAfter->setSingleShot(true);
connect(m_timerWidthAfter, &QTimer::timeout, this, &DialogSeamAllowance::EvalWidthAfter);
connect(uiTabPaths->checkBoxSeams, &QCheckBox::toggled, this, &DialogSeamAllowance::EnableSeamAllowance);
@ -2818,12 +2806,20 @@ void DialogSeamAllowance::InitSeamAllowanceTab()
connect(uiTabPaths->toolButtonExprBefore, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidthBefore);
connect(uiTabPaths->toolButtonExprAfter, &QPushButton::clicked, this, &DialogSeamAllowance::FXWidthAfter);
connect(uiTabPaths->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this,
&DialogSeamAllowance::WidthChanged);
connect(uiTabPaths->plainTextEditFormulaWidthBefore, &QPlainTextEdit::textChanged, this,
&DialogSeamAllowance::WidthBeforeChanged);
connect(uiTabPaths->plainTextEditFormulaWidthAfter, &QPlainTextEdit::textChanged, this,
&DialogSeamAllowance::WidthAfterChanged);
connect(uiTabPaths->plainTextEditFormulaWidth, &QPlainTextEdit::textChanged, this, [this]()
{
m_timerWidth->start(formulaTimerTimeout);
});
connect(uiTabPaths->plainTextEditFormulaWidthBefore, &QPlainTextEdit::textChanged, this, [this]()
{
m_timerWidthBefore->start(formulaTimerTimeout);
});
connect(uiTabPaths->plainTextEditFormulaWidthAfter, &QPlainTextEdit::textChanged, this, [this]()
{
m_timerWidthAfter->start(formulaTimerTimeout);
});
connect(uiTabPaths->pushButtonGrowWidth, &QPushButton::clicked, this,
&DialogSeamAllowance::DeployWidthFormulaTextEdit);
@ -3077,7 +3073,7 @@ QString DialogSeamAllowance::GetFormulaSAWidth() const
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QUndoCommand *> &DialogSeamAllowance::UndoStack()
QVector<QPointer<VUndoCommand>> &DialogSeamAllowance::UndoStack()
{
return m_undoStack;
}

View File

@ -49,16 +49,16 @@ namespace Ui
class VisPieceSpecialPoints;
class FancyTabBar;
class VPlaceLabelItem;
class QUndoCommand;
class VUndoCommand;
class DialogSeamAllowance : public DialogTool
{
Q_OBJECT
public:
DialogSeamAllowance(const VContainer *data, const VAbstractPattern *doc, const quint32 &toolId,
DialogSeamAllowance(const VContainer *data, const VAbstractPattern *doc, quint32 toolId,
QWidget *parent = nullptr);
DialogSeamAllowance(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
DialogSeamAllowance(const VContainer *data, quint32 toolId, QWidget *parent = nullptr);
virtual ~DialogSeamAllowance();
void EnableApply(bool enable);
@ -68,7 +68,7 @@ public:
QString GetFormulaSAWidth() const;
QVector<QUndoCommand*> &UndoStack();
QVector<QPointer<VUndoCommand> > &UndoStack();
public slots:
virtual void ChosenObject(quint32 id, const SceneObject &type) override;
@ -81,6 +81,7 @@ protected:
virtual void closeEvent(QCloseEvent *event) override;
virtual void showEvent( QShowEvent *event ) override;
virtual void resizeEvent(QResizeEvent *event) override;
virtual bool IsValid() const final;
private slots:
void NameDetailChanged();
@ -143,10 +144,6 @@ private slots:
void FXWidthBefore();
void FXWidthAfter();
void WidthChanged();
void WidthBeforeChanged();
void WidthAfterChanged();
void DeployWidthFormulaTextEdit();
void DeployWidthBeforeFormulaTextEdit();
void DeployWidthAfterFormulaTextEdit();
@ -190,6 +187,8 @@ private:
bool flagFormulaBefore;
bool flagFormulaAfter;
bool flagMainPathIsValid;
bool flagName;
bool flagFormula;
bool m_bAddMode;
QPointer<DialogTool> m_dialog;
@ -214,7 +213,7 @@ private:
QVector<VLabelTemplateLine> m_templateLines;
QVector<QUndoCommand*> m_undoStack;
QVector<QPointer<VUndoCommand>> m_undoStack;
QHash<quint32, VPlaceLabelItem> m_newPlaceLabels;
QHash<quint32, VPiecePath> m_newPaths;
@ -282,4 +281,12 @@ private:
void EnablePatternLabelFormulaControls(bool enable);
};
//---------------------------------------------------------------------------------------------------------------------
inline bool DialogSeamAllowance::IsValid() const
{
return flagName && flagMainPathIsValid && flagFormula && flagFormulaBefore && flagFormulaAfter
&& (flagGFormulas || flagGPin) && flagDLAngle && (flagDLFormulas || flagDPin) && flagPLAngle
&& (flagPLFormulas || flagPPin);
}
#endif // DIALOGSEAMALLOWANCE_H

View File

@ -101,7 +101,7 @@ VToolCutArc* VToolCutArc::Create(const QPointer<DialogTool> &dialog, VMainGraphi
VToolCutArcInitData initData;
initData.formula = dialogTool->GetFormula();
initData.arcId = dialogTool->getArcId();
initData.name = dialogTool->getPointName();
initData.name = dialogTool->GetPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
@ -205,7 +205,7 @@ void VToolCutArc::SaveDialog(QDomElement &domElement, QList<quint32> &oldDepende
AddDependence(oldDependencies, curveCutId);
AddDependence(newDependencies, dialogTool->getArcId());
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName());
doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula());
doc->SetAttribute(domElement, AttrArc, QString().setNum(dialogTool->getArcId()));
}
@ -283,5 +283,6 @@ QString VToolCutArc::MakeToolTip() const
return toolTip;
};
return ArcToolTip(ArcToolTip("<table>", ar1, QChar('1')), ar2, QChar('2')) + QLatin1String("</table>");
return ArcToolTip(ArcToolTip(QStringLiteral("<table>"), ar1, QChar('1')), ar2, QChar('2')) +
QStringLiteral("</table>");
}

View File

@ -104,7 +104,7 @@ VToolCutSpline* VToolCutSpline::Create(const QPointer<DialogTool> &dialog, VMain
VToolCutSplineInitData initData;
initData.formula = dialogTool->GetFormula();
initData.splineId = dialogTool->getSplineId();
initData.name = dialogTool->getPointName();
initData.name = dialogTool->GetPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
@ -204,7 +204,7 @@ void VToolCutSpline::SaveDialog(QDomElement &domElement, QList<quint32> &oldDepe
AddDependence(oldDependencies, curveCutId);
AddDependence(newDependencies, dialogTool->getSplineId());
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName());
doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula());
doc->SetAttribute(domElement, AttrSpline, QString().setNum(dialogTool->getSplineId()));
}

View File

@ -107,7 +107,7 @@ VToolCutSplinePath* VToolCutSplinePath::Create(const QPointer<DialogTool> &dialo
VToolCutSplinePathInitData initData;
initData.formula = dialogTool->GetFormula();
initData.splinePathId = dialogTool->getSplinePathId();
initData.name = dialogTool->getPointName();
initData.name = dialogTool->GetPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
@ -295,7 +295,7 @@ void VToolCutSplinePath::SaveDialog(QDomElement &domElement, QList<quint32> &old
AddDependence(oldDependencies, curveCutId);
AddDependence(newDependencies, dialogTool->getSplinePathId());
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName());
doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula());
doc->SetAttribute(domElement, AttrSplinePath, QString().setNum(dialogTool->getSplinePathId()));
}

View File

@ -99,7 +99,7 @@ void VToolAlongLine::SaveDialog(QDomElement &domElement, QList<quint32> &oldDepe
AddDependence(newDependencies, dialogTool->GetFirstPointId());
AddDependence(newDependencies, dialogTool->GetSecondPointId());
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName());
doc->SetAttribute(domElement, AttrTypeLine, dialogTool->GetTypeLine());
doc->SetAttribute(domElement, AttrLineColor, dialogTool->GetLineColor());
doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula());
@ -164,8 +164,8 @@ QString VToolAlongLine::MakeToolTip() const
.arg(qApp->fromPixel(curLine.length()))
.arg(UnitsToStr(qApp->patternUnit(), true), tr("Angle"))
.arg(curLine.angle())
.arg(QString("%1->%2").arg(basePoint->name(), current->name()),
QString("%1->%2").arg(current->name(), secondPoint->name()))
.arg(QStringLiteral("%1->%2").arg(basePoint->name(), current->name()),
QStringLiteral("%1->%2").arg(current->name(), secondPoint->name()))
.arg(qApp->fromPixel(curToSecond.length()))
.arg(tr("Label"), current->name());
return toolTip;
@ -230,7 +230,7 @@ VToolAlongLine* VToolAlongLine::Create(const QPointer<DialogTool> &dialog, VMain
initData.secondPointId = dialogTool->GetSecondPointId();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.name = dialogTool->GetPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;

View File

@ -146,7 +146,7 @@ VToolBisector* VToolBisector::Create(const QPointer<DialogTool> &dialog, VMainGr
initData.thirdPointId = dialogTool->GetThirdPointId();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.name = dialogTool->GetPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
@ -254,7 +254,7 @@ void VToolBisector::SaveDialog(QDomElement &domElement, QList<quint32> &oldDepen
AddDependence(newDependencies, dialogTool->GetSecondPointId());
AddDependence(newDependencies, dialogTool->GetThirdPointId());
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName());
doc->SetAttribute(domElement, AttrTypeLine, dialogTool->GetTypeLine());
doc->SetAttribute(domElement, AttrLineColor, dialogTool->GetLineColor());
doc->SetAttribute(domElement, AttrLength, dialogTool->GetFormula());

View File

@ -112,7 +112,7 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(const QPointer<DialogTo
initData.curveId = dialogTool->getCurveId();
initData.typeLine = dialogTool->GetTypeLine();
initData.lineColor = dialogTool->GetLineColor();
initData.name = dialogTool->getPointName();
initData.name = dialogTool->GetPointName();
initData.scene = scene;
initData.doc = doc;
initData.data = data;
@ -255,7 +255,7 @@ void VToolCurveIntersectAxis::SaveDialog(QDomElement &domElement, QList<quint32>
AddDependence(newDependencies, dialogTool->GetBasePointId());
AddDependence(newDependencies, dialogTool->getCurveId());
doc->SetAttribute(domElement, AttrName, dialogTool->getPointName());
doc->SetAttribute(domElement, AttrName, dialogTool->GetPointName());
doc->SetAttribute(domElement, AttrTypeLine, dialogTool->GetTypeLine());
doc->SetAttribute(domElement, AttrLineColor, dialogTool->GetLineColor());
doc->SetAttribute(domElement, AttrAngle, dialogTool->GetAngle());
@ -346,7 +346,7 @@ void VToolCurveIntersectAxis::InitArc(VContainer *data, qreal segLength, const V
//---------------------------------------------------------------------------------------------------------------------
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wswitch-default")
void VToolCurveIntersectAxis::InitSegments(const GOType &curveType, qreal segLength, const VPointF *p, quint32 curveId,
void VToolCurveIntersectAxis::InitSegments(GOType curveType, qreal segLength, const VPointF *p, quint32 curveId,
VContainer *data)
{
switch(curveType)

View File

@ -101,8 +101,7 @@ private:
template <class Item>
static void InitArc(VContainer *data, qreal segLength, const VPointF *p, quint32 curveId);
static void InitSegments(const GOType &curveType, qreal segLength, const VPointF *p, quint32 curveId,
VContainer *data);
static void InitSegments(GOType curveType, qreal segLength, const VPointF *p, quint32 curveId, VContainer *data);
};
#endif // VTOOLCURVEINTERSECTAXIS_H

Some files were not shown because too many files have changed in this diff Show More