2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file dialogincrements.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2013-11-15 13:41:26 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** 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/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-07-17 13:38:11 +02:00
|
|
|
#include "dialogincrements.h"
|
|
|
|
#include "ui_dialogincrements.h"
|
2015-08-25 12:35:50 +02:00
|
|
|
#include "../vwidgets/vwidgetpopup.h"
|
|
|
|
#include "../vmisc/vsettings.h"
|
|
|
|
#include "../qmuparser/qmudef.h"
|
|
|
|
#include "../vpatterndb/vtranslatevars.h"
|
|
|
|
#include "../vpatterndb/calculator.h"
|
|
|
|
#include "../vtools/dialogs/support/dialogeditwrongformula.h"
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2014-04-15 20:38:36 +02:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QMessageBox>
|
2014-06-17 11:50:11 +02:00
|
|
|
#include <QCloseEvent>
|
2014-06-25 12:30:22 +02:00
|
|
|
#include <QTableWidget>
|
2014-07-10 09:10:29 +02:00
|
|
|
#include <QSettings>
|
2014-10-03 12:32:12 +02:00
|
|
|
#include <QTableWidgetItem>
|
2016-05-24 14:06:35 +02:00
|
|
|
#include <QtNumeric>
|
2013-11-21 13:05:26 +01:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
#define DIALOG_MAX_FORMULA_HEIGHT 64
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief DialogIncrements create dialog
|
|
|
|
* @param data container with data
|
|
|
|
* @param doc dom document container
|
|
|
|
* @param parent parent widget
|
|
|
|
*/
|
2014-02-25 15:02:09 +01:00
|
|
|
DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *parent)
|
2015-08-25 12:35:50 +02:00
|
|
|
:DialogTool(data, NULL_ID, parent),
|
|
|
|
ui(new Ui::DialogIncrements),
|
|
|
|
data(data),
|
|
|
|
doc(doc),
|
2016-06-11 14:51:48 +02:00
|
|
|
formulaBaseHeight(0),
|
|
|
|
search()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-07-17 13:38:11 +02:00
|
|
|
ui->setupUi(this);
|
2015-12-09 11:40:43 +01:00
|
|
|
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
ui->lineEditName->setClearButtonEnabled(true);
|
2016-06-11 14:51:48 +02:00
|
|
|
ui->lineEditFind->setClearButtonEnabled(true);
|
2015-12-09 11:40:43 +01:00
|
|
|
#endif
|
|
|
|
|
2016-08-23 20:24:14 +02:00
|
|
|
ui->lineEditFind->installEventFilter(this);
|
|
|
|
|
2016-06-11 14:51:48 +02:00
|
|
|
search = QSharedPointer<VTableSearch>(new VTableSearch(ui->tableWidgetIncrement));
|
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
formulaBaseHeight = ui->plainTextEditFormula->height();
|
2016-08-23 20:24:14 +02:00
|
|
|
ui->plainTextEditFormula->installEventFilter(this);
|
2014-03-28 14:11:46 +01:00
|
|
|
|
2016-08-26 11:38:23 +02:00
|
|
|
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale::system()) : setLocale(QLocale::c());
|
2015-02-10 20:27:11 +01:00
|
|
|
|
2015-04-01 19:08:35 +02:00
|
|
|
qCDebug(vDialog, "Showing variables.");
|
2014-10-24 12:13:24 +02:00
|
|
|
ShowUnits();
|
|
|
|
|
2014-03-28 14:11:46 +01:00
|
|
|
FillIncrements();
|
2015-06-02 15:53:19 +02:00
|
|
|
FillLengthsLines();
|
|
|
|
FillLengthLinesAngles();
|
|
|
|
FillLengthsCurves();
|
2016-09-24 19:44:06 +02:00
|
|
|
FillCurvesCLengths();
|
2015-05-31 11:17:09 +02:00
|
|
|
FillRadiusesArcs();
|
2015-06-02 15:53:19 +02:00
|
|
|
FillAnglesCurves();
|
2014-03-28 14:11:46 +01:00
|
|
|
|
2014-06-05 11:52:00 +02:00
|
|
|
connect(this, &DialogIncrements::FullUpdateTree, this->doc, &VPattern::LiteParseTree);
|
2014-02-25 15:02:09 +01:00
|
|
|
connect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile);
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2013-10-15 12:20:34 +02:00
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
2015-10-08 19:45:26 +02:00
|
|
|
#if QT_VERSION > QT_VERSION_CHECK(5, 1, 0)
|
|
|
|
ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression(NameRegExp()), this));
|
|
|
|
#else
|
|
|
|
ui->lineEditName->setValidator( new QRegExpValidator(QRegExp(NameRegExp()), this));
|
|
|
|
#endif
|
2015-08-25 12:35:50 +02:00
|
|
|
|
|
|
|
connect(ui->tableWidgetIncrement, &QTableWidget::itemSelectionChanged, this,
|
|
|
|
&DialogIncrements::ShowIncrementDetails);
|
|
|
|
|
|
|
|
connect(ui->toolButtonAdd, &QPushButton::clicked, this, &DialogIncrements::AddIncrement);
|
|
|
|
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &DialogIncrements::RemoveIncrement);
|
|
|
|
connect(ui->toolButtonUp, &QToolButton::clicked, this, &DialogIncrements::MoveUp);
|
|
|
|
connect(ui->toolButtonDown, &QToolButton::clicked, this, &DialogIncrements::MoveDown);
|
|
|
|
connect(ui->pushButtonGrow, &QPushButton::clicked, this, &DialogIncrements::DeployFormula);
|
|
|
|
connect(ui->toolButtonExpr, &QToolButton::clicked, this, &DialogIncrements::Fx);
|
|
|
|
connect(ui->lineEditName, &QLineEdit::editingFinished, this, &DialogIncrements::SaveIncrName);
|
|
|
|
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrDescription);
|
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrFormula);
|
2016-12-21 19:08:02 +01:00
|
|
|
connect(ui->lineEditFind, &QLineEdit::textEdited, [this](const QString &term){search->Find(term);});
|
|
|
|
connect(ui->toolButtonFindPrevious, &QToolButton::clicked, [this](){search->FindPrevious();});
|
|
|
|
connect(ui->toolButtonFindNext, &QToolButton::clicked, [this](){search->FindNext();});
|
2015-08-25 12:35:50 +02:00
|
|
|
|
2016-08-26 15:16:06 +02:00
|
|
|
connect(search.data(), &VTableSearch::HasResult, [this] (bool state)
|
|
|
|
{
|
|
|
|
ui->toolButtonFindPrevious->setEnabled(state);
|
|
|
|
});
|
|
|
|
connect(search.data(), &VTableSearch::HasResult, [this] (bool state)
|
|
|
|
{
|
|
|
|
ui->toolButtonFindNext->setEnabled(state);
|
|
|
|
});
|
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
if (ui->tableWidgetIncrement->rowCount() > 0)
|
|
|
|
{
|
|
|
|
ui->tableWidgetIncrement->selectRow(0);
|
|
|
|
}
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief FillIncrementTable fill data for increment table
|
|
|
|
*/
|
2014-03-19 19:27:11 +01:00
|
|
|
void DialogIncrements::FillIncrements()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
ui->tableWidgetIncrement->blockSignals(true);
|
|
|
|
ui->tableWidgetIncrement->clearContents();
|
|
|
|
|
2014-08-21 14:44:40 +02:00
|
|
|
const QMap<QString, QSharedPointer<VIncrement> > increments = data->DataIncrements();
|
|
|
|
QMap<QString, QSharedPointer<VIncrement> >::const_iterator i;
|
2014-02-25 15:40:24 +01:00
|
|
|
QMap<quint32, QString> map;
|
2013-10-04 13:32:42 +02:00
|
|
|
//Sorting QHash by id
|
2014-08-21 14:44:40 +02:00
|
|
|
for (i = increments.constBegin(); i != increments.constEnd(); ++i)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-21 14:44:40 +02:00
|
|
|
QSharedPointer<VIncrement> incr = i.value();
|
2015-08-25 12:35:50 +02:00
|
|
|
map.insert(incr->getIndex(), i.key());
|
2013-10-04 13:32:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qint32 currentRow = -1;
|
2014-02-25 15:40:24 +01:00
|
|
|
QMapIterator<quint32, QString> iMap(map);
|
2015-08-25 12:35:50 +02:00
|
|
|
ui->tableWidgetIncrement->setRowCount ( increments.size() );
|
2013-11-04 21:35:15 +01:00
|
|
|
while (iMap.hasNext())
|
|
|
|
{
|
2013-10-04 13:32:42 +02:00
|
|
|
iMap.next();
|
2014-08-21 14:44:40 +02:00
|
|
|
QSharedPointer<VIncrement> incr = increments.value(iMap.value());
|
2013-07-25 14:00:51 +02:00
|
|
|
currentRow++;
|
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
AddCell(ui->tableWidgetIncrement, incr->GetName(), currentRow, 0, Qt::AlignVCenter); // name
|
|
|
|
AddCell(ui->tableWidgetIncrement, qApp->LocaleToString(*incr->GetValue()), currentRow, 1,
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter, incr->IsFormulaOk()); // calculated value
|
2013-07-25 14:00:51 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
QString formula;
|
|
|
|
try
|
2014-03-19 19:27:11 +01:00
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
|
2014-03-19 19:27:11 +01:00
|
|
|
}
|
2015-08-25 12:35:50 +02:00
|
|
|
catch (qmu::QmuParserError &e)
|
2014-03-19 19:27:11 +01:00
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(e)
|
2015-08-25 12:35:50 +02:00
|
|
|
formula = incr->GetFormula();
|
2014-03-19 19:27:11 +01:00
|
|
|
}
|
2013-07-25 14:00:51 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
AddCell(ui->tableWidgetIncrement, formula, currentRow, 2, Qt::AlignVCenter); // formula
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
2013-08-13 18:48:36 +02:00
|
|
|
ui->tableWidgetIncrement->resizeColumnsToContents();
|
|
|
|
ui->tableWidgetIncrement->resizeRowsToContents();
|
2015-08-25 12:35:50 +02:00
|
|
|
ui->tableWidgetIncrement->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
ui->tableWidgetIncrement->blockSignals(false);
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-07-29 14:19:11 +02:00
|
|
|
template <typename T>
|
2015-10-28 15:22:36 +01:00
|
|
|
void DialogIncrements::FillTable(const QMap<QString, T> &varTable, QTableWidget *table)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(table != nullptr)
|
2013-10-15 13:01:36 +02:00
|
|
|
|
2013-07-25 14:00:51 +02:00
|
|
|
qint32 currentRow = -1;
|
2014-07-29 14:19:11 +02:00
|
|
|
QMapIterator<QString, T> i(varTable);
|
2013-11-04 21:35:15 +01:00
|
|
|
while (i.hasNext())
|
|
|
|
{
|
2013-07-25 14:00:51 +02:00
|
|
|
i.next();
|
2014-07-29 14:19:11 +02:00
|
|
|
qreal length = *i.value()->GetValue();
|
2013-07-25 14:00:51 +02:00
|
|
|
currentRow++;
|
2014-07-29 13:28:18 +02:00
|
|
|
table->setRowCount ( varTable.size() );
|
2013-07-25 14:00:51 +02:00
|
|
|
|
2014-06-25 12:30:22 +02:00
|
|
|
QTableWidgetItem *item = new QTableWidgetItem(i.key());
|
2014-05-26 15:42:41 +02:00
|
|
|
item->setTextAlignment(Qt::AlignLeft);
|
2013-07-25 14:00:51 +02:00
|
|
|
item->setFont(QFont("Times", 12, QFont::Bold));
|
2014-06-25 12:30:22 +02:00
|
|
|
table->setItem(currentRow, 0, item);
|
2013-07-25 14:00:51 +02:00
|
|
|
|
2015-02-11 10:11:49 +01:00
|
|
|
item = new QTableWidgetItem(qApp->LocaleToString(length));
|
2013-07-25 14:00:51 +02:00
|
|
|
item->setTextAlignment(Qt::AlignHCenter);
|
2014-06-25 12:30:22 +02:00
|
|
|
table->setItem(currentRow, 1, item);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
2014-06-25 12:30:22 +02:00
|
|
|
table->resizeColumnsToContents();
|
|
|
|
table->resizeRowsToContents();
|
|
|
|
table->verticalHeader()->setDefaultSectionSize(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief FillLengthLines fill data for table of lines lengths
|
|
|
|
*/
|
2015-06-02 15:53:19 +02:00
|
|
|
void DialogIncrements::FillLengthsLines()
|
2014-06-25 12:30:22 +02:00
|
|
|
{
|
|
|
|
FillTable(data->DataLengthLines(), ui->tableWidgetLines);
|
2013-08-05 10:37:56 +02:00
|
|
|
}
|
|
|
|
|
2015-05-30 12:58:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-06-02 15:53:19 +02:00
|
|
|
void DialogIncrements::FillLengthLinesAngles()
|
2015-05-30 12:58:27 +02:00
|
|
|
{
|
2015-06-02 15:53:19 +02:00
|
|
|
FillTable(data->DataAngleLines(), ui->tableWidgetLinesAngles);
|
2015-05-30 12:58:27 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief FillLengthSplines fill data for table of splines lengths
|
|
|
|
*/
|
2015-06-02 15:53:19 +02:00
|
|
|
void DialogIncrements::FillLengthsCurves()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-04-01 21:34:57 +02:00
|
|
|
FillTable(data->DataLengthCurves(), ui->tableWidgetSplines);
|
2013-07-25 14:00:51 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::FillCurvesCLengths()
|
|
|
|
{
|
|
|
|
FillTable(data->DataCurvesCLength(), ui->tableWidgetCLength);
|
|
|
|
}
|
|
|
|
|
2015-05-31 11:17:09 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::FillRadiusesArcs()
|
|
|
|
{
|
|
|
|
FillTable(data->DataRadiusesArcs(), ui->tableWidgetRadiusesArcs);
|
|
|
|
}
|
|
|
|
|
2015-06-02 15:53:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::FillAnglesCurves()
|
|
|
|
{
|
|
|
|
FillTable(data->DataAnglesCurves(), ui->tableWidgetAnglesCurves);
|
|
|
|
}
|
|
|
|
|
2014-10-24 12:13:24 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::ShowUnits()
|
|
|
|
{
|
2015-05-30 12:58:27 +02:00
|
|
|
const QString unit = VDomDocument::UnitsToStr(qApp->patternUnit());
|
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
ShowHeaderUnits(ui->tableWidgetIncrement, 1, unit);// calculated value
|
|
|
|
ShowHeaderUnits(ui->tableWidgetIncrement, 2, unit);// formula
|
2014-10-24 12:13:24 +02:00
|
|
|
|
2015-05-30 12:58:27 +02:00
|
|
|
ShowHeaderUnits(ui->tableWidgetLines, 1, unit);// lengths
|
|
|
|
ShowHeaderUnits(ui->tableWidgetSplines, 1, unit);// lengths
|
2016-09-24 19:44:06 +02:00
|
|
|
ShowHeaderUnits(ui->tableWidgetCLength, 1, unit);// lengths
|
2016-04-01 21:34:57 +02:00
|
|
|
ShowHeaderUnits(ui->tableWidgetLinesAngles, 1, degreeSymbol);// angle
|
2015-05-31 11:17:09 +02:00
|
|
|
ShowHeaderUnits(ui->tableWidgetRadiusesArcs, 1, unit);// radius
|
2016-04-01 21:34:57 +02:00
|
|
|
ShowHeaderUnits(ui->tableWidgetAnglesCurves, 1, degreeSymbol);// angle
|
2014-10-24 12:13:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-05-30 12:58:27 +02:00
|
|
|
void DialogIncrements::ShowHeaderUnits(QTableWidget *table, int column, const QString &unit)
|
2014-10-24 12:13:24 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(table != nullptr)
|
2014-10-24 12:13:24 +02:00
|
|
|
|
|
|
|
const QString header = table->horizontalHeaderItem(column)->text();
|
|
|
|
const QString unitHeader = QString("%1 (%2)").arg(header).arg(unit);
|
|
|
|
table->horizontalHeaderItem(column)->setText(unitHeader);
|
|
|
|
}
|
|
|
|
|
2015-02-17 18:02:47 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-25 12:35:50 +02:00
|
|
|
void DialogIncrements::AddCell(QTableWidget *table, const QString &text, int row, int column, int aligment, bool ok)
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(table != nullptr)
|
2015-08-25 12:35:50 +02:00
|
|
|
|
|
|
|
QTableWidgetItem *item = new QTableWidgetItem(text);
|
|
|
|
item->setTextAlignment(aligment);
|
|
|
|
|
|
|
|
// set the item non-editable (view only), and non-selectable
|
|
|
|
Qt::ItemFlags flags = item->flags();
|
|
|
|
flags &= ~(Qt::ItemIsEditable); // reset/clear the flag
|
|
|
|
item->setFlags(flags);
|
|
|
|
|
|
|
|
if (not ok)
|
|
|
|
{
|
|
|
|
QBrush brush = item->foreground();
|
|
|
|
brush.setColor(Qt::red);
|
|
|
|
item->setForeground(brush);
|
|
|
|
}
|
|
|
|
|
|
|
|
table->setItem(row, column, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QString DialogIncrements::ClearIncrementName(const QString &name) const
|
2015-02-17 18:02:47 +01:00
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
QString clear = name;
|
|
|
|
const int index = clear.indexOf(CustomIncrSign);
|
|
|
|
if (index == 0)
|
|
|
|
{
|
|
|
|
clear.remove(0, 1);
|
|
|
|
}
|
|
|
|
return clear;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool DialogIncrements::EvalIncrementFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label)
|
|
|
|
{
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit());//Show unit in dialog lable (cm, mm or inch)
|
|
|
|
if (formula.isEmpty())
|
|
|
|
{
|
|
|
|
label->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field."));
|
|
|
|
label->setToolTip(tr("Empty field"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QString f;
|
|
|
|
// Replace line return character with spaces for calc if exist
|
|
|
|
if (fromUser)
|
|
|
|
{
|
|
|
|
f = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f = formula;
|
|
|
|
}
|
|
|
|
f.replace("\n", " ");
|
2016-05-24 14:25:58 +02:00
|
|
|
QScopedPointer<Calculator> cal(new Calculator());
|
2015-10-15 12:07:43 +02:00
|
|
|
const qreal result = cal->EvalFormula(data->PlainVariables(), f);
|
2015-08-25 12:35:50 +02:00
|
|
|
|
2016-05-24 14:06:35 +02:00
|
|
|
if (qIsInf(result) || qIsNaN(result))
|
|
|
|
{
|
|
|
|
label->setText(tr("Error") + " (" + postfix + ").");
|
|
|
|
label->setToolTip(tr("Invalid value"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
label->setText(qApp->LocaleToString(result) + " " + postfix);
|
|
|
|
label->setToolTip(tr("Value"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
label->setText(tr("Error") + " (" + postfix + "). " + tr("Parser error: %1").arg(e.GetMsg()));
|
|
|
|
label->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::Controls()
|
|
|
|
{
|
|
|
|
if (ui->tableWidgetIncrement->rowCount() > 0)
|
|
|
|
{
|
|
|
|
ui->toolButtonRemove->setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->toolButtonRemove->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ui->tableWidgetIncrement->rowCount() >= 2)
|
|
|
|
{
|
|
|
|
if (ui->tableWidgetIncrement->currentRow() == 0)
|
|
|
|
{
|
|
|
|
ui->toolButtonUp->setEnabled(false);
|
|
|
|
ui->toolButtonDown->setEnabled(true);
|
|
|
|
}
|
|
|
|
else if (ui->tableWidgetIncrement->currentRow() == ui->tableWidgetIncrement->rowCount()-1)
|
|
|
|
{
|
|
|
|
ui->toolButtonUp->setEnabled(true);
|
|
|
|
ui->toolButtonDown->setEnabled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->toolButtonUp->setEnabled(true);
|
|
|
|
ui->toolButtonDown->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->toolButtonUp->setEnabled(false);
|
|
|
|
ui->toolButtonDown->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::EnableDetails(bool enabled)
|
|
|
|
{
|
|
|
|
if (enabled)
|
|
|
|
{
|
|
|
|
Controls();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->toolButtonRemove->setEnabled(enabled);
|
|
|
|
ui->toolButtonUp->setEnabled(enabled);
|
|
|
|
ui->toolButtonDown->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not enabled)
|
|
|
|
{ // Clear
|
|
|
|
ui->lineEditName->blockSignals(true);
|
|
|
|
ui->lineEditName->clear();
|
|
|
|
ui->lineEditName->blockSignals(false);
|
|
|
|
|
|
|
|
ui->plainTextEditDescription->blockSignals(true);
|
|
|
|
ui->plainTextEditDescription->clear();
|
|
|
|
ui->plainTextEditDescription->blockSignals(false);
|
|
|
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(true);
|
|
|
|
ui->labelCalculatedValue->clear();
|
|
|
|
ui->labelCalculatedValue->blockSignals(false);
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
ui->plainTextEditFormula->clear();
|
|
|
|
ui->plainTextEditFormula->blockSignals(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->pushButtonGrow->setEnabled(enabled);
|
|
|
|
ui->toolButtonExpr->setEnabled(enabled);
|
|
|
|
ui->lineEditName->setEnabled(enabled);
|
|
|
|
ui->plainTextEditDescription->setEnabled(enabled);
|
|
|
|
ui->plainTextEditFormula->setEnabled(enabled);
|
2015-02-17 18:02:47 +01:00
|
|
|
}
|
|
|
|
|
2014-09-24 18:37:39 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief FullUpdateFromFile update information in tables form file
|
|
|
|
*/
|
|
|
|
void DialogIncrements::FullUpdateFromFile()
|
|
|
|
{
|
2014-01-17 23:03:24 +01:00
|
|
|
ui->tableWidgetLines->clearContents();
|
|
|
|
ui->tableWidgetSplines->clearContents();
|
2016-01-11 14:11:33 +01:00
|
|
|
ui->tableWidgetAnglesCurves->clearContents();
|
|
|
|
ui->tableWidgetLinesAngles->clearContents();
|
|
|
|
ui->tableWidgetRadiusesArcs->clearContents();
|
|
|
|
|
|
|
|
FillIncrements();
|
|
|
|
FillLengthsLines();
|
|
|
|
FillLengthLinesAngles();
|
|
|
|
FillLengthsCurves();
|
2016-09-24 19:44:06 +02:00
|
|
|
FillCurvesCLengths();
|
2016-01-11 14:11:33 +01:00
|
|
|
FillRadiusesArcs();
|
|
|
|
FillAnglesCurves();
|
2016-06-11 14:51:48 +02:00
|
|
|
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-06-02 16:28:02 +02:00
|
|
|
/**
|
|
|
|
* @brief clickedToolButtonAdd create new row in table
|
|
|
|
*/
|
2015-08-25 12:35:50 +02:00
|
|
|
void DialogIncrements::AddIncrement()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
qCDebug(vDialog, "Add a new increment");
|
2013-07-17 13:38:11 +02:00
|
|
|
qint32 num = 1;
|
|
|
|
QString name;
|
2013-11-04 21:35:15 +01:00
|
|
|
do
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
name = CustomIncrSign + tr("Increment_%1").arg(num);
|
2013-07-17 13:38:11 +02:00
|
|
|
num++;
|
2014-10-02 11:46:24 +02:00
|
|
|
} while (data->IsUnique(name)==false);
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
qint32 currentRow;
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
if (ui->tableWidgetIncrement->currentRow() == -1)
|
|
|
|
{
|
|
|
|
currentRow = ui->tableWidgetIncrement->rowCount();
|
|
|
|
doc->AddEmptyIncrement(name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentRow = ui->tableWidgetIncrement->currentRow()+1;
|
2015-10-03 00:44:44 +02:00
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(ui->tableWidgetIncrement->currentRow(), 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
doc->AddEmptyIncrementAfter(nameField->text(), name);
|
|
|
|
}
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
FullUpdateTree(Document::LiteParse);
|
|
|
|
ui->tableWidgetIncrement->selectRow(currentRow);
|
|
|
|
}
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief clickedToolButtonRemove remove one row from table
|
|
|
|
*/
|
|
|
|
void DialogIncrements::RemoveIncrement()
|
|
|
|
{
|
|
|
|
const int row = ui->tableWidgetIncrement->currentRow();
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
if (row == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
doc->RemoveIncrement(nameField->text());
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
FullUpdateTree(Document::LiteParse);
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
if (ui->tableWidgetIncrement->rowCount() > 0)
|
|
|
|
{
|
|
|
|
ui->tableWidgetIncrement->selectRow(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EnableDetails(false);
|
|
|
|
}
|
|
|
|
}
|
2013-07-17 13:38:11 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::MoveUp()
|
|
|
|
{
|
|
|
|
const int row = ui->tableWidgetIncrement->currentRow();
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
doc->MoveUpIncrement(nameField->text());
|
|
|
|
FullUpdateTree(Document::LiteParse);
|
|
|
|
ui->tableWidgetIncrement->selectRow(row-1);
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-25 12:35:50 +02:00
|
|
|
void DialogIncrements::MoveDown()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
const int row = ui->tableWidgetIncrement->currentRow();
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-08-04 16:35:57 +02:00
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
doc->MoveDownIncrement(nameField->text());
|
|
|
|
FullUpdateTree(Document::LiteParse);
|
|
|
|
ui->tableWidgetIncrement->selectRow(row+1);
|
|
|
|
}
|
2014-08-04 16:35:57 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::SaveIncrName()
|
|
|
|
{
|
|
|
|
const int row = ui->tableWidgetIncrement->currentRow();
|
2014-08-04 16:35:57 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
if (row == -1)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
const QString newName = CustomIncrSign + ui->lineEditName->text();
|
|
|
|
if (data->IsUnique(newName))
|
|
|
|
{
|
|
|
|
doc->SetIncrementName(nameField->text(), newName);
|
|
|
|
FullUpdateTree(Document::LiteParse);
|
|
|
|
ui->tableWidgetIncrement->blockSignals(true);
|
|
|
|
ui->tableWidgetIncrement->selectRow(row);
|
|
|
|
ui->tableWidgetIncrement->blockSignals(false);
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
2014-11-24 15:51:27 +01:00
|
|
|
else
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
ui->lineEditName->setText(ClearIncrementName(nameField->text()));
|
2014-11-24 15:51:27 +01:00
|
|
|
}
|
2015-08-25 12:35:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::SaveIncrDescription()
|
|
|
|
{
|
|
|
|
const int row = ui->tableWidgetIncrement->currentRow();
|
2014-08-04 16:35:57 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
if (row == -1)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
return;
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
2014-08-04 16:35:57 +02:00
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
doc->SetIncrementDescription(nameField->text(), ui->plainTextEditDescription->toPlainText());
|
|
|
|
|
|
|
|
FullUpdateTree(Document::LiteParse);
|
|
|
|
|
|
|
|
const QTextCursor cursor = ui->plainTextEditDescription->textCursor();
|
|
|
|
ui->tableWidgetIncrement->blockSignals(true);
|
|
|
|
ui->tableWidgetIncrement->selectRow(row);
|
2014-08-09 10:43:01 +02:00
|
|
|
ui->tableWidgetIncrement->blockSignals(false);
|
2015-08-25 12:35:50 +02:00
|
|
|
ui->plainTextEditDescription->setTextCursor(cursor);
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-25 12:35:50 +02:00
|
|
|
void DialogIncrements::SaveIncrFormula()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
const int row = ui->tableWidgetIncrement->currentRow();
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
|
|
|
|
// Replace line return character with spaces for calc if exist
|
|
|
|
QString text = ui->plainTextEditFormula->toPlainText();
|
|
|
|
text.replace("\n", " ");
|
|
|
|
|
|
|
|
QTableWidgetItem *formulaField = ui->tableWidgetIncrement->item(row, 2);
|
|
|
|
if (formulaField->text() == text)
|
|
|
|
{
|
|
|
|
QTableWidgetItem *result = ui->tableWidgetIncrement->item(row, 1);
|
|
|
|
//Show unit in dialog lable (cm, mm or inch)
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit());
|
|
|
|
ui->labelCalculatedValue->setText(result->text() + " " +postfix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
{
|
|
|
|
//Show unit in dialog lable (cm, mm or inch)
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit());
|
|
|
|
ui->labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSharedPointer<VIncrement> incr = data->GetVariable<VIncrement>(nameField->text());
|
2016-08-02 14:12:13 +02:00
|
|
|
if (not EvalIncrementFormula(text, true, incr->GetData(), ui->labelCalculatedValue))
|
2015-08-25 12:35:50 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const QString formula = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator());
|
|
|
|
doc->SetIncrementFormula(nameField->text(), formula);
|
|
|
|
}
|
2016-03-05 16:27:07 +01:00
|
|
|
catch (qmu::QmuParserError &e) // Just in case something bad will happen
|
2015-08-25 12:35:50 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(e)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FullUpdateTree(Document::LiteParse);
|
|
|
|
|
|
|
|
const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
|
|
|
ui->tableWidgetIncrement->blockSignals(true);
|
|
|
|
ui->tableWidgetIncrement->selectRow(row);
|
|
|
|
ui->tableWidgetIncrement->blockSignals(false);
|
|
|
|
ui->plainTextEditFormula->setTextCursor(cursor);
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-07-10 09:10:29 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-25 12:35:50 +02:00
|
|
|
void DialogIncrements::DeployFormula()
|
2014-07-10 09:10:29 +02:00
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
SCASSERT(ui->plainTextEditFormula != nullptr)
|
|
|
|
SCASSERT(ui->pushButtonGrow != nullptr)
|
2015-10-05 16:12:36 +02:00
|
|
|
|
|
|
|
const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
if (ui->plainTextEditFormula->height() < DIALOG_MAX_FORMULA_HEIGHT)
|
|
|
|
{
|
|
|
|
ui->plainTextEditFormula->setFixedHeight(DIALOG_MAX_FORMULA_HEIGHT);
|
|
|
|
//Set icon from theme (internal for Windows system)
|
|
|
|
ui->pushButtonGrow->setIcon(QIcon::fromTheme("go-next",
|
|
|
|
QIcon(":/icons/win.icon.theme/16x16/actions/go-next.png")));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->plainTextEditFormula->setFixedHeight(formulaBaseHeight);
|
|
|
|
//Set icon from theme (internal for Windows system)
|
|
|
|
ui->pushButtonGrow->setIcon(QIcon::fromTheme("go-down",
|
|
|
|
QIcon(":/icons/win.icon.theme/16x16/actions/go-down.png")));
|
|
|
|
}
|
2014-07-10 09:10:29 +02:00
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
// 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);
|
2015-10-05 16:12:36 +02:00
|
|
|
|
|
|
|
ui->plainTextEditFormula->setFocus();
|
|
|
|
ui->plainTextEditFormula->setTextCursor(cursor);
|
2014-07-10 09:10:29 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-25 12:35:50 +02:00
|
|
|
void DialogIncrements::Fx()
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
const int row = ui->tableWidgetIncrement->currentRow();
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
{
|
2014-03-21 11:08:29 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-08-25 12:35:50 +02:00
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
QSharedPointer<VIncrement> incr = data->GetVariable<VIncrement>(nameField->text());
|
|
|
|
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(incr->GetData(), NULL_ID, this);
|
|
|
|
dialog->setWindowTitle(tr("Edit increment"));
|
2016-03-05 16:27:07 +01:00
|
|
|
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText().replace("\n", " "),
|
|
|
|
qApp->Settings()->GetOsSeparator()));
|
2015-08-25 12:35:50 +02:00
|
|
|
const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true);
|
|
|
|
dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch)
|
|
|
|
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
{
|
2016-05-23 20:16:43 +02:00
|
|
|
// Fix the bug #492. https://bitbucket.org/dismine/valentina/issues/492/valentina-crashes-when-add-an-increment
|
|
|
|
// Because of the bug need to take QTableWidgetItem twice time. Previous update "killed" the pointer.
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(row, 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
doc->SetIncrementFormula(nameField->text(), dialog->GetFormula());
|
|
|
|
FullUpdateTree(Document::LiteParse);
|
|
|
|
ui->tableWidgetIncrement->selectRow(row);
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
2015-08-25 12:35:50 +02:00
|
|
|
delete dialog;
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2014-01-17 22:41:27 +01:00
|
|
|
void DialogIncrements::closeEvent(QCloseEvent *event)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
ui->lineEditName->blockSignals(true);
|
|
|
|
ui->plainTextEditDescription->blockSignals(true);
|
|
|
|
|
2013-07-28 00:18:06 +02:00
|
|
|
emit DialogClosed(QDialog::Accepted);
|
2014-01-17 22:41:27 +01:00
|
|
|
event->accept();
|
2013-07-17 13:38:11 +02:00
|
|
|
}
|
|
|
|
|
2016-01-08 13:06:38 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::changeEvent(QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
{
|
|
|
|
// retranslate designer form (single inheritance approach)
|
|
|
|
ui->retranslateUi(this);
|
2016-01-11 14:11:33 +01:00
|
|
|
FullUpdateFromFile();
|
2016-01-08 13:06:38 +01:00
|
|
|
}
|
|
|
|
// remember to call base class implementation
|
2016-08-23 20:24:14 +02:00
|
|
|
QWidget::changeEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool DialogIncrements::eventFilter(QObject *object, QEvent *event)
|
|
|
|
{
|
|
|
|
if (QLineEdit *textEdit = qobject_cast<QLineEdit *>(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())
|
|
|
|
{
|
|
|
|
textEdit->insert(QLocale::system().decimalPoint());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textEdit->insert(QLocale::c().decimalPoint());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// pass the event on to the parent class
|
|
|
|
return DialogTool::eventFilter(object, event);
|
|
|
|
}
|
|
|
|
return false;// pass the event to the widget
|
2016-01-08 13:06:38 +01:00
|
|
|
}
|
|
|
|
|
2015-08-25 12:35:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void DialogIncrements::ShowIncrementDetails()
|
|
|
|
{
|
|
|
|
if (ui->tableWidgetIncrement->rowCount() > 0)
|
|
|
|
{
|
|
|
|
EnableDetails(true);
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
// name
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidgetIncrement->item(ui->tableWidgetIncrement->currentRow(), 0);
|
2015-08-25 12:35:50 +02:00
|
|
|
QSharedPointer<VIncrement> incr;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
incr = data->GetVariable<VIncrement>(nameField->text());
|
|
|
|
}
|
|
|
|
catch(const VExceptionBadId &e)
|
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(e)
|
2015-08-25 12:35:50 +02:00
|
|
|
EnableDetails(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->lineEditName->blockSignals(true);
|
|
|
|
ui->lineEditName->setText(ClearIncrementName(incr->GetName()));
|
|
|
|
ui->lineEditName->blockSignals(false);
|
|
|
|
|
|
|
|
ui->plainTextEditDescription->blockSignals(true);
|
|
|
|
ui->plainTextEditDescription->setPlainText(incr->GetDescription());
|
|
|
|
ui->plainTextEditDescription->blockSignals(false);
|
|
|
|
|
|
|
|
EvalIncrementFormula(incr->GetFormula(), false, incr->GetData(), ui->labelCalculatedValue);
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
|
|
|
|
QString formula;
|
|
|
|
try
|
|
|
|
{
|
2016-05-23 17:23:39 +02:00
|
|
|
formula = qApp->TrVars()->FormulaToUser(incr->GetFormula(), qApp->Settings()->GetOsSeparator());
|
2015-08-25 12:35:50 +02:00
|
|
|
}
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(e)
|
2015-08-25 12:35:50 +02:00
|
|
|
formula = incr->GetFormula();
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->setPlainText(formula);
|
|
|
|
ui->plainTextEditFormula->blockSignals(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EnableDetails(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2013-11-04 21:35:15 +01:00
|
|
|
DialogIncrements::~DialogIncrements()
|
|
|
|
{
|
2013-07-17 13:38:11 +02:00
|
|
|
delete ui;
|
|
|
|
}
|