Dialog Final measurements.
--HG-- branch : feature
This commit is contained in:
parent
8c84cff91d
commit
0eb6b8b30f
741
src/app/valentina/dialogs/dialogfinalmeasurements.cpp
Normal file
741
src/app/valentina/dialogs/dialogfinalmeasurements.cpp
Normal file
|
@ -0,0 +1,741 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file dialogfinalmeasurements.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 26 9, 2017
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentine project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2017 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 "dialogfinalmeasurements.h"
|
||||
#include "ui_dialogfinalmeasurements.h"
|
||||
#include "../vmisc/vsettings.h"
|
||||
#include "../qmuparser/qmudef.h"
|
||||
#include "../qmuparser/qmutokenparser.h"
|
||||
#include "../vpatterndb/vtranslatevars.h"
|
||||
#include "../vpatterndb/calculator.h"
|
||||
#include "../vtools/dialogs/support/dialogeditwrongformula.h"
|
||||
|
||||
#define DIALOG_MAX_FORMULA_HEIGHT 64
|
||||
|
||||
namespace
|
||||
{
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
|
||||
template <typename T>
|
||||
void Move(QVector<T> &vector, int from, int to)
|
||||
{
|
||||
Q_ASSERT_X(from >= 0 && from < vector.size(), "QVector::move(int,int)", "'from' is out-of-range");
|
||||
Q_ASSERT_X(to >= 0 && to < vector.size(), "QVector::move(int,int)", "'to' is out-of-range");
|
||||
if (from == to) // don't detach when no-op
|
||||
{
|
||||
return;
|
||||
}
|
||||
T * const b = vector.begin();
|
||||
if (from < to)
|
||||
{
|
||||
std::rotate(b + from, b + from + 1, b + to + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::rotate(b + to, b + from, b + from + 1);
|
||||
}
|
||||
}
|
||||
#endif // QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DialogFinalMeasurements::DialogFinalMeasurements(VPattern *doc, QWidget *parent)
|
||||
: QDialog(parent),
|
||||
ui(new Ui::DialogFinalMeasurements),
|
||||
m_doc(doc),
|
||||
m_data(doc->GetCompleteData()),
|
||||
m_measurements(doc->GetFinalMeasurements()),
|
||||
m_search(),
|
||||
formulaBaseHeight(0),
|
||||
m_isInitialized(false)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->lineEditName->setClearButtonEnabled(true);
|
||||
ui->lineEditFind->setClearButtonEnabled(true);
|
||||
|
||||
ui->lineEditFind->installEventFilter(this);
|
||||
|
||||
m_search = QSharedPointer<VTableSearch>(new VTableSearch(ui->tableWidget));
|
||||
|
||||
formulaBaseHeight = ui->plainTextEditFormula->height();
|
||||
ui->plainTextEditFormula->installEventFilter(this);
|
||||
|
||||
qApp->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
|
||||
|
||||
qCDebug(vDialog, "Showing variables.");
|
||||
ShowUnits();
|
||||
|
||||
const bool freshCall = true;
|
||||
FillFinalMeasurements(freshCall);
|
||||
|
||||
connect(m_doc, &VPattern::FullUpdateFromFile, this, &DialogFinalMeasurements::FullUpdateFromFile);
|
||||
|
||||
ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression(
|
||||
QLatin1String("^$|")+NameRegExp()), this));
|
||||
|
||||
connect(ui->tableWidget, &QTableWidget::itemSelectionChanged, this,
|
||||
&DialogFinalMeasurements::ShowFinalMeasurementDetails);
|
||||
|
||||
connect(ui->toolButtonAdd, &QToolButton::clicked, this, &DialogFinalMeasurements::Add);
|
||||
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &DialogFinalMeasurements::Remove);
|
||||
connect(ui->toolButtonUp, &QToolButton::clicked, this, &DialogFinalMeasurements::MoveUp);
|
||||
connect(ui->toolButtonDown, &QToolButton::clicked, this, &DialogFinalMeasurements::MoveDown);
|
||||
connect(ui->pushButtonGrow, &QPushButton::clicked, this, &DialogFinalMeasurements::DeployFormula);
|
||||
connect(ui->toolButtonExpr, &QToolButton::clicked, this, &DialogFinalMeasurements::Fx);
|
||||
connect(ui->lineEditName, &QLineEdit::textEdited, this, &DialogFinalMeasurements::SaveName);
|
||||
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this,
|
||||
&DialogFinalMeasurements::SaveDescription);
|
||||
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogFinalMeasurements::SaveFormula);
|
||||
connect(ui->lineEditFind, &QLineEdit::textEdited, this, [this](const QString &term){m_search->Find(term);});
|
||||
connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this](){m_search->FindPrevious();});
|
||||
connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this](){m_search->FindNext();});
|
||||
|
||||
connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state)
|
||||
{
|
||||
ui->toolButtonFindPrevious->setEnabled(state);
|
||||
});
|
||||
|
||||
connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state)
|
||||
{
|
||||
ui->toolButtonFindNext->setEnabled(state);
|
||||
});
|
||||
|
||||
if (ui->tableWidget->rowCount() > 0)
|
||||
{
|
||||
ui->tableWidget->selectRow(0);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
DialogFinalMeasurements::~DialogFinalMeasurements()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
ui->plainTextEditFormula->blockSignals(true);
|
||||
ui->lineEditName->blockSignals(true);
|
||||
ui->plainTextEditDescription->blockSignals(true);
|
||||
|
||||
QDialog::closeEvent(event);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::changeEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
// retranslate designer form (single inheritance approach)
|
||||
ui->retranslateUi(this);
|
||||
FullUpdateFromFile();
|
||||
}
|
||||
// remember to call base class implementation
|
||||
QDialog::changeEvent(event);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool DialogFinalMeasurements::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().decimalPoint());
|
||||
}
|
||||
else
|
||||
{
|
||||
textEdit->insert(QLocale::c().decimalPoint());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// pass the event on to the parent class
|
||||
return QDialog::eventFilter(object, event);
|
||||
}
|
||||
return false;// pass the event to the widget
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::showEvent(QShowEvent *event)
|
||||
{
|
||||
QDialog::showEvent(event);
|
||||
if ( event->spontaneous() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// do your init stuff here
|
||||
|
||||
const QSize sz = qApp->Settings()->GetFinalMeasurementsDialogSize();
|
||||
if (not sz.isEmpty())
|
||||
{
|
||||
resize(sz);
|
||||
}
|
||||
|
||||
m_isInitialized = true;//first show windows are held
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
// remember the size for the next time this dialog is opened, but only
|
||||
// if widget was already initialized, which rules out the resize at
|
||||
// dialog creating, which would
|
||||
if (m_isInitialized)
|
||||
{
|
||||
qApp->Settings()->SetFinalMeasurementsDialogSize(size());
|
||||
}
|
||||
QDialog::resizeEvent(event);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::ShowFinalMeasurementDetails()
|
||||
{
|
||||
if (ui->tableWidget->rowCount() > 0 && m_measurements.size() == ui->tableWidget->rowCount())
|
||||
{
|
||||
EnableDetails(true);
|
||||
|
||||
const VFinalMeasurement &m = m_measurements.at(ui->tableWidget->currentRow());
|
||||
|
||||
ui->lineEditName->blockSignals(true);
|
||||
ui->lineEditName->setText(m.name);
|
||||
ui->lineEditName->blockSignals(false);
|
||||
|
||||
ui->plainTextEditDescription->blockSignals(true);
|
||||
ui->plainTextEditDescription->setPlainText(m.description);
|
||||
ui->plainTextEditDescription->blockSignals(false);
|
||||
|
||||
EvalUserFormula(m.formula, false);
|
||||
ui->plainTextEditFormula->blockSignals(true);
|
||||
|
||||
const QString formula = VTranslateVars::TryFormulaToUser(m.formula, qApp->Settings()->GetOsSeparator());
|
||||
|
||||
ui->plainTextEditFormula->setPlainText(formula);
|
||||
ui->plainTextEditFormula->blockSignals(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableDetails(false);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::Add()
|
||||
{
|
||||
const int currentRow = ui->tableWidget->currentRow()+1;
|
||||
|
||||
VFinalMeasurement m;
|
||||
m.name = tr("measurement");
|
||||
m.formula = "0";
|
||||
|
||||
m_measurements.append(m);
|
||||
|
||||
UpdateTree();
|
||||
ui->tableWidget->selectRow(currentRow);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::Remove()
|
||||
{
|
||||
const int row = ui->tableWidget->currentRow();
|
||||
|
||||
if (row == -1 || row >= m_measurements.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_measurements.remove(row);
|
||||
|
||||
UpdateTree();
|
||||
|
||||
if (ui->tableWidget->rowCount() > 0)
|
||||
{
|
||||
ui->tableWidget->selectRow(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableDetails(false);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::MoveUp()
|
||||
{
|
||||
const int row = ui->tableWidget->currentRow();
|
||||
|
||||
if (row == -1 || row == 0 || row >= m_measurements.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
|
||||
Move(m_measurements, row, row-1);
|
||||
#else
|
||||
m_measurements.move(row, row-1);
|
||||
#endif
|
||||
UpdateTree();
|
||||
|
||||
ui->tableWidget->selectRow(row-1);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::MoveDown()
|
||||
{
|
||||
const int row = ui->tableWidget->currentRow();
|
||||
|
||||
if (row == -1 || row == ui->tableWidget->rowCount()-1 || row >= m_measurements.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
|
||||
Move(m_measurements, row, row+1);
|
||||
#else
|
||||
m_measurements.move(row, row+1);
|
||||
#endif
|
||||
UpdateTree();
|
||||
|
||||
ui->tableWidget->selectRow(row+1);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::SaveName(const QString &text)
|
||||
{
|
||||
const int row = ui->tableWidget->currentRow();
|
||||
|
||||
if (row == -1 || row >= m_measurements.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_measurements[row].name = text.isEmpty() ? tr("measurement") : text;
|
||||
|
||||
UpdateTree();
|
||||
|
||||
ui->tableWidget->blockSignals(true);
|
||||
ui->tableWidget->selectRow(row);
|
||||
ui->tableWidget->blockSignals(false);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::SaveDescription()
|
||||
{
|
||||
const int row = ui->tableWidget->currentRow();
|
||||
|
||||
if (row == -1 || row >= m_measurements.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const QTextCursor cursor = ui->plainTextEditDescription->textCursor();
|
||||
|
||||
m_measurements[row].description = ui->plainTextEditDescription->toPlainText();
|
||||
|
||||
UpdateTree();
|
||||
|
||||
ui->tableWidget->blockSignals(true);
|
||||
ui->tableWidget->selectRow(row);
|
||||
ui->tableWidget->blockSignals(false);
|
||||
ui->plainTextEditDescription->setTextCursor(cursor);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::SaveFormula()
|
||||
{
|
||||
const int row = ui->tableWidget->currentRow();
|
||||
|
||||
if (row == -1 || row >= m_measurements.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace line return character with spaces for calc if exist
|
||||
QString text = ui->plainTextEditFormula->toPlainText();
|
||||
text.replace("\n", " ");
|
||||
|
||||
QTableWidgetItem *formulaField = ui->tableWidget->item(row, 2);
|
||||
if (formulaField->text() == text)
|
||||
{
|
||||
QTableWidgetItem *result = ui->tableWidget->item(row, 1);
|
||||
//Show unit in dialog lable (cm, mm or inch)
|
||||
const QString postfix = 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 = UnitsToStr(qApp->patternUnit());
|
||||
ui->labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (not EvalUserFormula(text, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m_measurements[row].formula = qApp->TrVars()->FormulaFromUser(text, qApp->Settings()->GetOsSeparator());
|
||||
}
|
||||
catch (qmu::QmuParserError &e) // Just in case something bad will happen
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
return;
|
||||
}
|
||||
|
||||
const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
||||
|
||||
UpdateTree();
|
||||
|
||||
ui->tableWidget->blockSignals(true);
|
||||
ui->tableWidget->selectRow(row);
|
||||
ui->tableWidget->blockSignals(false);
|
||||
ui->plainTextEditFormula->setTextCursor(cursor);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::DeployFormula()
|
||||
{
|
||||
const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
||||
|
||||
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")));
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
ui->plainTextEditFormula->setFocus();
|
||||
ui->plainTextEditFormula->setTextCursor(cursor);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::Fx()
|
||||
{
|
||||
const int row = ui->tableWidget->currentRow();
|
||||
|
||||
if (row == -1 || row >= m_measurements.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QScopedPointer<DialogEditWrongFormula> dialog(new DialogEditWrongFormula(&m_data, NULL_ID, this));
|
||||
dialog->setWindowTitle(tr("Edit measurement"));
|
||||
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText().replace("\n", " "),
|
||||
qApp->Settings()->GetOsSeparator()));
|
||||
const QString postfix = UnitsToStr(qApp->patternUnit(), true);
|
||||
dialog->setPostfix(postfix);//Show unit in dialog lable (cm, mm or inch)
|
||||
|
||||
if (dialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
m_measurements[row].formula = dialog->GetFormula();
|
||||
UpdateTree();
|
||||
|
||||
ui->tableWidget->selectRow(row);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::FullUpdateFromFile()
|
||||
{
|
||||
m_data = m_doc->GetCompleteData();
|
||||
m_measurements = m_doc->GetFinalMeasurements();
|
||||
|
||||
FillFinalMeasurements();
|
||||
|
||||
m_search->RefreshList(ui->lineEditFind->text());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::FillFinalMeasurements(bool freshCall)
|
||||
{
|
||||
ui->tableWidget->blockSignals(true);
|
||||
ui->tableWidget->clearContents();
|
||||
|
||||
ui->tableWidget->setRowCount(m_measurements.size());
|
||||
for (int i=0; i < m_measurements.size(); ++i)
|
||||
{
|
||||
const VFinalMeasurement &m = m_measurements.at(i);
|
||||
|
||||
AddCell(m.name, i, 0, Qt::AlignVCenter); // name
|
||||
|
||||
bool ok = true;
|
||||
const qreal result = EvalFormula(m.formula, ok);
|
||||
AddCell(qApp->LocaleToString(result), i, 1, Qt::AlignHCenter | Qt::AlignVCenter, ok); // calculated value
|
||||
|
||||
const QString formula = VTranslateVars::TryFormulaFromUser(m.formula, qApp->Settings()->GetOsSeparator());
|
||||
AddCell(formula, i, 2, Qt::AlignVCenter); // formula
|
||||
|
||||
}
|
||||
|
||||
if (freshCall)
|
||||
{
|
||||
ui->tableWidget->resizeColumnsToContents();
|
||||
ui->tableWidget->resizeRowsToContents();
|
||||
}
|
||||
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
|
||||
ui->tableWidget->blockSignals(false);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::ShowUnits()
|
||||
{
|
||||
const QString unit = UnitsToStr(qApp->patternUnit());
|
||||
|
||||
{
|
||||
// calculated value
|
||||
const QString header = ui->tableWidget->horizontalHeaderItem(1)->text();
|
||||
const QString unitHeader = QString("%1 (%2)").arg(header).arg(unit);
|
||||
ui->tableWidget->horizontalHeaderItem(1)->setText(unitHeader);
|
||||
}
|
||||
|
||||
{
|
||||
// formula
|
||||
const QString header = ui->tableWidget->horizontalHeaderItem(2)->text();
|
||||
const QString unitHeader = QString("%1 (%2)").arg(header).arg(unit);
|
||||
ui->tableWidget->horizontalHeaderItem(2)->setText(unitHeader);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::AddCell(const QString &text, int row, int column, int aligment, bool ok)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
ui->tableWidget->setItem(row, column, item);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool DialogFinalMeasurements::EvalUserFormula(const QString &formula, bool fromUser)
|
||||
{
|
||||
const QString postfix = UnitsToStr(qApp->patternUnit());//Show unit in dialog lable (cm, mm or inch)
|
||||
if (formula.isEmpty())
|
||||
{
|
||||
ui->labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field."));
|
||||
ui->labelCalculatedValue->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", " ");
|
||||
QScopedPointer<Calculator> cal(new Calculator());
|
||||
const qreal result = cal->EvalFormula(m_data.DataVariables(), f);
|
||||
|
||||
if (qIsInf(result) || qIsNaN(result))
|
||||
{
|
||||
ui->labelCalculatedValue->setText(tr("Error") + " (" + postfix + ").");
|
||||
ui->labelCalculatedValue->setToolTip(tr("Invalid result. Value is infinite or NaN. Please, check your "
|
||||
"calculations."));
|
||||
return false;
|
||||
}
|
||||
|
||||
ui->labelCalculatedValue->setText(qApp->LocaleToString(result) + " " + postfix);
|
||||
ui->labelCalculatedValue->setToolTip(tr("Value"));
|
||||
return true;
|
||||
}
|
||||
catch (qmu::QmuParserError &e)
|
||||
{
|
||||
ui->labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " +
|
||||
tr("Parser error: %1").arg(e.GetMsg()));
|
||||
ui->labelCalculatedValue->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::Controls()
|
||||
{
|
||||
ui->toolButtonRemove->setEnabled(ui->tableWidget->rowCount() > 0);
|
||||
|
||||
if (ui->tableWidget->rowCount() >= 2)
|
||||
{
|
||||
if (ui->tableWidget->currentRow() == 0)
|
||||
{
|
||||
ui->toolButtonUp->setEnabled(false);
|
||||
ui->toolButtonDown->setEnabled(true);
|
||||
}
|
||||
else if (ui->tableWidget->currentRow() == ui->tableWidget->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 DialogFinalMeasurements::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);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void DialogFinalMeasurements::UpdateTree()
|
||||
{
|
||||
int row = ui->tableWidget->currentRow();
|
||||
FillFinalMeasurements();
|
||||
ui->tableWidget->selectRow(row);
|
||||
|
||||
m_search->RefreshList(ui->lineEditFind->text());
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
qreal DialogFinalMeasurements::EvalFormula(const QString &formula, bool &ok)
|
||||
{
|
||||
qreal result = 0;
|
||||
if (formula.isEmpty())
|
||||
{
|
||||
ok = false;
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
QString f = formula;
|
||||
// Replace line return character with spaces for calc if exist
|
||||
f.replace("\n", " ");
|
||||
QScopedPointer<Calculator> cal(new Calculator());
|
||||
result = cal->EvalFormula(m_data.DataVariables(), f);
|
||||
|
||||
if (qIsInf(result) || qIsNaN(result))
|
||||
{
|
||||
ok = false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (qmu::QmuParserError &)
|
||||
{
|
||||
ok = false;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ok = true;
|
||||
return result;
|
||||
}
|
102
src/app/valentina/dialogs/dialogfinalmeasurements.h
Normal file
102
src/app/valentina/dialogs/dialogfinalmeasurements.h
Normal file
|
@ -0,0 +1,102 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file dialogfinalmeasurements.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 26 9, 2017
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentine project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2017 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 DIALOGFINALMEASUREMENTS_H
|
||||
#define DIALOGFINALMEASUREMENTS_H
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "../vmisc/vtablesearch.h"
|
||||
#include "../vpatterndb/vcontainer.h"
|
||||
#include "../xml/vpattern.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class DialogFinalMeasurements;
|
||||
}
|
||||
|
||||
class DialogFinalMeasurements : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DialogFinalMeasurements(VPattern *doc, QWidget *parent = nullptr);
|
||||
virtual ~DialogFinalMeasurements();
|
||||
|
||||
QVector<VFinalMeasurement> FinalMeasurements() const;
|
||||
|
||||
protected:
|
||||
virtual void closeEvent ( QCloseEvent * event ) Q_DECL_OVERRIDE;
|
||||
virtual void changeEvent ( QEvent * event) Q_DECL_OVERRIDE;
|
||||
virtual bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE;
|
||||
virtual void showEvent( QShowEvent *event ) Q_DECL_OVERRIDE;
|
||||
virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
|
||||
private slots:
|
||||
void ShowFinalMeasurementDetails();
|
||||
void Add();
|
||||
void Remove();
|
||||
void MoveUp();
|
||||
void MoveDown();
|
||||
void SaveName(const QString &text);
|
||||
void SaveDescription();
|
||||
void SaveFormula();
|
||||
void DeployFormula();
|
||||
void Fx();
|
||||
void FullUpdateFromFile();
|
||||
private:
|
||||
Q_DISABLE_COPY(DialogFinalMeasurements)
|
||||
Ui::DialogFinalMeasurements *ui;
|
||||
/** @brief doc dom document container */
|
||||
VPattern *m_doc;
|
||||
VContainer m_data;
|
||||
QVector<VFinalMeasurement> m_measurements;
|
||||
QSharedPointer<VTableSearch> m_search;
|
||||
int formulaBaseHeight;
|
||||
bool m_isInitialized;
|
||||
|
||||
void FillFinalMeasurements(bool freshCall = false);
|
||||
|
||||
void ShowUnits();
|
||||
|
||||
void AddCell(const QString &text, int row, int column, int aligment, bool ok = true);
|
||||
bool EvalUserFormula(const QString &formula, bool fromUser);
|
||||
void Controls();
|
||||
void EnableDetails(bool enabled);
|
||||
|
||||
void UpdateTree();
|
||||
|
||||
qreal EvalFormula(const QString &formula, bool &ok);
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
inline QVector<VFinalMeasurement> DialogFinalMeasurements::FinalMeasurements() const
|
||||
{
|
||||
return m_measurements;
|
||||
}
|
||||
|
||||
#endif // DIALOGFINALMEASUREMENTS_H
|
469
src/app/valentina/dialogs/dialogfinalmeasurements.ui
Normal file
469
src/app/valentina/dialogs/dialogfinalmeasurements.ui
Normal file
|
@ -0,0 +1,469 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DialogFinalMeasurements</class>
|
||||
<widget class="QDialog" name="DialogFinalMeasurements">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>717</width>
|
||||
<height>518</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelFind">
|
||||
<property name="text">
|
||||
<string>Find:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEditFind">
|
||||
<property name="placeholderText">
|
||||
<string>Search</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButtonFindPrevious">
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="go-previous" resource="../../../libs/vmisc/share/resources/theme.qrc">
|
||||
<normaloff>:/icons/win.icon.theme/16x16/actions/go-previous.png</normaloff>:/icons/win.icon.theme/16x16/actions/go-previous.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButtonFindNext">
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="go-next" resource="../../../libs/vmisc/share/resources/theme.qrc">
|
||||
<normaloff>:/icons/win.icon.theme/16x16/actions/go-next.png</normaloff>:/icons/win.icon.theme/16x16/actions/go-next.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>8</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>150</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>120</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderMinimumSectionSize">
|
||||
<number>70</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderDefaultSectionSize">
|
||||
<number>25</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderMinimumSectionSize">
|
||||
<number>8</number>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderStretchLastSection">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>The calculated value</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Formula</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBoxDetails">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>4</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>236</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Details</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Details</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>5000</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item alignment="Qt::AlignRight">
|
||||
<widget class="QToolButton" name="toolButtonAdd">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="list-add">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignLeft">
|
||||
<widget class="QToolButton" name="toolButtonRemove">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="list-remove">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEditName">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="labelCalculated">
|
||||
<property name="text">
|
||||
<string>Calculated value:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="labelCalculatedValue">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="labelFormula">
|
||||
<property name="text">
|
||||
<string>Formula:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayoutValue">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="plainTextEditFormula">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>28</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Calculation</string>
|
||||
</property>
|
||||
<property name="tabChangesFocus">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonGrow">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>18</width>
|
||||
<height>18</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeIncrement">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Show full calculation in message box</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="go-down">
|
||||
<normaloff>../../../libs/vtools/dialogs/support</normaloff>../../../libs/vtools/dialogs/support</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButtonExpr">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Formula wizard</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../libs/vmisc/share/resources/icon.qrc">
|
||||
<normaloff>:/icon/24x24/fx.png</normaloff>:/icon/24x24/fx.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Description:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QPlainTextEdit" name="plainTextEditDescription">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item alignment="Qt::AlignLeft">
|
||||
<widget class="QToolButton" name="toolButtonUp">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Move measurement up</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="go-up">
|
||||
<normaloff>../../tape</normaloff>../../tape</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignLeft">
|
||||
<widget class="QToolButton" name="toolButtonDown">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Move measurement down</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="go-down">
|
||||
<normaloff>../../tape</normaloff>../../tape</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>5000</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../../libs/vmisc/share/resources/icon.qrc"/>
|
||||
<include location="../../../libs/vmisc/share/resources/theme.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>DialogFinalMeasurements</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>227</x>
|
||||
<y>523</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>DialogFinalMeasurements</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>295</x>
|
||||
<y>529</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -35,5 +35,6 @@
|
|||
#include "dialognewpattern.h"
|
||||
#include "dialogaboutapp.h"
|
||||
#include "dialogpreferences.h"
|
||||
#include "dialogfinalmeasurements.h"
|
||||
|
||||
#endif // DIALOGS_H
|
||||
|
|
|
@ -19,7 +19,8 @@ HEADERS += \
|
|||
$$PWD/configpages/preferencespathpage.h \
|
||||
$$PWD/dialogdatetimeformats.h \
|
||||
$$PWD/dialogknownmaterials.h \
|
||||
$$PWD/dialogpatternmaterials.h
|
||||
$$PWD/dialogpatternmaterials.h \
|
||||
$$PWD/dialogfinalmeasurements.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/dialogincrements.cpp \
|
||||
|
@ -38,7 +39,8 @@ SOURCES += \
|
|||
$$PWD/configpages/preferencespathpage.cpp \
|
||||
$$PWD/dialogdatetimeformats.cpp \
|
||||
$$PWD/dialogknownmaterials.cpp \
|
||||
$$PWD/dialogpatternmaterials.cpp
|
||||
$$PWD/dialogpatternmaterials.cpp \
|
||||
$$PWD/dialogfinalmeasurements.cpp
|
||||
|
||||
FORMS += \
|
||||
$$PWD/dialogincrements.ui \
|
||||
|
@ -57,4 +59,5 @@ FORMS += \
|
|||
$$PWD/configpages/preferencespathpage.ui \
|
||||
$$PWD/dialogdatetimeformats.ui \
|
||||
$$PWD/dialogknownmaterials.ui \
|
||||
$$PWD/dialogpatternmaterials.ui
|
||||
$$PWD/dialogpatternmaterials.ui \
|
||||
$$PWD/dialogfinalmeasurements.ui
|
||||
|
|
|
@ -117,7 +117,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
patternReadOnly(false),
|
||||
dialogTable(nullptr),
|
||||
dialogTool(),
|
||||
dialogHistory(nullptr), comboBoxDraws(nullptr), patternPieceLabel(nullptr), mode(Draw::Calculation),
|
||||
dialogHistory(nullptr),
|
||||
dialogFMeasurements(nullptr),
|
||||
comboBoxDraws(nullptr), patternPieceLabel(nullptr), mode(Draw::Calculation),
|
||||
currentDrawIndex(0), currentToolBoxIndex(0),
|
||||
isDockToolOptionsVisible(true),
|
||||
isDockGroupsVisible(true),
|
||||
|
@ -2833,6 +2835,8 @@ void MainWindow::Clear()
|
|||
ui->actionZoomOriginal->setEnabled(false);
|
||||
ui->actionHistory->setEnabled(false);
|
||||
ui->actionTable->setEnabled(false);
|
||||
ui->actionExportIncrementsToCSV->setEnabled(false);
|
||||
ui->actionFinalMeasurements->setEnabled(false);
|
||||
ui->actionLast_tool->setEnabled(false);
|
||||
ui->actionShowCurveDetails->setEnabled(false);
|
||||
ui->actionLoadIndividual->setEnabled(false);
|
||||
|
@ -3078,6 +3082,8 @@ void MainWindow::SetEnableWidgets(bool enable)
|
|||
ui->actionDetails->setEnabled(enable);
|
||||
ui->actionLayout->setEnabled(enable);
|
||||
ui->actionTable->setEnabled(enable && drawStage);
|
||||
ui->actionExportIncrementsToCSV->setEnabled(enable);
|
||||
ui->actionFinalMeasurements->setEnabled(enable);
|
||||
ui->actionZoomFitBest->setEnabled(enable);
|
||||
ui->actionZoomFitBestCurrent->setEnabled(enable && drawStage);
|
||||
ui->actionZoomOriginal->setEnabled(enable);
|
||||
|
@ -3993,6 +3999,27 @@ void MainWindow::CreateActions()
|
|||
}
|
||||
});
|
||||
|
||||
connect(ui->actionFinalMeasurements, &QAction::triggered, this, [this]()
|
||||
{
|
||||
if (dialogFMeasurements.isNull())
|
||||
{
|
||||
dialogFMeasurements = new DialogFinalMeasurements(doc, this);
|
||||
connect(dialogFMeasurements.data(), &DialogFinalMeasurements::finished, this, [this](int result)
|
||||
{
|
||||
if (result == QDialog::Accepted)
|
||||
{
|
||||
doc->SetFinalMeasurements(dialogFMeasurements->FinalMeasurements());
|
||||
}
|
||||
delete dialogFMeasurements;
|
||||
});
|
||||
dialogFMeasurements->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
dialogFMeasurements->activateWindow();
|
||||
}
|
||||
});
|
||||
|
||||
connect(ui->actionAbout_Qt, &QAction::triggered, this, [this]()
|
||||
{
|
||||
QMessageBox::aboutQt(this, tr("About Qt"));
|
||||
|
|
|
@ -47,6 +47,7 @@ class QLabel;
|
|||
class DialogIncrements;
|
||||
class DialogTool;
|
||||
class DialogHistory;
|
||||
class DialogFinalMeasurements;
|
||||
class VWidgetGroups;
|
||||
class VWidgetDetails;
|
||||
class QToolButton;
|
||||
|
@ -229,6 +230,7 @@ private:
|
|||
QPointer<DialogIncrements> dialogTable;
|
||||
QSharedPointer<DialogTool> dialogTool;
|
||||
QPointer<DialogHistory> dialogHistory;
|
||||
QPointer<DialogFinalMeasurements> dialogFMeasurements;
|
||||
|
||||
/** @brief comboBoxDraws comboc who show name of pattern peaces. */
|
||||
QComboBox *comboBoxDraws;
|
||||
|
|
|
@ -1699,12 +1699,16 @@
|
|||
</property>
|
||||
<addaction name="actionOpenTape"/>
|
||||
<addaction name="actionEditCurrent"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionUnloadMeasurements"/>
|
||||
<addaction name="actionLoadIndividual"/>
|
||||
<addaction name="actionLoadMultisize"/>
|
||||
<addaction name="actionSyncMeasurements"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionTable"/>
|
||||
<addaction name="actionExportIncrementsToCSV"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionFinalMeasurements"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuWindow">
|
||||
<property name="title">
|
||||
|
@ -2649,6 +2653,9 @@
|
|||
</property>
|
||||
</action>
|
||||
<action name="actionExportIncrementsToCSV">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Export increments to CSV</string>
|
||||
</property>
|
||||
|
@ -2657,6 +2664,9 @@
|
|||
</property>
|
||||
</action>
|
||||
<action name="actionZoomFitBestCurrent">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Zoom fit best current</string>
|
||||
</property>
|
||||
|
@ -2675,6 +2685,14 @@
|
|||
<string>Label template editor</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionFinalMeasurements">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Final measurements</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
|
@ -2685,8 +2703,8 @@
|
|||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="share/resources/toolicon.qrc"/>
|
||||
<include location="../../libs/vmisc/share/resources/icon.qrc"/>
|
||||
<include location="share/resources/toolicon.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -78,6 +78,7 @@ const QString settingPreferenceDialogSize = QStringLiteral("preferenceDia
|
|||
const QString settingToolSeamAllowanceDialogSize = QStringLiteral("toolSeamAllowanceDialogSize");
|
||||
const QString settingIncrementsDialogSize = QStringLiteral("toolIncrementsDialogSize");
|
||||
const QString settingFormulaWizardDialogSize = QStringLiteral("formulaWizardDialogSize");
|
||||
const QString settingFinalMeasurementsDialogSize = QStringLiteral("finalMeasurementsDialogSize");
|
||||
const QString settingLatestSkippedVersion = QStringLiteral("lastestSkippedVersion");
|
||||
const QString settingDateOfLastRemind = QStringLiteral("dateOfLastRemind");
|
||||
|
||||
|
@ -616,6 +617,18 @@ void VCommonSettings::SetIncrementsDialogSize(const QSize &sz)
|
|||
setValue(settingIncrementsDialogSize, sz);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QSize VCommonSettings::GetFinalMeasurementsDialogSize() const
|
||||
{
|
||||
return value(settingFinalMeasurementsDialogSize, QSize(0, 0)).toSize();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VCommonSettings::SetFinalMeasurementsDialogSize(const QSize &sz)
|
||||
{
|
||||
setValue(settingFinalMeasurementsDialogSize, sz);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
int VCommonSettings::GetLatestSkippedVersion() const
|
||||
{
|
||||
|
|
|
@ -129,6 +129,9 @@ public:
|
|||
QSize GetIncrementsDialogSize() const;
|
||||
void SetIncrementsDialogSize(const QSize& sz);
|
||||
|
||||
QSize GetFinalMeasurementsDialogSize() const;
|
||||
void SetFinalMeasurementsDialogSize(const QSize& sz);
|
||||
|
||||
int GetLatestSkippedVersion() const;
|
||||
void SetLatestSkippedVersion(int value);
|
||||
|
||||
|
|
|
@ -1069,6 +1069,20 @@ QString VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator)
|
|||
return newFormula;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QString VTranslateVars::TryFormulaToUser(const QString &formula, bool osSeparator)
|
||||
{
|
||||
try
|
||||
{
|
||||
return qApp->TrVars()->FormulaToUser(formula, osSeparator);
|
||||
}
|
||||
catch (qmu::QmuParserError &e)// In case something bad will happen
|
||||
{
|
||||
Q_UNUSED(e)
|
||||
return formula;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTranslateVars::Retranslate()
|
||||
{
|
||||
|
|
|
@ -62,7 +62,9 @@ public:
|
|||
|
||||
QString FormulaFromUser(const QString &formula, bool osSeparator) const;
|
||||
static QString TryFormulaFromUser(const QString &formula, bool osSeparator);
|
||||
|
||||
QString FormulaToUser(const QString &formula, bool osSeparator) const;
|
||||
static QString TryFormulaToUser(const QString &formula, bool osSeparator);
|
||||
|
||||
virtual void Retranslate() Q_DECL_OVERRIDE;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user