57 #include "ui_edit_formula_dialog.h"
59 #include <qiterator.h>
60 #include <QAbstractItemView>
61 #include <QApplication>
66 #include <QHeaderView>
68 #include <QListWidget>
69 #include <QMapIterator>
70 #include <QPlainTextEdit>
71 #include <QPushButton>
72 #include <QSharedPointer>
74 #include <QGuiApplication>
77 #include <QTableWidget>
78 #include <QTableWidgetItem>
79 #include <QTextCursor>
80 #include <QToolButton>
85 #include "../ifc/xml/vdomdocument.h"
86 #include "../tools/dialogtool.h"
87 #include "../vmisc/def.h"
88 #include "../vmisc/vabstractapplication.h"
89 #include "../vmisc/vcommonsettings.h"
90 #include "../vpatterndb/vcontainer.h"
91 #include "../vpatterndb/vtranslatevars.h"
92 #include "../vpatterndb/variables/varcradius.h"
93 #include "../vpatterndb/variables/vcurveangle.h"
94 #include "../vpatterndb/variables/vcurvelength.h"
95 #include "../vpatterndb/variables/vincrement.h"
96 #include "../vpatterndb/variables/vlineangle.h"
97 #include "../vpatterndb/variables/vlinelength.h"
98 #include "../vpatterndb/variables/vmeasurement.h"
108 , m_formula(QString())
109 , m_undoFormula(QString())
111 , m_checkLessThanZero(false)
112 , m_postfix(QString())
113 , m_restoreCursor(false)
116 setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
120 ui->plainTextEditFormula->installEventFilter(
this);
137 if (QGuiApplication::overrideCursor() !=
nullptr)
139 if (QGuiApplication::overrideCursor()->shape() == Qt::WaitCursor)
142 QGuiApplication::restoreOverrideCursor();
147 ui->tableWidget->setColumnCount(2);
148 ui->tableWidget->setEditTriggers(QTableWidget::NoEditTriggers);
149 ui->tableWidget->verticalHeader()->hide();
150 ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
159 QGuiApplication::setOverrideCursor(Qt::WaitCursor);
168 m_formula =
ui->plainTextEditFormula->toPlainText();
197 if (
ui->tableWidget->rowCount() == 0)
199 ui->description_Label->setText(
"");
202 QTableWidgetItem *item =
ui->tableWidget->item( row,
ColumnName );
204 switch (
ui->menuTab_ListWidget->currentRow())
208 const QString name =
qApp->TrVars()->VarFromUser(item->text());
210 const QString desc = (
measurements->getGuiText() ==
"") ?
"" : QString(
"\nDescription: %1").arg(
measurements->getGuiText());
218 const QString desc =(variables->GetDescription() ==
"") ?
"" : QString(
"\nDescription: %1").arg(variables->GetDescription());
220 UnitsToStr(
qApp->patternUnit(),
true), tr(
"Custom Variable"), desc);
260 ui->description_Label->setText(item->toolTip());
343 QTextCursor cursor =
ui->plainTextEditFormula->textCursor();
346 if (cursor.hasSelection())
348 QString selected = cursor.selectedText();
349 cursor.insertText(
ui->tableWidget->item(item->row(),
ColumnName)->text() +
350 QStringLiteral(
"(") + selected + QStringLiteral(
")"));
351 cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
352 ui->plainTextEditFormula->setTextCursor(cursor);
356 cursor.insertText(
ui->tableWidget->item(item->row(),
ColumnName)->text() + QStringLiteral(
"()"));
357 cursor.setPosition(cursor.position() - 1);
362 cursor.insertText(
ui->tableWidget->item(item->row(),
ColumnName)->text());
364 ui->plainTextEditFormula->setTextCursor(cursor);
365 ui->plainTextEditFormula->setFocus();
375 ui->checkBoxHideEmpty->setEnabled(
true);
385 ui->checkBoxHideEmpty->setEnabled(
false);
395 ui->checkBoxHideEmpty->setEnabled(
false);
405 ui->checkBoxHideEmpty->setEnabled(
false);
415 ui->checkBoxHideEmpty->setEnabled(
false);
425 ui->checkBoxHideEmpty->setEnabled(
false);
435 ui->checkBoxHideEmpty->setEnabled(
false);
445 ui->checkBoxHideEmpty->setEnabled(
false);
455 ui->checkBoxHideEmpty->setEnabled(
false);
469 ui->plainTextEditFormula->blockSignals(
true);
476 QDialog::showEvent(event);
477 if (event->spontaneous())
488 const QSize size =
qApp->Settings()->GetFormulaWizardDialogSize();
494 QScreen *screen = QGuiApplication::primaryScreen();
495 QRect position = frameGeometry();
496 position.moveCenter(screen->availableGeometry().center());
497 move(position.topLeft());
509 qApp->Settings()->SetFormulaWizardDialogSize(size());
511 DialogTool::resizeEvent(event);
517 m_formula =
qApp->TrVars()->FormulaToUser(value,
qApp->Settings()->GetOsSeparator());
544 return qApp->TrVars()->TryFormulaFromUser(
m_formula,
qApp->Settings()->GetOsSeparator());
555 auto ClearFilterFormulaInputs = [
this] () {
ui->filterFormulaInputs->clear(); };
558 connect(
ui->menuTab_ListWidget, &QListWidget::currentRowChanged,
this, ClearFilterFormulaInputs);
562 for (
int i = 0; i <
ui->menuTab_ListWidget->count(); ++i)
564 ui->menuTab_ListWidget->item(i)->setSizeHint(QSize(
ui->menuTab_ListWidget->width(), 50));
570 const QString &type,
const QString &description)
572 const QString desc = QString(
"%5: %1(%2 %3)%4").arg(name).arg(value).arg(unit).arg(description).arg(type);
573 ui->description_Label->setText(desc);
581 template <
class key,
class val>
584 ui->tableWidget->blockSignals(
true);
585 ui->tableWidget->clearContents();
586 ui->tableWidget->setRowCount(0);
588 ui->description_Label->setText(
"");
590 QMapIterator<key, val> iMap(var);
591 while (iMap.hasNext())
594 if (
ui->checkBoxHideEmpty->isEnabled() &&
ui->checkBoxHideEmpty->isChecked() && iMap.value()->isNotUsed())
598 if (iMap.value()->Filter(
toolId) ==
false)
600 ui->tableWidget->setRowCount(
ui->tableWidget->rowCount() + 1);
601 QTableWidgetItem *item =
new QTableWidgetItem(iMap.key());
602 ui->tableWidget->setItem(
ui->tableWidget->rowCount()-1,
ColumnName, item);
605 ui->tableWidget->blockSignals(
false);
606 ui->tableWidget->selectRow(0);
607 ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
617 ui->tableWidget->blockSignals(
true);
618 ui->tableWidget->clearContents();
619 ui->tableWidget->setRowCount(0);
621 ui->description_Label->setText(
"");
623 QMapIterator<QString, QSharedPointer<VMeasurement>> iMap(var);
624 while (iMap.hasNext())
627 if (
ui->checkBoxHideEmpty->isEnabled() &&
ui->checkBoxHideEmpty->isChecked() && iMap.value()->isNotUsed())
631 if (iMap.value()->Filter(
toolId) ==
false)
633 ui->tableWidget->setRowCount(
ui->tableWidget->rowCount() + 1);
634 QTableWidgetItem *itemName =
new QTableWidgetItem(iMap.key());
635 itemName->setToolTip(itemName->text());
637 QTableWidgetItem *itemFullName =
new QTableWidgetItem();
638 if (iMap.value()->isCustom())
640 itemFullName->setText(iMap.value()->getGuiText());
644 itemFullName->setText(
qApp->TrVars()->guiText(iMap.value()->GetName()));
647 itemFullName->setToolTip(itemFullName->text());
648 ui->tableWidget->setItem(
ui->tableWidget->rowCount()-1,
ColumnName, itemName);
649 ui->tableWidget->setItem(
ui->tableWidget->rowCount()-1,
ColumnFullName, itemFullName);
652 ui->tableWidget->blockSignals(
false);
653 ui->tableWidget->selectRow(0);
654 ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
663 ui->tableWidget->blockSignals(
true);
664 ui->tableWidget->clearContents();
665 ui->tableWidget->setRowCount(0);
667 ui->description_Label->setText(
"");
670 while (i !=
qApp->TrVars()->getFunctions().constEnd())
672 ui->tableWidget->setRowCount(
ui->tableWidget->rowCount() + 1);
673 QTableWidgetItem *item =
new QTableWidgetItem(i.value().translate());
674 ui->tableWidget->setItem(
ui->tableWidget->rowCount()-1,
ColumnName, item);
675 item->setToolTip(i.value().getMdisambiguation());
679 ui->tableWidget->blockSignals(
false);
680 ui->tableWidget->selectRow(0);
681 ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
687 ui->tableWidget->blockSignals(
true);
690 if (filter.isEmpty())
693 for (
auto i = 0; i <
ui->tableWidget->rowCount(); ++i)
695 ui->tableWidget->showRow(i);
701 for (
auto i = 0; i <
ui->tableWidget->rowCount(); i++)
703 ui->tableWidget->hideRow(i);
707 for (
auto item :
ui->tableWidget->findItems(filter, Qt::MatchContains))
712 ui->tableWidget->showRow(item->row());
717 ui->tableWidget->blockSignals(
false);
722 ui->plainTextEditFormula->clear();
The VContainer class container of all variables.
const QMap< QString, QSharedPointer< VArcRadius > > arcRadiusesData() const
const QMap< QString, QSharedPointer< VLineAngle > > lineAnglesData() const
const QMap< QString, QSharedPointer< VCurveAngle > > curveAnglesData() const
const QMap< QString, QSharedPointer< VCurveCLength > > controlPointLengthsData() const
const QMap< QString, QSharedPointer< VCurveLength > > curveLengthsData() const
const QMap< QString, QSharedPointer< VLengthLine > > lineLengthsData() const
const QHash< QString, QSharedPointer< VInternalVariable > > * DataVariables() const
const QMap< QString, QSharedPointer< VIncrement > > variablesData() const
QSharedPointer< T > GetVariable(QString name) const
GetVariable return varible by name.
const QMap< QString, QSharedPointer< VMeasurement > > DataMeasurements() const
The VIncrement class keep data row of increment table.
virtual qreal GetValue() const
The VMeasurement class keep data row of multisize table.
const QString degreeSymbol
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.