55 #include <qiterator.h>
57 #include <QCloseEvent>
59 #include <QDoubleSpinBox>
66 #include <QMapIterator>
67 #include <QMessageLogger>
70 #include <QPlainTextEdit>
71 #include <QPushButton>
72 #include <QRegularExpression>
73 #include <QRegularExpressionMatch>
74 #include <QScopedPointer>
75 #include <QSharedPointer>
78 #include <QTextCursor>
87 #include "../ifc/xml/vdomdocument.h"
88 #include "../qmuparser/qmudef.h"
89 #include "../qmuparser/qmuparsererror.h"
90 #include "../vgeometry/vpointf.h"
91 #include "../vpatterndb/calculator.h"
92 #include "../vpatterndb/vcontainer.h"
93 #include "../vpatterndb/vtranslatevars.h"
94 #include "../vpatterndb/vpiecenode.h"
95 #include "../../tools/vabstracttool.h"
96 #include "../ifc/xml/vabstractpattern.h"
97 #include "../vgeometry/vabstractcurve.h"
98 #include "../vgeometry/vgobject.h"
99 #include "../vmisc/vcommonsettings.h"
103 Q_LOGGING_CATEGORY(vDialog,
"v.dialog")
105 #define DIALOG_MAX_FORMULA_HEIGHT 64
106 #define DIALOG_MIN_WIDTH 260
111 quint32
RowId(QListWidget *listWidget,
int i)
115 if (i < 0 || i >= listWidget->count())
120 const QListWidgetItem *rowItem = listWidget->item(i);
122 const VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
123 return rowNode.
GetId();
136 isInitialized(false),
140 timerFormula(nullptr),
142 apply_Button(nullptr),
143 spinBoxAngle(nullptr),
144 plainTextEditFormula(nullptr),
145 labelResultCalculation(nullptr),
146 labelEditNamePoint(nullptr),
147 labelEditFormula(nullptr),
148 okColor(this->palette().color(QPalette::Active, QPalette::WindowText)),
150 associatedTool(nullptr),
167 if (not
vis.isNull())
176 switch (event->key())
184 QDialog::keyPressEvent ( event );
205 QDialog::showEvent( event );
206 if ( event->spontaneous() )
216 setMaximumSize(size());
217 setMinimumSize(size());
227 box->blockSignals(
true);
229 for (
int i=0; i < list.size(); ++i)
233 box->blockSignals(
false);
234 box->setCurrentIndex(-1);
250 FillCombo<VAbstractCurve>(box,
GOType::Arc, rule, ch1, ch2);
257 box->blockSignals(
true);
262 for (i = objs->constBegin(); i != objs->constEnd(); ++i)
268 PrepareList<VAbstractCurve>(list, i.key());
274 box->blockSignals(
false);
281 box->blockSignals(
true);
286 for (i = objs->constBegin(); i != objs->constEnd(); ++i)
292 PrepareList<VAbstractCurve>(list, i.key());
298 box->blockSignals(
false);
308 for (i = objs->constBegin(); i != objs->constEnd(); ++i)
320 PrepareList<VAbstractCurve>(list, i.key());
336 while (i != stylesPics.constEnd())
338 box->addItem(i.value(),
"", QVariant(i.key()));
345 box->setCurrentIndex(index);
355 int size = box->iconSize().height();
357 #if defined(Q_OS_MAC)
363 while (i != map.constEnd())
365 QPixmap pix(size, size);
366 pix.fill(QColor(i.key()));
367 box->addItem(QIcon(pix), i.value(), QVariant(i.key()));
404 value = box->currentData().toString();
422 const qint32 index = box->findData(value);
425 box->blockSignals(
true);
426 box->setCurrentIndex(index);
427 box->blockSignals(
false);
435 QTextCursor cursor = plainTextEdit->textCursor();
436 cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
437 plainTextEdit->setTextCursor(cursor);
443 if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(
object))
445 if (event->type() == QEvent::KeyPress)
447 QKeyEvent *keyEvent =
static_cast<QKeyEvent *
>(event);
448 if ((keyEvent->key() == Qt::Key_Enter) || (keyEvent->key() == Qt::Key_Return))
453 else if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier))
455 if (
qApp->Settings()->GetOsSeparator())
457 plainTextEdit->insertPlainText(QLocale().decimalPoint());
461 plainTextEdit->insertPlainText(QLocale::c().decimalPoint());
470 return QDialog::eventFilter(
object, event);
483 name = baseName + QString(
"_%1").arg(num);
495 if (candidate < 0 || candidate >= listWidget->count())
504 const QListWidgetItem *rowItem = listWidget->item(i);
506 rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
515 while (rowNode.
isExcluded() && i < listWidget->count());
526 if (candidate < 0 || candidate >= listWidget->count())
535 const QListWidgetItem *rowItem = listWidget->item(i);
537 rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
555 if (listWidget->count() > 1)
559 return topId == bottomId;
568 for (
int i=0, sz = listWidget->count()-1; i<sz; ++i)
571 const quint32 firstId =
RowId(listWidget, firstIndex);
574 if (firstId == secondId)
586 QSet<quint32> pointLabels;
588 for (
int i=0; i < listWidget->count(); ++i)
590 const QListWidgetItem *rowItem = listWidget->item(i);
592 const VPieceNode rowNode = qvariant_cast<VPieceNode>(rowItem->data(Qt::UserRole));
596 pointLabels.insert(rowNode.
GetId());
600 return countPoints == pointLabels.size();
606 const QIcon icon = QIcon::fromTheme(
"dialog-warning",
607 QIcon(
":/icons/win.icon.theme/16x16/status/dialog-warning.png"));
609 const QPixmap pixmap = icon.pixmap(QSize(16, 16));
610 QByteArray byteArray;
611 QBuffer buffer(&byteArray);
612 pixmap.save(&buffer,
"PNG");
613 const QString url = QString(
"<img src=\"data:image/png;base64,") + byteArray.toBase64() + QLatin1String(
"\"/> ");
620 QFont font =
qApp->Settings()->getGuiFont();
621 font.setPointSize(
qApp->Settings()->getGuiFontSize());
623 font.setStrikeOut(nodeExcluded);
632 info.
name = obj->name();
633 info.
icon =
"://icon/24x24/spacer.png";
638 qApp->TrVars()->VariablesToUser(info.
name, 0, obj->name(), bias);
642 info.
icon =
"://icon/24x24/reverse.png";
645 else if (showNotch && node.
isNotch())
650 info.
icon =
"://icon/24x24/t_notch.png";
653 info.
icon =
"://icon/24x24/u_notch.png";
656 info.
icon =
"://icon/24x24/internal_v_notch.png";
659 info.
icon =
"://icon/24x24/external_v_notch.png";
662 info.
icon =
"://icon/24x24/castle_notch.png";
665 info.
icon =
"://icon/24x24/diamond_notch.png";
668 info.
icon =
"://icon/24x24/slit_notch.png";
694 qDebug()<<
"Got wrong tools. Ignore.";
698 bool newNodeAllowed =
false;
700 if(listWidget->count() == 0 || isDuplicate ||
RowId(listWidget, listWidget->count()-1) != node.
GetId())
702 newNodeAllowed =
true;
707 QListWidgetItem *item =
new QListWidgetItem(info.
name);
709 item->setData(Qt::UserRole, QVariant::fromValue(node));
710 item->setIcon(QIcon(info.
icon));
711 listWidget->addItem(item);
712 listWidget->setCurrentRow(listWidget->count()-1);
750 if (edit->text().isEmpty())
755 if (postfix.isEmpty())
775 if (edit->toPlainText().isEmpty())
780 if (postfix.isEmpty())
792 timer->setSingleShot(
true);
805 qreal
DialogTool::Eval(
const QString &text,
bool &flag, QLabel *label,
const QString& postfix,
bool checkZero,
806 bool checkLessThanZero)
811 qreal result = INT_MIN;
817 label->setText(tr(
"Error") +
" (" + postfix +
")");
818 label->setToolTip(tr(
"Empty field"));
825 QString formula = text;
826 formula.replace(
"\n",
" ");
828 formula =
qApp->TrVars()->FormulaFromUser(formula,
qApp->Settings()->GetOsSeparator());
829 QScopedPointer<Calculator> cal(
new Calculator());
832 if (qIsInf(result) || qIsNaN(result))
836 label->setText(tr(
"Error") +
" (" + postfix +
")");
837 label->setToolTip(tr(
"Invalid result. Value is infinite or NaN. Please, check your calculations."));
842 if (checkZero && qFuzzyIsNull(result))
846 label->setText(tr(
"Error") +
" (" + postfix +
")");
847 label->setToolTip(tr(
"Value can't be 0"));
849 else if (checkLessThanZero && result < 0)
853 label->setText(tr(
"Error") +
" (" + postfix +
")");
854 label->setToolTip(tr(
"Value can't be less than 0"));
858 label->setText(
qApp->LocaleToString(result) +
" " +postfix);
861 label->setToolTip(tr(
"Result Value"));
868 label->setText(tr(
"Error") +
" (" + postfix +
")");
872 label->setToolTip(tr(
"Parser error: %1").arg(e.
GetMsg()));
873 qDebug() <<
"\nMath parser error:\n"
874 <<
"--------------------------------------\n"
875 <<
"Message: " << e.
GetMsg() <<
"\n"
876 <<
"Expression: " << e.
GetExpr() <<
"\n"
877 <<
"--------------------------------------";
888 const qreal range = end - start ;
889 const qreal offsetValue = value - start ;
891 return ( offsetValue - ( floor( offsetValue / range ) * range ) ) + start ;
897 const quint32 &ch1,
const quint32 &ch2)
const
901 box->blockSignals(
true);
906 box->blockSignals(
false);
925 const quint32 &ch1,
const quint32 &ch2)
const
962 qint32 index = box->currentIndex();
965 return qvariant_cast<quint32>(box->itemData(index));
977 const qint32 index = box->findData(
id);
980 box->setCurrentIndex(index);
986 qWarning()<<
"Can't find object by id"<<id;
995 SCASSERT(buttonGrowLength !=
nullptr)
997 const QTextCursor cursor = formula->textCursor();
1001 setMaximumWidth(QWIDGETSIZE_MAX);
1004 buttonGrowLength->setIcon(QIcon::fromTheme(
"go-up",
1005 QIcon(
":/icons/win.icon.theme/16x16/actions/go-up.png")));
1010 formula->setFixedHeight(formulaBaseHeight);
1012 buttonGrowLength->setIcon(QIcon::fromTheme(
"go-down",
1013 QIcon(
":/icons/win.icon.theme/16x16/actions/go-down.png")));
1018 setUpdatesEnabled(
false);
1020 setUpdatesEnabled(
true);
1022 formula->setFocus();
1023 formula->setTextCursor(cursor);
1037 QMapIterator<QString, quint32> iter(list);
1038 while (iter.hasNext())
1041 box->addItem(iter.key(), iter.value());
1046 template <
typename T>
1052 QString newName = obj->name();
1054 if (
qApp->TrVars()->VariablesToUser(newName, 0, obj->name(), bias))
1060 list[obj->name()] = id;
1113 QLineEdit* edit = qobject_cast<QLineEdit*>(sender());
1116 QString name = edit->text();
1119 rx.match(name).hasMatch() ==
false)
1137 QPalette palette = widget->palette();
1138 palette.setColor(QPalette::Active, widget->foregroundRole(), color);
1139 widget->setPalette(palette);
1174 QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(sender());
1183 QPlainTextEdit* edit = qobject_cast<QPlainTextEdit*>(sender());
1305 const int currentIndex = list->currentRow();
1306 if (QListWidgetItem *currentItem = list->takeItem(currentIndex))
1308 list->insertItem(0, currentItem);
1309 list->setCurrentRow(0);
1317 int currentIndex = list->currentRow();
1318 if (QListWidgetItem *currentItem = list->takeItem(currentIndex--))
1320 if (currentIndex < 0)
1324 list->insertItem(currentIndex, currentItem);
1325 list->setCurrentRow(currentIndex);
1333 int currentIndex = list->currentRow();
1334 if (QListWidgetItem *currentItem = list->takeItem(currentIndex++))
1336 if (currentIndex > list->count())
1338 currentIndex = list->count();
1340 list->insertItem(currentIndex, currentItem);
1341 list->setCurrentRow(currentIndex);
1349 const int currentIndex = list->currentRow();
1350 if (QListWidgetItem *currentItem = list->takeItem(currentIndex))
1352 list->insertItem(list->count(), currentItem);
1353 list->setCurrentRow(list->count()-1);
1378 if (tool !=
nullptr)
1383 if (not
vis.isNull())
1396 template <
typename GObject>
1398 const quint32 &ch2)
const
1401 box->blockSignals(
true);
1406 for (i = objs->constBegin(); i != objs->constEnd(); ++i)
1410 if (i.key() !=
toolId && i.value()->getIdTool() !=
toolId && i.key() != ch1 && i.key() != ch2)
1415 PrepareList<GObject>(list, i.key());
1421 if (i.key() !=
toolId && i.value()->getIdTool() !=
toolId)
1426 PrepareList<GObject>(list, i.key());
1433 box->blockSignals(
false);
The Calculator class for calculation formula.
The VContainer class container of all variables.
static bool IsUnique(const QString &name)
const QHash< QString, QSharedPointer< VInternalVariable > > * DataVariables() const
const QSharedPointer< VGObject > GetGObject(quint32 id) const
GetGObject returns a point by id.
const QSharedPointer< T > GeometricObject(const quint32 &id) const
const QHash< quint32, QSharedPointer< VGObject > > * DataGObjects() const
data container with datagObjects return container of gObjects
VPiece GetPiece(quint32 id) const
NotchType getNotchType() const
Error class of the parser.
const QString & GetMsg() const
Returns the message string for this error.
const QString & GetExpr() const
gets the expression related tp this error.
QString UnitsToStr(const Unit &unit, const bool translate)
UnitsToStr translate unit to string.
const QString LineTypeSolidLine