2015-07-24 12:06:39 +02:00
|
|
|
|
/************************************************************************
|
2015-07-10 11:49:37 +02:00
|
|
|
|
**
|
|
|
|
|
** @file tmainwindow.cpp
|
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
|
** @date 10 7, 2015
|
|
|
|
|
**
|
|
|
|
|
** @brief
|
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-07-10 11:49:37 +02:00
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
|
** Copyright (C) 2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-07-10 11:49:37 +02:00
|
|
|
|
**
|
|
|
|
|
** 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 "tmainwindow.h"
|
|
|
|
|
#include "ui_tmainwindow.h"
|
2015-07-12 19:38:30 +02:00
|
|
|
|
#include "dialogs/dialogabouttape.h"
|
2015-07-13 12:48:29 +02:00
|
|
|
|
#include "dialogs/dialognewmeasurements.h"
|
2015-08-01 11:39:32 +02:00
|
|
|
|
#include "dialogs/dialogmdatabase.h"
|
2017-04-12 14:50:48 +02:00
|
|
|
|
#include "dialogs/dialogtapepreferences.h"
|
2020-09-28 15:38:32 +02:00
|
|
|
|
#include "dialogs/dialogsetupmultisize.h"
|
2020-10-05 14:14:38 +02:00
|
|
|
|
#include "dialogs/dialogrestrictdimension.h"
|
2020-10-08 12:34:38 +02:00
|
|
|
|
#include "dialogs/dialogdimensionlabels.h"
|
2020-10-10 18:31:23 +02:00
|
|
|
|
#include "dialogs/dialogmeasurementscsvcolumns.h"
|
2022-02-14 12:26:24 +01:00
|
|
|
|
#include "dialogs/dialogdimensioncustomnames.h"
|
2019-07-10 11:42:37 +02:00
|
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2015-07-21 17:28:20 +02:00
|
|
|
|
#include "../vpatterndb/calculator.h"
|
2017-06-01 12:04:25 +02:00
|
|
|
|
#include "../vpatterndb/pmsystems.h"
|
2018-01-31 13:34:50 +01:00
|
|
|
|
#include "../vpatterndb/measurements.h"
|
2015-07-22 11:44:31 +02:00
|
|
|
|
#include "../ifc/ifcdef.h"
|
2015-07-25 14:59:40 +02:00
|
|
|
|
#include "../ifc/xml/vvitconverter.h"
|
|
|
|
|
#include "../ifc/xml/vvstconverter.h"
|
2015-08-11 16:52:18 +02:00
|
|
|
|
#include "../ifc/xml/vpatternconverter.h"
|
2015-09-28 20:54:41 +02:00
|
|
|
|
#include "../vmisc/vsysexits.h"
|
2016-06-01 15:37:42 +02:00
|
|
|
|
#include "../vmisc/qxtcsvmodel.h"
|
2018-01-31 13:34:50 +01:00
|
|
|
|
#include "../vmisc/dialogs/dialogexporttocsv.h"
|
2020-01-16 18:09:23 +01:00
|
|
|
|
#include "../vmisc/compatibility.h"
|
2015-08-11 16:52:18 +02:00
|
|
|
|
#include "vlitepattern.h"
|
2015-07-22 11:47:51 +02:00
|
|
|
|
#include "../qmuparser/qmudef.h"
|
2015-07-24 14:06:53 +02:00
|
|
|
|
#include "../vtools/dialogs/support/dialogeditwrongformula.h"
|
2015-08-01 19:09:10 +02:00
|
|
|
|
#include "version.h"
|
2021-10-19 13:43:20 +02:00
|
|
|
|
#include "../vmisc/dialogs/dialogselectlanguage.h"
|
2015-07-24 14:06:53 +02:00
|
|
|
|
#include "mapplication.h" // Should be last because of definning qApp
|
2015-07-10 11:49:37 +02:00
|
|
|
|
|
2019-07-04 16:32:58 +02:00
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
|
|
|
|
|
#include "../vmisc/backport/qscopeguard.h"
|
|
|
|
|
#else
|
|
|
|
|
#include <QScopeGuard>
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QMessageBox>
|
2015-07-21 15:18:10 +02:00
|
|
|
|
#include <QComboBox>
|
2015-07-25 15:37:07 +02:00
|
|
|
|
#include <QProcess>
|
2016-05-24 14:06:35 +02:00
|
|
|
|
#include <QtNumeric>
|
2016-06-01 15:37:42 +02:00
|
|
|
|
#include <QTextCodec>
|
2020-10-03 06:34:25 +02:00
|
|
|
|
#include <QTimer>
|
2015-07-18 14:39:33 +02:00
|
|
|
|
|
2015-12-03 13:07:51 +01:00
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
|
#include <QMimeData>
|
|
|
|
|
#include <QDrag>
|
|
|
|
|
#endif //defined(Q_OS_MAC)
|
|
|
|
|
|
2015-07-21 18:24:47 +02:00
|
|
|
|
#define DIALOG_MAX_FORMULA_HEIGHT 64
|
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
|
QT_WARNING_PUSH
|
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
|
|
|
|
QT_WARNING_DISABLE_INTEL(1418)
|
2015-10-19 15:21:06 +02:00
|
|
|
|
|
2015-08-01 19:09:10 +02:00
|
|
|
|
Q_LOGGING_CATEGORY(tMainWindow, "t.mainwindow")
|
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
|
QT_WARNING_POP
|
2015-10-19 15:21:06 +02:00
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
enum class MUnits : qint8 { Table, Degrees};
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
// We need this enum in case we will add or delete a column. And also make code more readable.
|
2020-10-03 17:52:31 +02:00
|
|
|
|
enum {
|
|
|
|
|
ColumnName = 0,
|
|
|
|
|
ColumnFullName = 1,
|
|
|
|
|
ColumnCalcValue = 2,
|
|
|
|
|
ColumnFormula = 3,
|
|
|
|
|
ColumnBaseValue = 4,
|
|
|
|
|
ColumnShiftA = 5,
|
|
|
|
|
ColumnShiftB = 6,
|
|
|
|
|
ColumnShiftC = 7,
|
|
|
|
|
ColumnCorrection = 8
|
|
|
|
|
};
|
2015-09-29 17:46:00 +02:00
|
|
|
|
|
2015-07-10 11:49:37 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
TMainWindow::TMainWindow(QWidget *parent)
|
2017-04-12 08:49:05 +02:00
|
|
|
|
: VAbstractMainWindow(parent),
|
2015-07-15 09:16:59 +02:00
|
|
|
|
ui(new Ui::TMainWindow),
|
2020-10-03 06:34:25 +02:00
|
|
|
|
formulaBaseHeight(0),
|
2021-11-22 14:24:48 +01:00
|
|
|
|
gradation(new QTimer(this)),
|
|
|
|
|
m_searchHistory(new QMenu(this))
|
2015-07-10 11:49:37 +02:00
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2015-12-09 11:40:43 +01:00
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
|
VAbstractApplication::VApp()->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c());
|
2016-08-25 19:00:03 +02:00
|
|
|
|
|
2015-12-09 11:40:43 +01:00
|
|
|
|
ui->lineEditName->setClearButtonEnabled(true);
|
|
|
|
|
ui->lineEditFullName->setClearButtonEnabled(true);
|
2017-09-19 15:07:48 +02:00
|
|
|
|
ui->lineEditCustomerName->setClearButtonEnabled(true);
|
2015-12-09 11:40:43 +01:00
|
|
|
|
ui->lineEditEmail->setClearButtonEnabled(true);
|
|
|
|
|
|
2016-08-23 20:24:14 +02:00
|
|
|
|
ui->lineEditFind->installEventFilter(this);
|
|
|
|
|
ui->plainTextEditFormula->installEventFilter(this);
|
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search = QSharedPointer<VTableSearch>(new VTableSearch(ui->tableWidget));
|
2015-07-10 13:22:46 +02:00
|
|
|
|
ui->tabWidget->setVisible(false);
|
2015-07-12 16:19:53 +02:00
|
|
|
|
|
2015-07-21 15:18:10 +02:00
|
|
|
|
ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
|
|
|
|
|
ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu);
|
|
|
|
|
|
2019-09-06 21:18:18 +02:00
|
|
|
|
m_recentFileActs.fill(nullptr);
|
2016-02-18 12:18:14 +01:00
|
|
|
|
|
2020-10-03 06:34:25 +02:00
|
|
|
|
connect(gradation, &QTimer::timeout, this, &TMainWindow::GradationChanged);
|
|
|
|
|
|
2015-07-12 16:19:53 +02:00
|
|
|
|
SetupMenu();
|
2021-05-21 19:51:46 +02:00
|
|
|
|
|
2015-08-01 19:09:10 +02:00
|
|
|
|
ReadSettings();
|
2015-12-01 15:38:09 +01:00
|
|
|
|
|
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
|
// On Mac deafault icon size is 32x32.
|
|
|
|
|
ui->toolBarGradation->setIconSize(QSize(24, 24));
|
2015-12-03 09:43:31 +01:00
|
|
|
|
|
2016-06-18 15:09:04 +02:00
|
|
|
|
ui->pushButtonShowInExplorer->setText(tr("Show in Finder"));
|
|
|
|
|
|
2015-12-03 09:43:31 +01:00
|
|
|
|
// Mac OS Dock Menu
|
|
|
|
|
QMenu *menu = new QMenu(this);
|
2015-12-05 10:50:32 +01:00
|
|
|
|
connect(menu, &QMenu::aboutToShow, this, &TMainWindow::AboutToShowDockMenu);
|
|
|
|
|
AboutToShowDockMenu();
|
2017-02-22 07:09:33 +01:00
|
|
|
|
menu->setAsDockMenu();
|
2015-12-03 09:43:31 +01:00
|
|
|
|
#endif //defined(Q_OS_MAC)
|
2021-10-19 13:43:20 +02:00
|
|
|
|
|
|
|
|
|
if (MApplication::VApp()->IsAppInGUIMode())
|
|
|
|
|
{
|
|
|
|
|
QTimer::singleShot(1000, this, &TMainWindow::SetDefaultGUILanguage);
|
|
|
|
|
}
|
2015-07-10 11:49:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
TMainWindow::~TMainWindow()
|
|
|
|
|
{
|
2021-11-22 14:24:48 +01:00
|
|
|
|
ui->lineEditFind->blockSignals(true); // prevents crash
|
2015-10-28 15:22:36 +01:00
|
|
|
|
delete data;
|
|
|
|
|
delete m;
|
2018-08-02 12:48:48 +02:00
|
|
|
|
qDeleteAll(hackedWidgets);
|
2015-07-10 11:49:37 +02:00
|
|
|
|
delete ui;
|
|
|
|
|
}
|
2015-07-10 13:14:55 +02:00
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString TMainWindow::CurrentFile() const
|
|
|
|
|
{
|
|
|
|
|
return curFile;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-08 16:33:37 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::RetranslateTable()
|
|
|
|
|
{
|
2015-09-03 12:31:23 +02:00
|
|
|
|
if (m != nullptr)
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
RefreshTable();
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-09-03 12:31:23 +02:00
|
|
|
|
}
|
2015-08-08 16:33:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 12:23:00 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 06:33:56 +02:00
|
|
|
|
bool TMainWindow::SetDimensionABase(int base)
|
2015-08-18 15:31:21 +02:00
|
|
|
|
{
|
2020-10-03 06:33:56 +02:00
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
|
|
|
|
if (dimensions.isEmpty())
|
2015-08-18 15:31:21 +02:00
|
|
|
|
{
|
2020-10-03 06:33:56 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't provide dimensions")));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-09-07 09:36:53 +02:00
|
|
|
|
|
2020-10-03 06:33:56 +02:00
|
|
|
|
const qint32 i = gradationDimensionA->findData(base);
|
|
|
|
|
if (i != -1)
|
|
|
|
|
{
|
|
|
|
|
gradationDimensionA->setCurrentIndex(i);
|
|
|
|
|
}
|
2019-09-07 09:36:53 +02:00
|
|
|
|
|
2021-01-18 19:43:53 +01:00
|
|
|
|
if (not VFuzzyComparePossibleNulls(base, currentDimensionA))
|
2020-10-03 06:33:56 +02:00
|
|
|
|
{
|
|
|
|
|
qCCritical(tMainWindow, "%s\n", qPrintable(tr("Invalid base value for dimension A")));
|
|
|
|
|
return false;
|
2015-08-18 15:31:21 +02:00
|
|
|
|
}
|
2020-10-03 06:33:56 +02:00
|
|
|
|
return true;
|
2015-08-18 15:31:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 06:33:56 +02:00
|
|
|
|
bool TMainWindow::SetDimensionBBase(int base)
|
2015-08-18 15:31:21 +02:00
|
|
|
|
{
|
2020-10-03 06:33:56 +02:00
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() <= 1)
|
2015-08-18 15:31:21 +02:00
|
|
|
|
{
|
2020-10-03 06:33:56 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't support dimension B")));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-09-07 09:36:53 +02:00
|
|
|
|
|
2020-10-03 06:33:56 +02:00
|
|
|
|
const qint32 i = gradationDimensionB->findData(base);
|
|
|
|
|
if (i != -1)
|
|
|
|
|
{
|
|
|
|
|
gradationDimensionB->setCurrentIndex(i);
|
|
|
|
|
}
|
2019-09-07 09:36:53 +02:00
|
|
|
|
|
2021-01-18 19:43:53 +01:00
|
|
|
|
if (not VFuzzyComparePossibleNulls(base, currentDimensionB))
|
2020-10-03 06:33:56 +02:00
|
|
|
|
{
|
|
|
|
|
qCCritical(tMainWindow, "%s\n", qPrintable(tr("Invalid base value for dimension B")));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
bool TMainWindow::SetDimensionCBase(int base)
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() <= 2)
|
|
|
|
|
{
|
|
|
|
|
qCCritical(tMainWindow, "%s\n", qPrintable(tr("The table doesn't support dimension C")));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const qint32 i = gradationDimensionC->findData(base);
|
|
|
|
|
if (i != -1)
|
|
|
|
|
{
|
|
|
|
|
gradationDimensionC->setCurrentIndex(i);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 19:43:53 +01:00
|
|
|
|
if (not VFuzzyComparePossibleNulls(base, currentDimensionC))
|
2020-10-03 06:33:56 +02:00
|
|
|
|
{
|
|
|
|
|
qCCritical(tMainWindow, "%s\n", qPrintable(tr("Invalid base value for dimension C")));
|
|
|
|
|
return false;
|
2015-08-18 15:31:21 +02:00
|
|
|
|
}
|
2020-10-03 06:33:56 +02:00
|
|
|
|
return true;
|
2015-08-18 15:31:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetPUnit(Unit unit)
|
|
|
|
|
{
|
|
|
|
|
pUnit = unit;
|
2019-03-14 10:53:08 +01:00
|
|
|
|
SetCurrentPatternUnit();
|
2015-08-18 15:31:21 +02:00
|
|
|
|
UpdatePatternUnit();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-10 13:14:55 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-11 11:06:14 +02:00
|
|
|
|
bool TMainWindow::LoadFile(const QString &path)
|
2015-07-12 16:19:53 +02:00
|
|
|
|
{
|
2015-07-25 14:59:40 +02:00
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
2018-03-14 14:39:15 +01:00
|
|
|
|
if (not QFileInfo::exists(path))
|
2015-08-18 16:53:33 +02:00
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("File '%1' doesn't exist!").arg(path)));
|
2021-02-06 14:52:21 +01:00
|
|
|
|
if (MApplication::VApp()->IsTestMode())
|
2015-09-28 20:54:41 +02:00
|
|
|
|
{
|
2015-10-11 11:06:14 +02:00
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
2015-10-01 17:21:13 +02:00
|
|
|
|
}
|
2015-10-11 11:06:14 +02:00
|
|
|
|
return false;
|
2015-08-18 16:53:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
// Check if file already opened
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const QList<TMainWindow*> list = MApplication::VApp()->MainWindows();
|
2021-05-21 17:08:37 +02:00
|
|
|
|
auto w = std::find_if(list.begin(), list.end(),
|
|
|
|
|
[path](TMainWindow *window) { return window->CurrentFile() == path; });
|
|
|
|
|
if (w != list.end())
|
2015-07-25 14:59:40 +02:00
|
|
|
|
{
|
2021-05-21 17:08:37 +02:00
|
|
|
|
(*w)->activateWindow();
|
|
|
|
|
close();
|
|
|
|
|
return false;
|
2015-08-01 19:09:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 01:58:39 +01:00
|
|
|
|
VlpCreateLock(lock, path);
|
2015-09-14 13:53:49 +02:00
|
|
|
|
|
2015-10-09 11:50:37 +02:00
|
|
|
|
if (not lock->IsLocked())
|
2015-08-01 19:09:10 +02:00
|
|
|
|
{
|
2021-05-21 17:08:37 +02:00
|
|
|
|
if (not IgnoreLocking(lock->GetLockError(), path, MApplication::VApp()->IsAppInGUIMode()))
|
2015-10-01 16:59:01 +02:00
|
|
|
|
{
|
2015-12-23 14:26:29 +01:00
|
|
|
|
return false;
|
2015-10-01 17:21:13 +02:00
|
|
|
|
}
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
data = new VContainer(VAbstractApplication::VApp()->TrVars(), &mUnit, VContainer::UniqueNamespace());
|
2015-07-25 14:59:40 +02:00
|
|
|
|
|
|
|
|
|
m = new VMeasurements(data);
|
|
|
|
|
m->setXMLContent(path);
|
|
|
|
|
|
|
|
|
|
mType = m->Type();
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Unknown)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
throw VException(tr("File has unknown format."));
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-12 20:21:48 +02:00
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
2015-07-25 14:59:40 +02:00
|
|
|
|
{
|
|
|
|
|
VVSTConverter converter(path);
|
2018-04-13 07:43:44 +02:00
|
|
|
|
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
|
2018-11-18 08:52:08 +01:00
|
|
|
|
m_curFileFormatVersionStr = converter.GetFormatVersionStr();
|
2017-02-04 12:28:47 +01:00
|
|
|
|
m->setXMLContent(converter.Convert());// Read again after conversion
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VVITConverter converter(path);
|
2018-04-13 07:43:44 +02:00
|
|
|
|
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
|
2018-11-18 08:52:08 +01:00
|
|
|
|
m_curFileFormatVersionStr = converter.GetFormatVersionStr();
|
2017-02-04 12:28:47 +01:00
|
|
|
|
m->setXMLContent(converter.Convert());// Read again after conversion
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 12:45:58 +02:00
|
|
|
|
if (not m->IsDefinedKnownNamesValid())
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
throw VException(tr("File contains invalid known measurement(s)."));
|
2015-09-25 12:45:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 10:19:06 +02:00
|
|
|
|
mUnit = m->Units();
|
2015-08-18 13:53:30 +02:00
|
|
|
|
pUnit = mUnit;
|
2015-07-25 14:59:40 +02:00
|
|
|
|
|
2020-10-07 17:09:27 +02:00
|
|
|
|
currentDimensionA = m->DimensionABase();
|
|
|
|
|
currentDimensionB = m->DimensionBBase();
|
|
|
|
|
currentDimensionC = m->DimensionCBase();
|
2015-07-25 14:59:40 +02:00
|
|
|
|
|
|
|
|
|
ui->labelToolTip->setVisible(false);
|
|
|
|
|
ui->tabWidget->setVisible(true);
|
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
mIsReadOnly = m->IsReadOnly();
|
|
|
|
|
UpdatePadlock(mIsReadOnly);
|
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
SetCurrentFile(path);
|
|
|
|
|
|
|
|
|
|
InitWindow();
|
|
|
|
|
|
2017-04-14 11:04:03 +02:00
|
|
|
|
const bool freshCall = true;
|
|
|
|
|
RefreshData(freshCall);
|
2015-07-25 14:59:40 +02:00
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->rowCount() > 0)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->selectRow(0);
|
|
|
|
|
}
|
2015-07-25 17:18:01 +02:00
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
MeasurementGUI();
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
|
|
|
|
ui->actionImportFromCSV->setEnabled(true);
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
catch (VException &e)
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-07-25 14:59:40 +02:00
|
|
|
|
ui->labelToolTip->setVisible(true);
|
|
|
|
|
ui->tabWidget->setVisible(false);
|
|
|
|
|
delete m;
|
|
|
|
|
m = nullptr;
|
|
|
|
|
delete data;
|
|
|
|
|
data = nullptr;
|
2015-09-15 20:21:51 +02:00
|
|
|
|
lock.reset();
|
2015-10-01 17:21:13 +02:00
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
|
if (MApplication::VApp()->IsTestMode())
|
2015-10-01 17:21:13 +02:00
|
|
|
|
{
|
2015-10-11 11:06:14 +02:00
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
2015-10-01 17:21:13 +02:00
|
|
|
|
}
|
2015-10-11 11:06:14 +02:00
|
|
|
|
return false;
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
return MApplication::VApp()->NewMainWindow()->LoadFile(path);
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-11 11:06:14 +02:00
|
|
|
|
return true;
|
2015-07-12 16:19:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::FileNew()
|
|
|
|
|
{
|
2015-07-15 09:16:59 +02:00
|
|
|
|
if (m == nullptr)
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2015-07-15 09:16:59 +02:00
|
|
|
|
DialogNewMeasurements measurements(this);
|
|
|
|
|
if (measurements.exec() == QDialog::Rejected)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
mUnit = measurements.MUnit();
|
2015-08-18 13:53:30 +02:00
|
|
|
|
pUnit = mUnit;
|
2015-07-16 11:38:54 +02:00
|
|
|
|
mType = measurements.Type();
|
|
|
|
|
|
2020-09-28 15:38:32 +02:00
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
|
|
|
|
{
|
|
|
|
|
DialogSetupMultisize setup(mUnit, this);
|
|
|
|
|
if (setup.exec() == QDialog::Rejected)
|
|
|
|
|
{
|
2022-05-28 16:17:01 +02:00
|
|
|
|
mUnit = Unit::Cm;
|
|
|
|
|
pUnit = mUnit;
|
|
|
|
|
mType = MeasurementsType::Individual;
|
2020-09-28 15:38:32 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
|
data = new VContainer(VAbstractApplication::VApp()->TrVars(), &mUnit, VContainer::UniqueNamespace());
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
2020-10-01 12:32:02 +02:00
|
|
|
|
m = new VMeasurements(mUnit, setup.Dimensions(), data);
|
2020-10-01 13:16:21 +02:00
|
|
|
|
m->SetFullCircumference(setup.FullCircumference());
|
2017-06-08 08:39:56 +02:00
|
|
|
|
m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer;
|
|
|
|
|
m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr;
|
2020-10-03 06:34:25 +02:00
|
|
|
|
|
|
|
|
|
SetCurrentDimensionValues();
|
2015-07-16 11:38:54 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
data = new VContainer(VAbstractApplication::VApp()->TrVars(), &mUnit, VContainer::UniqueNamespace());
|
2020-10-01 12:32:02 +02:00
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
m = new VMeasurements(mUnit, data);
|
2017-06-08 08:39:56 +02:00
|
|
|
|
m_curFileFormatVersion = VVITConverter::MeasurementMaxVer;
|
|
|
|
|
m_curFileFormatVersionStr = VVITConverter::MeasurementMaxVerStr;
|
2015-07-16 11:38:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
mIsReadOnly = m->IsReadOnly();
|
|
|
|
|
UpdatePadlock(mIsReadOnly);
|
|
|
|
|
|
2018-03-14 15:01:24 +01:00
|
|
|
|
SetCurrentFile(QString());
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-18 14:39:33 +02:00
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
InitWindow();
|
2015-07-25 17:18:01 +02:00
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
MeasurementGUI();
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
|
|
|
|
ui->actionImportFromCSV->setEnabled(true);
|
2015-07-15 09:16:59 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
MApplication::VApp()->NewMainWindow()->FileNew();
|
2015-07-15 09:16:59 +02:00
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 14:59:40 +02:00
|
|
|
|
void TMainWindow::OpenIndividual()
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
const QString filter = tr("Individual measurements") + QStringLiteral(" (*.vit);;") + tr("Multisize measurements") +
|
|
|
|
|
QStringLiteral(" (*.vst);;") + tr("All files") + QStringLiteral(" (*.*)");
|
2016-09-27 11:27:52 +02:00
|
|
|
|
//Use standard path to individual measurements
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const QString pathTo = MApplication::VApp()->TapeSettings()->GetPathIndividualMeasurements();
|
2016-09-27 11:27:52 +02:00
|
|
|
|
|
2017-02-17 19:37:49 +01:00
|
|
|
|
bool usedNotExistedDir = false;
|
|
|
|
|
QDir directory(pathTo);
|
|
|
|
|
if (not directory.exists())
|
|
|
|
|
{
|
2018-04-13 08:14:55 +02:00
|
|
|
|
usedNotExistedDir = directory.mkpath(QChar('.'));
|
2017-02-17 19:37:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-27 11:27:52 +02:00
|
|
|
|
Open(pathTo, filter);
|
2017-02-17 19:37:49 +01:00
|
|
|
|
|
|
|
|
|
if (usedNotExistedDir)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
QDir(pathTo).rmpath(QChar('.'));
|
2017-02-17 19:37:49 +01:00
|
|
|
|
}
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-07-12 20:21:48 +02:00
|
|
|
|
void TMainWindow::OpenMultisize()
|
2015-07-12 17:56:34 +02:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
const QString filter = tr("Multisize measurements") + QStringLiteral(" (*.vst);;") + tr("Individual measurements") +
|
|
|
|
|
QStringLiteral(" (*.vit);;") + tr("All files") + QStringLiteral(" (*.*)");
|
2017-07-12 20:21:48 +02:00
|
|
|
|
//Use standard path to multisize measurements
|
2021-02-06 14:52:21 +01:00
|
|
|
|
QString pathTo = MApplication::VApp()->TapeSettings()->GetPathMultisizeMeasurements();
|
2017-07-12 20:21:48 +02:00
|
|
|
|
pathTo = VCommonSettings::PrepareMultisizeTables(pathTo);
|
2016-09-27 11:27:52 +02:00
|
|
|
|
|
|
|
|
|
Open(pathTo, filter);
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::OpenTemplate()
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
const QString filter = tr("Measurements") + QStringLiteral(" (*.vst *.vit);;") + tr("All files") +
|
|
|
|
|
QStringLiteral(" (*.*)");
|
2016-09-27 11:27:52 +02:00
|
|
|
|
//Use standard path to template files
|
2021-02-06 14:52:21 +01:00
|
|
|
|
QString pathTo = MApplication::VApp()->TapeSettings()->GetPathTemplate();
|
2017-06-05 16:52:42 +02:00
|
|
|
|
pathTo = VCommonSettings::PrepareStandardTemplates(pathTo);
|
2016-09-27 11:27:52 +02:00
|
|
|
|
Open(pathTo, filter);
|
|
|
|
|
|
|
|
|
|
if (m != nullptr)
|
|
|
|
|
{// The file was opened.
|
2018-03-14 15:01:24 +01:00
|
|
|
|
SetCurrentFile(QString()); // Force user to to save new file
|
2016-09-27 11:27:52 +02:00
|
|
|
|
lock.reset();// remove lock from template
|
2015-07-15 09:16:59 +02:00
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 14:37:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::CreateFromExisting()
|
|
|
|
|
{
|
2022-07-01 09:29:03 +02:00
|
|
|
|
const QString filter = tr("Measurements") + QStringLiteral(" (*.vst *.vit);;") + tr("All files") +
|
|
|
|
|
QStringLiteral(" (*.*)");
|
2017-02-17 19:37:49 +01:00
|
|
|
|
|
2022-07-01 09:29:03 +02:00
|
|
|
|
const QString mPath = QFileDialog::getOpenFileName(this, tr("Select file"), QDir::homePath(), filter, nullptr,
|
2021-02-06 14:52:21 +01:00
|
|
|
|
VAbstractApplication::VApp()->NativeFileDialog());
|
2015-10-15 14:37:10 +02:00
|
|
|
|
|
2016-09-27 11:27:52 +02:00
|
|
|
|
if (not mPath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (m == nullptr)
|
2015-10-15 14:37:10 +02:00
|
|
|
|
{
|
|
|
|
|
LoadFromExistingFile(mPath);
|
|
|
|
|
}
|
2016-09-27 11:27:52 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
MApplication::VApp()->NewMainWindow()->CreateFromExisting();
|
2016-09-27 11:27:52 +02:00
|
|
|
|
}
|
2015-10-15 14:37:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-23 11:56:22 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Preferences()
|
|
|
|
|
{
|
2016-11-04 12:29:59 +01:00
|
|
|
|
// Calling constructor of the dialog take some time. Because of this user have time to call the dialog twice.
|
2017-04-12 14:50:48 +02:00
|
|
|
|
static QPointer<DialogTapePreferences> guard;// Prevent any second run
|
2016-11-04 12:29:59 +01:00
|
|
|
|
if (guard.isNull())
|
|
|
|
|
{
|
2017-06-14 10:48:51 +02:00
|
|
|
|
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
2019-01-06 12:29:57 +01:00
|
|
|
|
auto *preferences = new DialogTapePreferences(this);
|
2016-11-04 12:29:59 +01:00
|
|
|
|
// QScopedPointer needs to be sure any exception will never block guard
|
2017-04-12 14:50:48 +02:00
|
|
|
|
QScopedPointer<DialogTapePreferences> dlg(preferences);
|
|
|
|
|
guard = preferences;
|
|
|
|
|
// Must be first
|
|
|
|
|
connect(dlg.data(), &DialogTapePreferences::UpdateProperties, this, &TMainWindow::WindowsLocale);
|
|
|
|
|
connect(dlg.data(), &DialogTapePreferences::UpdateProperties, this, &TMainWindow::ToolBarStyles);
|
2017-06-14 10:48:51 +02:00
|
|
|
|
QGuiApplication::restoreOverrideCursor();
|
2016-11-04 12:29:59 +01:00
|
|
|
|
dlg->exec();
|
|
|
|
|
}
|
2016-07-23 11:56:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-12 14:50:48 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ToolBarStyles()
|
|
|
|
|
{
|
|
|
|
|
ToolBarStyle(ui->toolBarGradation);
|
|
|
|
|
ToolBarStyle(ui->mainToolBar);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 15:01:57 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
|
{
|
2018-04-27 15:32:26 +02:00
|
|
|
|
#if defined(Q_OS_MAC) && QT_VERSION < QT_VERSION_CHECK(5, 11, 1)
|
2018-04-03 16:41:39 +02:00
|
|
|
|
// Workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-43344
|
|
|
|
|
static int numCalled = 0;
|
|
|
|
|
if (numCalled++ >= 1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-07-18 15:01:57 +02:00
|
|
|
|
if (MaybeSave())
|
|
|
|
|
{
|
2015-08-01 19:09:10 +02:00
|
|
|
|
WriteSettings();
|
2015-07-18 15:01:57 +02:00
|
|
|
|
event->accept();
|
2015-08-01 15:06:12 +02:00
|
|
|
|
deleteLater();
|
2015-07-18 15:01:57 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
event->ignore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-08 16:33:37 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::changeEvent(QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
|
{
|
2021-05-20 17:33:53 +02:00
|
|
|
|
WindowsLocale();
|
2016-08-25 19:00:03 +02:00
|
|
|
|
|
2015-08-08 16:33:37 +02:00
|
|
|
|
// retranslate designer form (single inheritance approach)
|
|
|
|
|
ui->retranslateUi(this);
|
2015-10-16 19:26:05 +02:00
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder());
|
|
|
|
|
UpdateSearchControlsTooltips();
|
|
|
|
|
|
2021-05-21 19:51:46 +02:00
|
|
|
|
UpdateWindowTitle();
|
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
InitMeasurementUnits();
|
|
|
|
|
|
2017-07-12 20:21:48 +02:00
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
2015-10-16 19:26:05 +02:00
|
|
|
|
{
|
2017-02-17 19:37:49 +01:00
|
|
|
|
ui->labelMType->setText(tr("Multisize measurements"));
|
2020-10-01 15:56:44 +02:00
|
|
|
|
|
2020-10-01 18:06:20 +02:00
|
|
|
|
InitDimensionsBaseValue();
|
2020-10-03 06:34:25 +02:00
|
|
|
|
InitDimensionControls();
|
2020-10-03 17:52:31 +02:00
|
|
|
|
InitDimesionShifts();
|
2021-03-26 15:27:17 +01:00
|
|
|
|
RetranslateTableHeaders();
|
2015-10-16 19:26:05 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->labelMType->setText(tr("Individual measurements"));
|
|
|
|
|
|
|
|
|
|
const qint32 index = ui->comboBoxGender->currentIndex();
|
|
|
|
|
ui->comboBoxGender->blockSignals(true);
|
|
|
|
|
ui->comboBoxGender->clear();
|
|
|
|
|
InitGender(ui->comboBoxGender);
|
|
|
|
|
ui->comboBoxGender->setCurrentIndex(index);
|
|
|
|
|
ui->comboBoxGender->blockSignals(false);
|
2020-10-15 08:35:08 +02:00
|
|
|
|
|
|
|
|
|
InitMeasurementDimension();
|
2015-10-16 19:26:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const qint32 index = ui->comboBoxPMSystem->currentIndex();
|
|
|
|
|
ui->comboBoxPMSystem->blockSignals(true);
|
|
|
|
|
ui->comboBoxPMSystem->clear();
|
|
|
|
|
InitPMSystems(ui->comboBoxPMSystem);
|
|
|
|
|
ui->comboBoxPMSystem->setCurrentIndex(index);
|
|
|
|
|
ui->comboBoxPMSystem->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-11-22 08:32:33 +01:00
|
|
|
|
if (labelPatternUnit)
|
|
|
|
|
{
|
|
|
|
|
labelPatternUnit->setText(tr("Pattern unit:"));
|
|
|
|
|
}
|
2015-10-16 19:26:05 +02:00
|
|
|
|
|
2020-11-22 08:32:33 +01:00
|
|
|
|
if (comboBoxUnits)
|
2015-11-05 13:06:45 +01:00
|
|
|
|
{
|
|
|
|
|
const qint32 index = comboBoxUnits->currentIndex();
|
|
|
|
|
comboBoxUnits->blockSignals(true);
|
|
|
|
|
comboBoxUnits->clear();
|
|
|
|
|
InitComboBoxUnits();
|
|
|
|
|
comboBoxUnits->setCurrentIndex(index);
|
|
|
|
|
comboBoxUnits->blockSignals(false);
|
|
|
|
|
}
|
2015-10-16 19:26:05 +02:00
|
|
|
|
}
|
2015-08-08 16:33:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remember to call base class implementation
|
|
|
|
|
QMainWindow::changeEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 20:24:14 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
bool TMainWindow::eventFilter(QObject *object, QEvent *event)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
if (auto *plainTextEdit = qobject_cast<QPlainTextEdit *>(object))
|
2016-08-23 20:24:14 +02:00
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::KeyPress)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
auto *keyEvent = static_cast<QKeyEvent *>(event);
|
|
|
|
|
if ((keyEvent->key() == Qt::Key_Period) && ((keyEvent->modifiers() & Qt::KeypadModifier) != 0u))
|
2016-08-23 20:24:14 +02:00
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
if (VAbstractApplication::VApp()->Settings()->GetOsSeparator())
|
2016-08-23 20:24:14 +02:00
|
|
|
|
{
|
2017-01-03 09:46:28 +01:00
|
|
|
|
plainTextEdit->insertPlainText(QLocale().decimalPoint());
|
2016-08-23 20:24:14 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
plainTextEdit->insertPlainText(QLocale::c().decimalPoint());
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-06 12:29:57 +01:00
|
|
|
|
else if (auto *textEdit = qobject_cast<QLineEdit *>(object))
|
2016-08-23 20:24:14 +02:00
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::KeyPress)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
auto *keyEvent = static_cast<QKeyEvent *>(event);
|
|
|
|
|
if ((keyEvent->key() == Qt::Key_Period) && ((keyEvent->modifiers() & Qt::KeypadModifier) != 0u))
|
2016-08-23 20:24:14 +02:00
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
if (VAbstractApplication::VApp()->Settings()->GetOsSeparator())
|
2016-08-23 20:24:14 +02:00
|
|
|
|
{
|
2017-01-03 09:46:28 +01:00
|
|
|
|
textEdit->insert(QLocale().decimalPoint());
|
2016-08-23 20:24:14 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
textEdit->insert(QLocale::c().decimalPoint());
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-06 12:29:57 +01:00
|
|
|
|
|
|
|
|
|
// pass the event on to the parent class
|
|
|
|
|
return QMainWindow::eventFilter(object, event);
|
2016-08-23 20:24:14 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-12 14:09:19 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-27 12:25:18 +02:00
|
|
|
|
void TMainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int mib, const QChar &separator)
|
2017-05-12 14:09:19 +02:00
|
|
|
|
{
|
|
|
|
|
QxtCsvModel csv;
|
|
|
|
|
const int columns = ui->tableWidget->columnCount();
|
|
|
|
|
{
|
|
|
|
|
int colCount = 0;
|
|
|
|
|
for (int column = 0; column < columns; ++column)
|
|
|
|
|
{
|
|
|
|
|
if (not ui->tableWidget->isColumnHidden(column))
|
|
|
|
|
{
|
|
|
|
|
csv.insertColumn(colCount++);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-27 12:25:18 +02:00
|
|
|
|
if (withHeader)
|
2017-05-12 14:09:19 +02:00
|
|
|
|
{
|
|
|
|
|
int colCount = 0;
|
|
|
|
|
for (int column = 0; column < columns; ++column)
|
|
|
|
|
{
|
|
|
|
|
if (not ui->tableWidget->isColumnHidden(column))
|
|
|
|
|
{
|
2018-01-31 13:31:34 +01:00
|
|
|
|
QTableWidgetItem *header = ui->tableWidget->horizontalHeaderItem(column);
|
2017-05-12 14:09:19 +02:00
|
|
|
|
csv.setHeaderText(colCount, header->text());
|
|
|
|
|
++colCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int rows = ui->tableWidget->rowCount();
|
|
|
|
|
for (int row = 0; row < rows; ++row)
|
|
|
|
|
{
|
|
|
|
|
csv.insertRow(row);
|
|
|
|
|
int colCount = 0;
|
|
|
|
|
for (int column = 0; column < columns; ++column)
|
|
|
|
|
{
|
|
|
|
|
if (not ui->tableWidget->isColumnHidden(column))
|
|
|
|
|
{
|
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->item(row, column);
|
|
|
|
|
csv.setText(row, colCount, item->text());
|
|
|
|
|
++colCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 15:05:04 +02:00
|
|
|
|
QString error;
|
|
|
|
|
csv.toCSV(fileName, error, withHeader, separator, QTextCodec::codecForMib(mib));
|
2017-05-12 14:09:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 21:18:18 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QStringList TMainWindow::RecentFileList() const
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
return MApplication::VApp()->TapeSettings()->GetRecentFileList();
|
2019-09-06 21:18:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-04 12:28:47 +01:00
|
|
|
|
bool TMainWindow::FileSave()
|
2015-07-12 17:56:34 +02:00
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
|
if (curFile.isEmpty() || mIsReadOnly)
|
2015-07-18 14:39:33 +02:00
|
|
|
|
{
|
|
|
|
|
return FileSaveAs();
|
|
|
|
|
}
|
2019-01-06 12:29:57 +01:00
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Multisize
|
|
|
|
|
&& m_curFileFormatVersion < VVSTConverter::MeasurementMaxVer
|
|
|
|
|
&& not ContinueFormatRewrite(m_curFileFormatVersionStr, VVSTConverter::MeasurementMaxVerStr))
|
2015-07-18 14:39:33 +02:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Individual
|
|
|
|
|
&& m_curFileFormatVersion < VVITConverter::MeasurementMaxVer
|
|
|
|
|
&& not ContinueFormatRewrite(m_curFileFormatVersionStr, VVITConverter::MeasurementMaxVerStr))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-04-12 08:49:05 +02:00
|
|
|
|
|
2021-05-21 16:17:22 +02:00
|
|
|
|
if (not CheckFilePermissions(curFile, this))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
2019-01-06 12:29:57 +01:00
|
|
|
|
|
|
|
|
|
QString error;
|
|
|
|
|
if (not SaveMeasurements(curFile, error))
|
|
|
|
|
{
|
|
|
|
|
QMessageBox messageBox;
|
|
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
|
messageBox.setText(tr("Could not save the file"));
|
|
|
|
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
messageBox.setDetailedText(error);
|
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
|
messageBox.exec();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
|
|
|
|
{
|
|
|
|
|
m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer;
|
|
|
|
|
m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_curFileFormatVersion = VVITConverter::MeasurementMaxVer;
|
|
|
|
|
m_curFileFormatVersionStr = VVITConverter::MeasurementMaxVerStr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
return true;
|
2015-07-12 17:56:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-04 12:28:47 +01:00
|
|
|
|
bool TMainWindow::FileSaveAs()
|
2015-07-12 17:56:34 +02:00
|
|
|
|
{
|
2015-07-18 14:39:33 +02:00
|
|
|
|
QString filters;
|
|
|
|
|
QString fName = tr("measurements");
|
|
|
|
|
QString suffix;
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
filters = tr("Individual measurements") + QStringLiteral(" (*.vit)");
|
|
|
|
|
suffix = QStringLiteral("vit");
|
2018-04-13 08:14:55 +02:00
|
|
|
|
fName += QChar('.') + suffix;
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
filters = tr("Multisize measurements") + QStringLiteral(" (*.vst)");
|
|
|
|
|
suffix = QStringLiteral("vst");
|
2018-04-13 08:14:55 +02:00
|
|
|
|
fName += QChar('.') + suffix;
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString dir;
|
|
|
|
|
if (curFile.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
dir = MApplication::VApp()->TapeSettings()->GetPathIndividualMeasurements();
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
dir = MApplication::VApp()->TapeSettings()->GetPathMultisizeMeasurements();
|
2017-07-12 20:21:48 +02:00
|
|
|
|
dir = VCommonSettings::PrepareMultisizeTables(dir);
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-17 19:37:49 +01:00
|
|
|
|
dir = QFileInfo(curFile).absolutePath();
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-17 19:37:49 +01:00
|
|
|
|
bool usedNotExistedDir = false;
|
|
|
|
|
QDir directory(dir);
|
|
|
|
|
if (not directory.exists())
|
|
|
|
|
{
|
2018-04-13 08:14:55 +02:00
|
|
|
|
usedNotExistedDir = directory.mkpath(QChar('.'));
|
2017-02-17 19:37:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 15:48:37 +02:00
|
|
|
|
if (not curFile.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
fName = StrippedName(curFile);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 17:43:15 +01:00
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QChar('/') + fName, filters, nullptr,
|
2021-02-06 14:52:21 +01:00
|
|
|
|
VAbstractApplication::VApp()->NativeFileDialog());
|
2017-02-17 19:37:49 +01:00
|
|
|
|
|
2019-07-04 16:32:58 +02:00
|
|
|
|
auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]()
|
2017-02-17 19:37:49 +01:00
|
|
|
|
{
|
|
|
|
|
if (usedNotExistedDir)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
QDir(dir).rmpath(QChar('.'));
|
2017-02-17 19:37:49 +01:00
|
|
|
|
}
|
2019-07-04 16:32:58 +02:00
|
|
|
|
});
|
2015-07-18 14:39:33 +02:00
|
|
|
|
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
|
return false;
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
|
QFileInfo f( fileName );
|
|
|
|
|
if (f.suffix().isEmpty() && f.suffix() != suffix)
|
|
|
|
|
{
|
2018-04-13 08:14:55 +02:00
|
|
|
|
fileName += QChar('.') + suffix;
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
2015-09-16 13:29:01 +02:00
|
|
|
|
|
2019-07-04 16:13:33 +02:00
|
|
|
|
if (QFileInfo::exists(fileName) && curFile != fileName)
|
2015-09-16 13:29:01 +02:00
|
|
|
|
{
|
2015-10-09 11:50:37 +02:00
|
|
|
|
// Temporary try to lock the file before saving
|
2015-10-26 08:57:20 +01:00
|
|
|
|
VLockGuard<char> tmp(fileName);
|
2015-09-16 13:29:01 +02:00
|
|
|
|
if (not tmp.IsLocked())
|
|
|
|
|
{
|
2015-10-09 11:50:37 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s",
|
|
|
|
|
qUtf8Printable(tr("Failed to lock. This file already opened in another window.")));
|
2017-02-04 12:28:47 +01:00
|
|
|
|
return false;
|
2015-09-16 13:29:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
// Need for restoring previous state in case of failure
|
|
|
|
|
const bool readOnly = m->IsReadOnly();
|
|
|
|
|
|
|
|
|
|
m->SetReadOnly(false);
|
|
|
|
|
mIsReadOnly = false;
|
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
|
QString error;
|
|
|
|
|
bool result = SaveMeasurements(fileName, error);
|
2019-01-06 12:29:57 +01:00
|
|
|
|
if (not result)
|
2015-07-18 14:39:33 +02:00
|
|
|
|
{
|
|
|
|
|
QMessageBox messageBox;
|
|
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
|
messageBox.setInformativeText(tr("Could not save file"));
|
|
|
|
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
messageBox.setDetailedText(error);
|
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
|
messageBox.exec();
|
2015-09-16 13:29:01 +02:00
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
// Restore previous state
|
|
|
|
|
m->SetReadOnly(readOnly);
|
|
|
|
|
mIsReadOnly = readOnly;
|
|
|
|
|
return false;
|
2015-09-16 13:29:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-30 20:36:59 +01:00
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
|
|
|
|
{
|
|
|
|
|
m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer;
|
|
|
|
|
m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_curFileFormatVersion = VVITConverter::MeasurementMaxVer;
|
|
|
|
|
m_curFileFormatVersionStr = VVITConverter::MeasurementMaxVerStr;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
UpdatePadlock(false);
|
|
|
|
|
UpdateWindowTitle();
|
|
|
|
|
|
2019-07-04 16:13:33 +02:00
|
|
|
|
if (curFile == fileName && not lock.isNull())
|
|
|
|
|
{
|
|
|
|
|
lock->Unlock();
|
|
|
|
|
}
|
2015-10-26 08:57:20 +01:00
|
|
|
|
VlpCreateLock(lock, fileName);
|
2015-10-09 11:50:37 +02:00
|
|
|
|
if (not lock->IsLocked())
|
2015-09-16 13:29:01 +02:00
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window. "
|
|
|
|
|
"Expect collissions when run 2 copies of the program.")));
|
2017-02-04 12:28:47 +01:00
|
|
|
|
return false;
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
2017-02-04 12:28:47 +01:00
|
|
|
|
return true;
|
2015-07-12 17:56:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::AboutToShowWindowMenu()
|
|
|
|
|
{
|
|
|
|
|
ui->menuWindow->clear();
|
2015-12-03 09:43:31 +01:00
|
|
|
|
CreateWindowMenu(ui->menuWindow);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-18 17:09:15 +02:00
|
|
|
|
void TMainWindow::ShowWindow() const
|
2015-07-12 17:56:34 +02:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
if (auto *action = qobject_cast<QAction*>(sender()))
|
2015-07-12 17:56:34 +02:00
|
|
|
|
{
|
|
|
|
|
const QVariant v = action->data();
|
|
|
|
|
if (v.canConvert<int>())
|
|
|
|
|
{
|
|
|
|
|
const int offset = qvariant_cast<int>(v);
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const QList<TMainWindow*> windows = MApplication::VApp()->MainWindows();
|
2015-12-05 10:50:32 +01:00
|
|
|
|
windows.at(offset)->raise();
|
2015-07-12 17:56:34 +02:00
|
|
|
|
windows.at(offset)->activateWindow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 13:34:50 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ImportDataFromCSV()
|
|
|
|
|
{
|
|
|
|
|
if (m == nullptr || m->Type() == MeasurementsType::Unknown)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-06 12:29:57 +01:00
|
|
|
|
const QString filters = tr("Comma-Separated Values") + QStringLiteral(" (*.csv)");
|
|
|
|
|
const QString suffix = QStringLiteral("csv");
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2020-12-17 17:43:15 +01:00
|
|
|
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Import from CSV"), QDir::homePath(), filters, nullptr,
|
2021-02-06 14:52:21 +01:00
|
|
|
|
VAbstractApplication::VApp()->NativeFileDialog());
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFileInfo f( fileName );
|
|
|
|
|
if (f.suffix().isEmpty() && f.suffix() != suffix)
|
|
|
|
|
{
|
2018-04-13 08:14:55 +02:00
|
|
|
|
fileName += QChar('.') + suffix;
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DialogExportToCSV dialog(this);
|
2021-02-06 14:52:21 +01:00
|
|
|
|
dialog.SetWithHeader(VAbstractApplication::VApp()->Settings()->GetCSVWithHeader());
|
|
|
|
|
dialog.SetSelectedMib(VAbstractApplication::VApp()->Settings()->GetCSVCodec());
|
|
|
|
|
dialog.SetSeparator(VAbstractApplication::VApp()->Settings()->GetCSVSeparator());
|
2018-02-06 14:46:20 +01:00
|
|
|
|
dialog.ShowFilePreview(fileName);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
VAbstractApplication::VApp()->Settings()->SetCSVSeparator(dialog.GetSeparator());
|
|
|
|
|
VAbstractApplication::VApp()->Settings()->SetCSVCodec(dialog.GetSelectedMib());
|
|
|
|
|
VAbstractApplication::VApp()->Settings()->SetCSVWithHeader(dialog.IsWithHeader());
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2020-10-10 18:31:23 +02:00
|
|
|
|
QSharedPointer<DialogMeasurementsCSVColumns> columns;
|
|
|
|
|
if (m->Type() == MeasurementsType::Multisize)
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
columns = QSharedPointer<DialogMeasurementsCSVColumns>::create(fileName, m->Type(), dimensions, this);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-10-10 18:31:23 +02:00
|
|
|
|
columns = QSharedPointer<DialogMeasurementsCSVColumns>::create(fileName, m->Type(), this);
|
|
|
|
|
}
|
|
|
|
|
columns->SetWithHeader(dialog.IsWithHeader());
|
|
|
|
|
columns->SetSeparator(dialog.GetSeparator());
|
|
|
|
|
columns->SetCodec(QTextCodec::codecForMib(dialog.GetSelectedMib()));
|
|
|
|
|
|
|
|
|
|
if (columns->exec() == QDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
QxtCsvModel csv(fileName, nullptr, dialog.IsWithHeader(), dialog.GetSeparator(),
|
|
|
|
|
QTextCodec::codecForMib(dialog.GetSelectedMib()));
|
|
|
|
|
const QVector<int> map = columns->ColumnsMap();
|
|
|
|
|
|
|
|
|
|
if (m->Type() == MeasurementsType::Individual)
|
|
|
|
|
{
|
|
|
|
|
ImportIndividualMeasurements(csv, map);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ImportMultisizeMeasurements(csv, map);
|
|
|
|
|
}
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-03 13:07:51 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
#if defined(Q_OS_MAC)
|
2015-12-05 10:50:32 +01:00
|
|
|
|
void TMainWindow::AboutToShowDockMenu()
|
|
|
|
|
{
|
|
|
|
|
if (QMenu *menu = qobject_cast<QMenu *>(sender()))
|
|
|
|
|
{
|
|
|
|
|
menu->clear();
|
|
|
|
|
CreateWindowMenu(menu);
|
|
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
|
|
menu->addAction(ui->actionOpenIndividual);
|
2017-07-12 20:21:48 +02:00
|
|
|
|
menu->addAction(ui->actionOpenMultisize);
|
2015-12-05 10:50:32 +01:00
|
|
|
|
menu->addAction(ui->actionOpenTemplate);
|
|
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
|
|
QAction *actionPreferences = menu->addAction(tr("Preferences"));
|
|
|
|
|
actionPreferences->setMenuRole(QAction::NoRole);
|
|
|
|
|
connect(actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-12-03 13:07:51 +01:00
|
|
|
|
void TMainWindow::OpenAt(QAction *where)
|
|
|
|
|
{
|
|
|
|
|
const QString path = curFile.left(curFile.indexOf(where->text())) + where->text();
|
|
|
|
|
if (path == curFile)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
QProcess process;
|
|
|
|
|
process.start(QStringLiteral("/usr/bin/open"), QStringList() << path, QIODevice::ReadOnly);
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
}
|
|
|
|
|
#endif //defined(Q_OS_MAC)
|
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-09-19 15:07:48 +02:00
|
|
|
|
void TMainWindow::SaveCustomerName()
|
2015-07-18 13:08:44 +02:00
|
|
|
|
{
|
2017-09-19 15:07:48 +02:00
|
|
|
|
if (m->Customer() != ui->lineEditCustomerName->text())
|
2015-07-25 17:18:01 +02:00
|
|
|
|
{
|
2017-09-19 15:07:48 +02:00
|
|
|
|
m->SetCustomer(ui->lineEditCustomerName->text());
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveEmail()
|
|
|
|
|
{
|
2015-07-25 17:18:01 +02:00
|
|
|
|
if (m->Email() != ui->lineEditEmail->text())
|
|
|
|
|
{
|
|
|
|
|
m->SetEmail(ui->lineEditEmail->text());
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
|
void TMainWindow::SaveGender(int index)
|
2015-07-18 13:08:44 +02:00
|
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
|
const GenderType type = static_cast<GenderType>(ui->comboBoxGender->itemData(index).toInt());
|
|
|
|
|
if (m->Gender() != type)
|
2015-07-25 17:18:01 +02:00
|
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
|
m->SetGender(type);
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveBirthDate(const QDate &date)
|
|
|
|
|
{
|
2015-07-25 17:18:01 +02:00
|
|
|
|
if (m->BirthDate() != date)
|
|
|
|
|
{
|
|
|
|
|
m->SetBirthDate(date);
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveNotes()
|
|
|
|
|
{
|
2015-07-25 17:18:01 +02:00
|
|
|
|
if (m->Notes() != ui->plainTextEditNotes->toPlainText())
|
|
|
|
|
{
|
|
|
|
|
m->SetNotes(ui->plainTextEditNotes->toPlainText());
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SavePMSystem(int index)
|
|
|
|
|
{
|
|
|
|
|
QString system = ui->comboBoxPMSystem->itemData(index).toString();
|
|
|
|
|
system.remove(0, 1);// clear p
|
|
|
|
|
|
|
|
|
|
if (m->PMSystem() != system)
|
|
|
|
|
{
|
|
|
|
|
m->SetPMSystem(system);
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-10-16 19:26:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 08:41:04 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Remove()
|
|
|
|
|
{
|
2019-01-15 09:52:43 +01:00
|
|
|
|
ShowMDiagram(QString());
|
2015-07-22 08:41:04 +02:00
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->Remove(nameField->data(Qt::UserRole).toString());
|
2015-07-22 08:41:04 +02:00
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-22 08:41:04 +02:00
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RemoveRow(row);
|
2015-07-22 08:41:04 +02:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->rowCount() > 0)
|
|
|
|
|
{
|
2019-12-05 09:27:33 +01:00
|
|
|
|
ui->tableWidget->selectRow(row >= ui->tableWidget->rowCount() ? ui->tableWidget->rowCount() - 1 : row);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-09 11:45:30 +02:00
|
|
|
|
MFields(false);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
2018-01-31 13:34:50 +01:00
|
|
|
|
ui->actionExportToCSV->setEnabled(false);
|
2016-06-01 15:37:42 +02:00
|
|
|
|
|
2015-07-24 12:20:38 +02:00
|
|
|
|
ui->lineEditName->blockSignals(true);
|
2018-03-14 15:01:24 +01:00
|
|
|
|
ui->lineEditName->setText(QString());
|
2015-07-24 12:20:38 +02:00
|
|
|
|
ui->lineEditName->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ui->plainTextEditDescription->blockSignals(true);
|
2018-03-14 15:01:24 +01:00
|
|
|
|
ui->plainTextEditDescription->setPlainText(QString());
|
2015-07-24 12:20:38 +02:00
|
|
|
|
ui->plainTextEditDescription->blockSignals(false);
|
|
|
|
|
|
2015-07-25 10:54:39 +02:00
|
|
|
|
ui->lineEditFullName->blockSignals(true);
|
2018-03-14 15:01:24 +01:00
|
|
|
|
ui->lineEditFullName->setText(QString());
|
2015-07-25 10:54:39 +02:00
|
|
|
|
ui->lineEditFullName->blockSignals(false);
|
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->comboBoxMUnits->blockSignals(true);
|
|
|
|
|
ui->comboBoxMUnits->setCurrentIndex(-1);
|
|
|
|
|
ui->comboBoxMUnits->blockSignals(false);
|
|
|
|
|
|
2017-07-12 20:21:48 +02:00
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
2015-07-24 12:20:38 +02:00
|
|
|
|
{
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(true);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->blockSignals(true);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxShiftA->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxShiftB->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxShiftC->blockSignals(true);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
2018-03-14 15:01:24 +01:00
|
|
|
|
ui->labelCalculatedValue->setText(QString());
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setValue(0);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->setValue(0);
|
|
|
|
|
ui->doubleSpinBoxShiftA->setValue(0);
|
|
|
|
|
ui->doubleSpinBoxShiftB->setValue(0);
|
|
|
|
|
ui->doubleSpinBoxShiftC->setValue(0);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(false);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->blockSignals(false);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxShiftA->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxShiftB->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxShiftC->blockSignals(false);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(true);
|
2018-03-14 15:01:24 +01:00
|
|
|
|
ui->labelCalculatedValue->setText(QString());
|
2015-07-24 12:20:38 +02:00
|
|
|
|
ui->labelCalculatedValue->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
2018-03-14 15:01:24 +01:00
|
|
|
|
ui->plainTextEditFormula->setPlainText(QString());
|
2015-07-24 12:20:38 +02:00
|
|
|
|
ui->plainTextEditFormula->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-10 16:24:16 +01:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X
|
2015-07-22 08:41:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 16:57:11 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MoveTop()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
|
|
|
|
m->MoveTop(nameField->data(Qt::UserRole).toString());
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->tableWidget->selectRow(0);
|
2018-03-10 16:24:16 +01:00
|
|
|
|
ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X
|
2015-10-12 16:57:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 09:01:34 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MoveUp()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->MoveUp(nameField->data(Qt::UserRole).toString());
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-22 09:01:34 +02:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-07-24 12:11:03 +02:00
|
|
|
|
ui->tableWidget->selectRow(row-1);
|
2018-03-10 16:24:16 +01:00
|
|
|
|
ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X
|
2015-07-22 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MoveDown()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->MoveDown(nameField->data(Qt::UserRole).toString());
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-22 09:01:34 +02:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-07-24 12:11:03 +02:00
|
|
|
|
ui->tableWidget->selectRow(row+1);
|
2018-03-10 16:24:16 +01:00
|
|
|
|
ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X
|
2015-07-22 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 16:57:11 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MoveBottom()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
|
|
|
|
m->MoveBottom(nameField->data(Qt::UserRole).toString());
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->tableWidget->selectRow(ui->tableWidget->rowCount()-1);
|
2018-03-10 16:24:16 +01:00
|
|
|
|
ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X
|
2015-10-12 16:57:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-24 14:06:53 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Fx()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
|
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId & e)
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-09-29 16:04:24 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-24 14:06:53 +02:00
|
|
|
|
|
2019-01-06 12:29:57 +01:00
|
|
|
|
auto *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this);
|
2015-07-24 14:06:53 +02:00
|
|
|
|
dialog->setWindowTitle(tr("Edit measurement"));
|
2018-01-24 18:10:29 +01:00
|
|
|
|
dialog->SetMeasurementsMode();
|
2021-02-06 14:52:21 +01:00
|
|
|
|
dialog->SetFormula(VAbstractApplication::VApp()->TrVars()
|
|
|
|
|
->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText(), true));
|
2017-07-02 13:34:36 +02:00
|
|
|
|
const QString postfix = UnitsToStr(mUnit, true);//Show unit in dialog lable (cm, mm or inch)
|
2015-07-24 14:06:53 +02:00
|
|
|
|
dialog->setPostfix(postfix);
|
|
|
|
|
|
|
|
|
|
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.
|
2019-01-06 12:29:57 +01:00
|
|
|
|
nameField = ui->tableWidget->item(row, ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->SetMValue(nameField->data(Qt::UserRole).toString(), dialog->GetFormula());
|
2015-07-24 14:06:53 +02:00
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-24 14:06:53 +02:00
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-09-15 18:49:24 +02:00
|
|
|
|
|
2015-07-24 14:06:53 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
}
|
|
|
|
|
delete dialog;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::AddCustom()
|
|
|
|
|
{
|
2017-04-14 09:35:44 +02:00
|
|
|
|
const QString name = GetCustomName();
|
|
|
|
|
qint32 currentRow = -1;
|
2015-07-21 19:26:33 +02:00
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->currentRow() == -1)
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->rowCount();
|
|
|
|
|
m->AddEmpty(name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->currentRow()+1;
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->AddEmptyAfter(nameField->data(Qt::UserRole).toString(), name);
|
2015-07-21 19:26:33 +02:00
|
|
|
|
}
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->AddRow(currentRow);
|
2015-08-01 12:33:57 +02:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->selectRow(currentRow);
|
|
|
|
|
|
2016-06-01 15:37:42 +02:00
|
|
|
|
ui->actionExportToCSV->setEnabled(true);
|
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2018-03-10 16:24:16 +01:00
|
|
|
|
ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X
|
2015-07-19 14:28:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::AddKnown()
|
|
|
|
|
{
|
2016-06-01 15:37:42 +02:00
|
|
|
|
QScopedPointer<DialogMDataBase> dialog (new DialogMDataBase(m->ListKnown(), this));
|
2015-08-01 11:39:32 +02:00
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
|
{
|
2015-08-01 13:25:05 +02:00
|
|
|
|
qint32 currentRow;
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
2015-08-01 13:25:05 +02:00
|
|
|
|
const QStringList list = dialog->GetNewNames();
|
|
|
|
|
if (ui->tableWidget->currentRow() == -1)
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->rowCount() + list.size() - 1;
|
2018-04-03 13:36:38 +02:00
|
|
|
|
for (auto &name : list)
|
2015-08-01 13:25:05 +02:00
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
m->AddEmpty(name, VAbstractApplication::VApp()->TrVars()->MFormula(name));
|
2015-08-01 13:25:05 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
|
m->AddEmpty(name);
|
2015-08-01 13:25:05 +02:00
|
|
|
|
}
|
2015-09-15 18:49:24 +02:00
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->AddRow(currentRow);
|
2015-08-01 13:25:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->currentRow() + list.size();
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
QString after = nameField->data(Qt::UserRole).toString();
|
2018-04-03 13:36:38 +02:00
|
|
|
|
for (auto &name : list)
|
2015-08-01 13:25:05 +02:00
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
m->AddEmptyAfter(after, name, VAbstractApplication::VApp()->TrVars()->MFormula(name));
|
2015-08-01 13:25:05 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
|
m->AddEmptyAfter(after, name);
|
2015-08-01 13:25:05 +02:00
|
|
|
|
}
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->AddRow(currentRow);
|
2018-04-03 13:36:38 +02:00
|
|
|
|
after = name;
|
2015-08-01 13:25:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-08-01 13:25:05 +02:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->selectRow(currentRow);
|
|
|
|
|
|
2016-06-01 15:37:42 +02:00
|
|
|
|
ui->actionExportToCSV->setEnabled(true);
|
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-08-01 11:39:32 +02:00
|
|
|
|
}
|
2018-03-10 16:24:16 +01:00
|
|
|
|
ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X
|
2015-07-19 14:28:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::AddSeparator()
|
|
|
|
|
{
|
|
|
|
|
const QString name = GetCustomName();
|
|
|
|
|
qint32 currentRow = -1;
|
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->currentRow() == -1)
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->rowCount();
|
|
|
|
|
m->AddSeparator(name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->currentRow()+1;
|
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
|
|
|
|
m->AddSeparatorAfter(nameField->data(Qt::UserRole).toString(), name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_search->AddRow(currentRow);
|
|
|
|
|
RefreshData();
|
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->selectRow(currentRow);
|
|
|
|
|
|
|
|
|
|
ui->actionExportToCSV->setEnabled(true);
|
|
|
|
|
|
|
|
|
|
MeasurementsWereSaved(false);
|
|
|
|
|
ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-11 16:52:18 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ImportFromPattern()
|
|
|
|
|
{
|
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString filter(tr("Pattern files (*.val)"));
|
|
|
|
|
//Use standard path to individual measurements
|
2021-02-06 14:52:21 +01:00
|
|
|
|
QString pathTo = MApplication::VApp()->TapeSettings()->GetPathPattern();
|
2015-08-11 16:52:18 +02:00
|
|
|
|
|
2020-12-17 17:43:15 +01:00
|
|
|
|
const QString mPath = QFileDialog::getOpenFileName(this, tr("Import from a pattern"), pathTo, filter, nullptr,
|
2021-02-06 14:52:21 +01:00
|
|
|
|
VAbstractApplication::VApp()->NativeFileDialog());
|
2015-08-11 16:52:18 +02:00
|
|
|
|
if (mPath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 01:58:39 +01:00
|
|
|
|
VLockGuard<char> tmp(mPath);
|
2015-10-09 11:50:37 +02:00
|
|
|
|
if (not tmp.IsLocked())
|
2015-08-11 16:52:18 +02:00
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
|
2015-09-14 13:53:49 +02:00
|
|
|
|
return;
|
2015-08-11 16:52:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList measurements;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
VPatternConverter converter(mPath);
|
2017-01-21 14:50:17 +01:00
|
|
|
|
QScopedPointer<VLitePattern> doc(new VLitePattern());
|
2017-02-04 12:28:47 +01:00
|
|
|
|
doc->setXMLContent(converter.Convert());
|
2015-08-11 16:52:18 +02:00
|
|
|
|
measurements = doc->ListMeasurements();
|
|
|
|
|
}
|
|
|
|
|
catch (VException &e)
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-08-11 16:52:18 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
measurements = FilterMeasurements(measurements, m->ListAll());
|
|
|
|
|
|
|
|
|
|
qint32 currentRow;
|
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->currentRow() == -1)
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->rowCount() + measurements.size() - 1;
|
2018-04-03 13:36:38 +02:00
|
|
|
|
for (auto &mName : measurements)
|
2015-08-11 16:52:18 +02:00
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
|
m->AddEmpty(mName);
|
2015-08-11 16:52:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->currentRow() + measurements.size();
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
QString after = nameField->data(Qt::UserRole).toString();
|
2018-04-03 13:36:38 +02:00
|
|
|
|
for (auto &mName : measurements)
|
2015-08-11 16:52:18 +02:00
|
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
|
m->AddEmptyAfter(after, mName);
|
|
|
|
|
after = mName;
|
2015-08-11 16:52:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-09-15 18:49:24 +02:00
|
|
|
|
|
2015-08-11 16:52:18 +02:00
|
|
|
|
ui->tableWidget->selectRow(currentRow);
|
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-08-11 16:52:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 15:18:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 06:34:25 +02:00
|
|
|
|
void TMainWindow::DimensionABaseChanged()
|
2015-07-21 15:18:10 +02:00
|
|
|
|
{
|
2021-01-18 19:43:53 +01:00
|
|
|
|
currentDimensionA = gradationDimensionA->currentData().toDouble();
|
2020-10-03 06:34:25 +02:00
|
|
|
|
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
if (dimensions.size() > 1)
|
|
|
|
|
{
|
|
|
|
|
MeasurementDimension_p dimension = dimensions.at(1);
|
|
|
|
|
InitDimensionGradation(1, dimension, gradationDimensionB);
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
dimension = dimensions.at(2);
|
|
|
|
|
InitDimensionGradation(2, dimension, gradationDimensionC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gradation->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::DimensionBBaseChanged()
|
|
|
|
|
{
|
2021-01-18 19:43:53 +01:00
|
|
|
|
currentDimensionB = gradationDimensionB->currentData().toDouble();
|
2020-10-03 06:34:25 +02:00
|
|
|
|
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
MeasurementDimension_p dimension = dimensions.at(2);
|
|
|
|
|
InitDimensionGradation(2, dimension, gradationDimensionC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gradation->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::DimensionCBaseChanged()
|
|
|
|
|
{
|
2021-01-18 19:43:53 +01:00
|
|
|
|
currentDimensionC = gradationDimensionC->currentData().toDouble();
|
2020-10-03 06:34:25 +02:00
|
|
|
|
gradation->start();
|
2015-07-21 15:18:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 06:34:25 +02:00
|
|
|
|
void TMainWindow::GradationChanged()
|
2015-07-21 15:18:10 +02:00
|
|
|
|
{
|
2020-10-03 06:34:25 +02:00
|
|
|
|
gradation->stop();
|
2015-07-25 07:41:04 +02:00
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
2015-07-21 15:18:10 +02:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-07-25 07:41:04 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 17:28:20 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowMData()
|
2017-05-23 09:45:04 +02:00
|
|
|
|
{
|
|
|
|
|
ShowNewMData(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowNewMData(bool fresh)
|
2015-07-21 17:28:20 +02:00
|
|
|
|
{
|
|
|
|
|
if (ui->tableWidget->rowCount() > 0)
|
|
|
|
|
{
|
2015-09-09 11:45:30 +02:00
|
|
|
|
MFields(true);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
2018-08-02 14:03:15 +02:00
|
|
|
|
if (ui->tableWidget->currentRow() == -1)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(0);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName); // name
|
2018-08-02 14:03:15 +02:00
|
|
|
|
SCASSERT(nameField != nullptr)
|
2015-08-01 16:36:56 +02:00
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
2015-07-21 17:28:20 +02:00
|
|
|
|
|
2015-08-01 16:36:56 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2015-09-29 16:04:24 +02:00
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
2015-08-01 16:36:56 +02:00
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId &e)
|
|
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
|
Q_UNUSED(e)
|
2015-09-09 11:45:30 +02:00
|
|
|
|
MFields(false);
|
2015-08-01 16:36:56 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
2015-10-29 17:20:59 +01:00
|
|
|
|
ShowMDiagram(meash->GetName());
|
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
ui->labelFullName->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->lineEditFullName->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
|
2015-12-01 15:56:05 +01:00
|
|
|
|
// Don't block all signal for QLineEdit. Need for correct handle with clear button.
|
2017-04-14 09:35:44 +02:00
|
|
|
|
disconnect(ui->lineEditName, &QLineEdit::textEdited, this, &TMainWindow::SaveMName);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->plainTextEditDescription->blockSignals(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
ui->plainTextEditDescription->setPlainText(meash->GetDescription());
|
2015-08-01 16:36:56 +02:00
|
|
|
|
ui->lineEditFullName->setText(meash->GetGuiText());
|
|
|
|
|
ui->lineEditName->setText(ClearCustomName(meash->GetName()));
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-01 16:36:56 +02:00
|
|
|
|
//Show known
|
2021-02-06 14:52:21 +01:00
|
|
|
|
ui->plainTextEditDescription->setPlainText(
|
|
|
|
|
VAbstractApplication::VApp()->TrVars()->Description(meash->GetName()));
|
|
|
|
|
ui->lineEditFullName->setText(VAbstractApplication::VApp()->TrVars()->GuiText(meash->GetName()));
|
2015-08-01 16:36:56 +02:00
|
|
|
|
ui->lineEditName->setText(nameField->text());
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
2017-04-14 09:35:44 +02:00
|
|
|
|
connect(ui->lineEditName, &QLineEdit::textEdited, this, &TMainWindow::SaveMName);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->plainTextEditDescription->blockSignals(false);
|
2015-07-25 10:54:39 +02:00
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
ui->labelMUnits->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->comboBoxMUnits->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
|
2020-10-03 17:45:21 +02:00
|
|
|
|
ui->comboBoxMUnits->blockSignals(true);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->comboBoxMUnits->setCurrentIndex(
|
|
|
|
|
ui->comboBoxMUnits->findData(static_cast<int>(meash->IsSpecialUnits() ? MUnits::Degrees : MUnits::Table)));
|
2020-10-03 17:45:21 +02:00
|
|
|
|
ui->comboBoxMUnits->blockSignals(false);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
|
2017-07-12 20:21:48 +02:00
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
2015-07-21 17:28:20 +02:00
|
|
|
|
{
|
2022-02-05 14:00:22 +01:00
|
|
|
|
ui->labelCalculated->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->labelCalculatedValue->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
|
|
|
|
|
ui->labelBaseValue->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->doubleSpinBoxBaseValue->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
|
|
|
|
|
ui->labelCorrection->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->doubleSpinBoxCorrection->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
|
|
|
|
|
ui->labelShiftA->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->doubleSpinBoxShiftA->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > 1)
|
|
|
|
|
{
|
|
|
|
|
ui->labelShiftB->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->doubleSpinBoxShiftB->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
ui->labelShiftC->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->doubleSpinBoxShiftC->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->labelCalculatedValue->blockSignals(true);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->blockSignals(true);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxShiftA->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxShiftB->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxShiftC->blockSignals(true);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
2020-10-03 16:47:42 +02:00
|
|
|
|
QString calculatedValue;
|
|
|
|
|
|
|
|
|
|
if (meash->IsSpecialUnits())
|
2020-10-03 17:45:21 +02:00
|
|
|
|
{
|
|
|
|
|
const qreal value = *data->DataVariables()->value(meash->GetName())->GetValue();
|
2021-02-06 14:52:21 +01:00
|
|
|
|
calculatedValue = VAbstractApplication::VApp()->LocaleToString(value) + QChar(QChar::Space) +
|
|
|
|
|
degreeSymbol;
|
2020-10-03 17:45:21 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
2020-10-03 16:47:42 +02:00
|
|
|
|
{
|
|
|
|
|
const QString postfix = UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch)
|
|
|
|
|
const qreal value = UnitConvertor(*data->DataVariables()->value(meash->GetName())->GetValue(), mUnit,
|
|
|
|
|
pUnit);
|
2021-02-06 14:52:21 +01:00
|
|
|
|
calculatedValue = VAbstractApplication::VApp()->LocaleToString(value) + QChar(QChar::Space) + postfix;
|
2020-10-03 16:47:42 +02:00
|
|
|
|
}
|
|
|
|
|
ui->labelCalculatedValue->setText(calculatedValue);
|
2015-08-18 13:53:30 +02:00
|
|
|
|
|
2017-05-23 09:45:04 +02:00
|
|
|
|
if (fresh)
|
|
|
|
|
{
|
|
|
|
|
ui->doubleSpinBoxBaseValue->setValue(meash->GetBase());
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->setValue(
|
|
|
|
|
meash->GetCorrection(currentDimensionA, currentDimensionB, currentDimensionC));
|
|
|
|
|
ui->doubleSpinBoxShiftA->setValue(meash->GetShiftA());
|
|
|
|
|
ui->doubleSpinBoxShiftB->setValue(meash->GetShiftB());
|
|
|
|
|
ui->doubleSpinBoxShiftC->setValue(meash->GetShiftC());
|
2017-05-23 09:45:04 +02:00
|
|
|
|
}
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(false);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->blockSignals(false);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxShiftA->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxShiftB->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxShiftC->blockSignals(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-02-05 14:00:22 +01:00
|
|
|
|
ui->labelCalculated->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->labelCalculatedValue->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
|
|
|
|
|
ui->labelFormula->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->plainTextEditFormula->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->pushButtonGrow->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->toolButtonExpr->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
|
|
|
|
|
ui->labelDimension->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
ui->comboBoxDimension->setVisible(meash->GetType() == VarType::Measurement);
|
|
|
|
|
|
2020-10-03 16:47:42 +02:00
|
|
|
|
EvalFormula(meash->GetFormula(), false, meash->GetData(), ui->labelCalculatedValue,
|
|
|
|
|
meash->IsSpecialUnits());
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
|
QString formula =
|
|
|
|
|
VTranslateVars::TryFormulaToUser(meash->GetFormula(),
|
|
|
|
|
VAbstractApplication::VApp()->Settings()->GetOsSeparator());
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->setPlainText(formula);
|
|
|
|
|
ui->plainTextEditFormula->blockSignals(false);
|
2020-10-15 08:35:08 +02:00
|
|
|
|
|
|
|
|
|
ui->comboBoxDimension->blockSignals(true);
|
|
|
|
|
ui->comboBoxDimension->setCurrentIndex(
|
|
|
|
|
ui->comboBoxDimension->findData(static_cast<int>(meash->GetDimension())));
|
|
|
|
|
ui->comboBoxDimension->blockSignals(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
MeasurementGUI();
|
2015-09-09 11:45:30 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MFields(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-29 17:20:59 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowMDiagram(const QString &name)
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const VTranslateVars *trv = VAbstractApplication::VApp()->TrVars();
|
2015-10-29 17:20:59 +01:00
|
|
|
|
const QString number = trv->MNumber(name);
|
|
|
|
|
|
|
|
|
|
if (number.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
ui->labelDiagram->setText(tr("<html><head/><body><p><span style=\" font-size:340pt;\">?</span></p>"
|
|
|
|
|
"<p align=\"center\">Unknown measurement</p></body></html>"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-15 16:48:48 +01:00
|
|
|
|
ui->labelDiagram->setText(QString("<html><head/><body><p align=\"center\">%1</p>"
|
2015-10-29 17:20:59 +01:00
|
|
|
|
"<p align=\"center\"><b>%2</b>. <i>%3</i></p></body></html>")
|
2018-03-14 14:39:15 +01:00
|
|
|
|
.arg(DialogMDataBase::ImgTag(number), number, trv->GuiText(name)));
|
2015-10-29 17:20:59 +01:00
|
|
|
|
}
|
|
|
|
|
// This part is very ugly, can't find better way to resize dockWidget.
|
|
|
|
|
ui->labelDiagram->adjustSize();
|
2015-11-15 16:48:48 +01:00
|
|
|
|
// And also those 50 px. DockWidget has some border. And i can't find how big it is.
|
2015-10-29 17:20:59 +01:00
|
|
|
|
// Can lead to problem in future.
|
|
|
|
|
ui->dockWidgetDiagram->setMaximumWidth(ui->labelDiagram->width()+50);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 18:24:47 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::DeployFormula()
|
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
|
SCASSERT(ui->plainTextEditFormula != nullptr)
|
|
|
|
|
SCASSERT(ui->pushButtonGrow != nullptr)
|
2015-10-05 15:52:18 +02:00
|
|
|
|
|
|
|
|
|
const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
|
|
|
|
|
2015-07-21 18:24:47 +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)
|
2019-01-06 12:29:57 +01:00
|
|
|
|
ui->pushButtonGrow->setIcon(QIcon::fromTheme(QStringLiteral("go-next"),
|
2015-07-21 18:24:47 +02:00
|
|
|
|
QIcon(":/icons/win.icon.theme/16x16/actions/go-next.png")));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->plainTextEditFormula->setFixedHeight(formulaBaseHeight);
|
|
|
|
|
//Set icon from theme (internal for Windows system)
|
2019-01-06 12:29:57 +01:00
|
|
|
|
ui->pushButtonGrow->setIcon(QIcon::fromTheme(QStringLiteral("go-down"),
|
2015-07-21 18:24:47 +02:00
|
|
|
|
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);
|
2015-10-05 15:52:18 +02:00
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->setFocus();
|
|
|
|
|
ui->plainTextEditFormula->setTextCursor(cursor);
|
2015-07-21 18:24:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-04-14 09:35:44 +02:00
|
|
|
|
void TMainWindow::SaveMName(const QString &text)
|
2015-07-22 11:44:31 +02:00
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
|
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
2015-10-01 16:59:01 +02:00
|
|
|
|
catch(const VExceptionBadId &e)
|
2015-09-29 16:04:24 +02:00
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-09-29 16:04:24 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2017-04-14 09:35:44 +02:00
|
|
|
|
QString newName = text;
|
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
2017-04-14 09:35:44 +02:00
|
|
|
|
newName.isEmpty() ? newName = GetCustomName() : newName = CustomMSign + newName;
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2017-04-14 09:35:44 +02:00
|
|
|
|
if (not data->IsUnique(newName))
|
2015-09-29 16:04:24 +02:00
|
|
|
|
{
|
2017-04-14 09:35:44 +02:00
|
|
|
|
qint32 num = 2;
|
|
|
|
|
QString name = newName;
|
|
|
|
|
do
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
name = name + QChar('_') + QString::number(num);
|
2017-04-14 09:35:44 +02:00
|
|
|
|
num++;
|
|
|
|
|
} while (not data->IsUnique(name));
|
|
|
|
|
newName = name;
|
2015-09-29 16:04:24 +02:00
|
|
|
|
}
|
2017-04-14 09:35:44 +02:00
|
|
|
|
|
|
|
|
|
m->SetMName(nameField->text(), newName);
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2017-04-14 09:35:44 +02:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2017-04-14 09:35:44 +02:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCWarning(tMainWindow, "%s", qUtf8Printable(tr("The name of known measurement forbidden to change.")));
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMValue()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
|
|
|
|
QString text = ui->plainTextEditFormula->toPlainText();
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
QTableWidgetItem *formulaField = ui->tableWidget->item(row, ColumnFormula);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
if (formulaField->text() == text)
|
|
|
|
|
{
|
2015-09-29 17:46:00 +02:00
|
|
|
|
QTableWidgetItem *result = ui->tableWidget->item(row, ColumnCalcValue);
|
2017-07-02 13:34:36 +02:00
|
|
|
|
const QString postfix = UnitsToStr(mUnit);//Show unit in dialog lable (cm, mm or inch)
|
2018-04-22 17:39:56 +02:00
|
|
|
|
ui->labelCalculatedValue->setText(result->text() + QChar(QChar::Space) +postfix);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
{
|
2017-07-02 13:34:36 +02:00
|
|
|
|
const QString postfix = UnitsToStr(mUnit);//Show unit in dialog lable (cm, mm or inch)
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 16:04:24 +02:00
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId & e)
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-09-29 16:04:24 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-08-25 12:35:50 +02:00
|
|
|
|
|
2020-10-03 16:47:42 +02:00
|
|
|
|
if (not EvalFormula(text, true, meash->GetData(), ui->labelCalculatedValue, meash->IsSpecialUnits()))
|
2015-08-25 12:35:50 +02:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const QString formula = VAbstractApplication::VApp()->TrVars()
|
|
|
|
|
->FormulaFromUser(text, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->SetMValue(nameField->data(Qt::UserRole).toString(), formula);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
}
|
2015-09-29 17:09:41 +02:00
|
|
|
|
catch (qmu::QmuParserError &e) // Just in case something bad will happen
|
2015-07-24 12:06:39 +02:00
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
|
Q_UNUSED(e)
|
2015-07-24 12:06:39 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->tableWidget->blockSignals(true);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->setTextCursor(cursor);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 08:10:56 +02:00
|
|
|
|
void TMainWindow::SaveMBaseValue(double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-11-22 15:31:31 +01:00
|
|
|
|
m->SetMBaseValue(nameField->data(Qt::UserRole).toString(), value);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2015-11-22 15:31:31 +01:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2015-11-22 15:31:31 +01:00
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
2016-06-22 20:07:06 +02:00
|
|
|
|
|
2017-05-23 09:45:04 +02:00
|
|
|
|
ShowNewMData(false);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 17:52:31 +02:00
|
|
|
|
void TMainWindow::SaveMShiftA(double value)
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
|
|
|
|
m->SetMShiftA(nameField->data(Qt::UserRole).toString(), value);
|
|
|
|
|
|
|
|
|
|
MeasurementsWereSaved(false);
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2020-10-03 17:52:31 +02:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ShowNewMData(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMShiftB(double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
m->SetMShiftB(nameField->data(Qt::UserRole).toString(), value);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2015-11-22 15:31:31 +01:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2015-11-22 15:31:31 +01:00
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
2016-06-22 20:07:06 +02:00
|
|
|
|
|
2017-05-23 09:45:04 +02:00
|
|
|
|
ShowNewMData(false);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 17:52:31 +02:00
|
|
|
|
void TMainWindow::SaveMShiftC(double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
m->SetMShiftC(nameField->data(Qt::UserRole).toString(), value);
|
|
|
|
|
|
|
|
|
|
MeasurementsWereSaved(false);
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2020-10-03 17:52:31 +02:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ShowNewMData(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMCorrectionValue(double value)
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
|
|
|
|
m->SetMCorrectionValue(nameField->data(Qt::UserRole).toString(),
|
|
|
|
|
currentDimensionA, currentDimensionB, currentDimensionC, value);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2015-11-22 15:31:31 +01:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2016-06-21 13:13:14 +02:00
|
|
|
|
ui->tableWidget->blockSignals(true);
|
2015-11-22 15:31:31 +01:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
2016-06-21 13:13:14 +02:00
|
|
|
|
ui->tableWidget->blockSignals(false);
|
2016-06-22 20:07:06 +02:00
|
|
|
|
|
2017-05-23 09:45:04 +02:00
|
|
|
|
ShowNewMData(false);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMDescription()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->SetMDescription(nameField->data(Qt::UserRole).toString(), ui->plainTextEditDescription->toPlainText());
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
const QTextCursor cursor = ui->plainTextEditDescription->textCursor();
|
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
|
RefreshData();
|
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->tableWidget->blockSignals(true);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ui->plainTextEditDescription->setTextCursor(cursor);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 10:54:39 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMFullName()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-07-25 10:54:39 +02:00
|
|
|
|
|
2015-10-03 00:00:18 +02:00
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
2015-07-25 10:54:39 +02:00
|
|
|
|
|
2015-10-03 00:00:18 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-25 10:54:39 +02:00
|
|
|
|
|
2015-10-03 00:00:18 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
m->SetMFullName(nameField->data(Qt::UserRole).toString(), ui->lineEditFullName->text());
|
|
|
|
|
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2015-10-03 00:00:18 +02:00
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s", qUtf8Printable(tr("The full name of known measurement forbidden to change.")));
|
|
|
|
|
}
|
2015-07-25 10:54:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMUnits()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
|
|
|
|
const MUnits units = static_cast<MUnits>(ui->comboBoxMUnits->currentData().toInt());
|
|
|
|
|
m->SetMSpecialUnits(nameField->data(Qt::UserRole).toString(), units == MUnits::Degrees);
|
|
|
|
|
|
|
|
|
|
MeasurementsWereSaved(false);
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2020-10-03 17:52:31 +02:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ShowNewMData(false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-15 08:35:08 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMDimension()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
|
|
|
|
const IMD dimension = static_cast<IMD>(ui->comboBoxDimension->currentData().toInt());
|
|
|
|
|
m->SetMDimension(nameField->data(Qt::UserRole).toString(), dimension);
|
|
|
|
|
|
|
|
|
|
MeasurementsWereSaved(false);
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2020-10-15 08:35:08 +02:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ShowNewMData(false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 18:26:56 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::FullCircumferenceChanged(bool checked)
|
|
|
|
|
{
|
|
|
|
|
m->SetFullCircumference(checked);
|
|
|
|
|
MeasurementsWereSaved(false);
|
|
|
|
|
InitDimensionsBaseValue();
|
2020-10-03 06:34:25 +02:00
|
|
|
|
InitDimensionControls();
|
2020-10-01 18:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 10:45:16 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ExportToIndividual()
|
|
|
|
|
{
|
|
|
|
|
QString dir;
|
|
|
|
|
if (curFile.isEmpty())
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
dir = MApplication::VApp()->TapeSettings()->GetPathIndividualMeasurements();
|
2020-10-05 10:45:16 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dir = QFileInfo(curFile).absolutePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool usedNotExistedDir = false;
|
|
|
|
|
QDir directory(dir);
|
|
|
|
|
if (not directory.exists())
|
|
|
|
|
{
|
|
|
|
|
usedNotExistedDir = directory.mkpath(QChar('.'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString filters = tr("Individual measurements") + QStringLiteral(" (*.vit)");
|
|
|
|
|
QString fName = tr("measurements.vit");
|
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Export to individual"), dir + QChar('/') + fName,
|
2021-02-06 14:52:21 +01:00
|
|
|
|
filters, nullptr, VAbstractApplication::VApp()->NativeFileDialog());
|
2020-10-05 10:45:16 +02:00
|
|
|
|
|
|
|
|
|
auto RemoveTempDir = qScopeGuard([usedNotExistedDir, dir]()
|
|
|
|
|
{
|
|
|
|
|
if (usedNotExistedDir)
|
|
|
|
|
{
|
|
|
|
|
QDir(dir).rmpath(QChar('.'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString suffix = QStringLiteral("vit");
|
|
|
|
|
QFileInfo f( fileName );
|
|
|
|
|
if (f.suffix().isEmpty() && f.suffix() != suffix)
|
|
|
|
|
{
|
|
|
|
|
fileName += QChar('.') + suffix;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
|
QScopedPointer<VContainer> tmpData(
|
|
|
|
|
new VContainer(VAbstractApplication::VApp()->TrVars(), &mUnit, VContainer::UniqueNamespace()));
|
2020-10-05 10:45:16 +02:00
|
|
|
|
|
|
|
|
|
VMeasurements individualMeasurements(mUnit, tmpData.data());
|
|
|
|
|
|
|
|
|
|
const QMap<int, QSharedPointer<VMeasurement> > orderedTable = OrderedMeasurments();
|
|
|
|
|
QMap<int, QSharedPointer<VMeasurement> >::const_iterator iMap;
|
|
|
|
|
for (iMap = orderedTable.constBegin(); iMap != orderedTable.constEnd(); ++iMap)
|
|
|
|
|
{
|
|
|
|
|
const QSharedPointer<VMeasurement> &meash = iMap.value();
|
|
|
|
|
individualMeasurements.AddEmpty(meash->GetName());
|
|
|
|
|
individualMeasurements.SetMValue(meash->GetName(), QString::number(*meash->GetValue()));
|
|
|
|
|
individualMeasurements.SetMSpecialUnits(meash->GetName(), meash->IsSpecialUnits());
|
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
individualMeasurements.SetMDescription(meash->GetName(), meash->GetDescription());
|
|
|
|
|
individualMeasurements.SetMFullName(meash->GetName(), meash->GetGuiText());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString error;
|
|
|
|
|
const bool result = individualMeasurements.SaveDocument(fileName, error);
|
|
|
|
|
if (not result)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox messageBox;
|
|
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
|
messageBox.setInformativeText(tr("Could not save the file"));
|
|
|
|
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
messageBox.setDetailedText(error);
|
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
|
messageBox.exec();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 14:14:38 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-19 20:13:17 +01:00
|
|
|
|
void TMainWindow::RestrictFirstDimesion()
|
2020-10-05 14:14:38 +02:00
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
2021-01-19 20:13:17 +01:00
|
|
|
|
const QMap<QString, VDimensionRestriction> restrictions = m->GetRestrictions();
|
|
|
|
|
bool fullCircumference = m->IsFullCircumference();
|
|
|
|
|
|
|
|
|
|
DialogRestrictDimension dialog(dimensions, restrictions, RestrictDimension::First, fullCircumference, this);
|
|
|
|
|
if (dialog.exec() == QDialog::Rejected)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m->SetRestrictions(dialog.Restrictions());
|
|
|
|
|
MeasurementsWereSaved(false);
|
|
|
|
|
|
|
|
|
|
if (not dimensions.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
InitDimensionGradation(0, dimensions.at(0), gradationDimensionA);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-05 14:14:38 +02:00
|
|
|
|
|
2021-01-19 20:13:17 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::RestrictSecondDimesion()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
const QMap<QString, VDimensionRestriction> restrictions = m->GetRestrictions();
|
2020-10-05 14:14:38 +02:00
|
|
|
|
bool fullCircumference = m->IsFullCircumference();
|
|
|
|
|
|
2021-01-19 20:13:17 +01:00
|
|
|
|
DialogRestrictDimension dialog(dimensions, restrictions, RestrictDimension::Second, fullCircumference, this);
|
2020-10-05 14:14:38 +02:00
|
|
|
|
if (dialog.exec() == QDialog::Rejected)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m->SetRestrictions(dialog.Restrictions());
|
|
|
|
|
MeasurementsWereSaved(false);
|
2020-10-07 16:14:12 +02:00
|
|
|
|
DimensionABaseChanged(); // trigger refresh
|
2020-10-05 14:14:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::RestrictThirdDimesion()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
2021-01-19 20:13:17 +01:00
|
|
|
|
const QMap<QString, VDimensionRestriction> restrictions = m->GetRestrictions();
|
2020-10-05 14:14:38 +02:00
|
|
|
|
bool fullCircumference = m->IsFullCircumference();
|
|
|
|
|
|
2021-01-19 20:13:17 +01:00
|
|
|
|
DialogRestrictDimension dialog(dimensions, restrictions, RestrictDimension::Third, fullCircumference, this);
|
2020-10-05 14:14:38 +02:00
|
|
|
|
if (dialog.exec() == QDialog::Rejected)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m->SetRestrictions(dialog.Restrictions());
|
|
|
|
|
MeasurementsWereSaved(false);
|
2020-10-07 16:14:12 +02:00
|
|
|
|
DimensionABaseChanged(); // trigger refresh
|
2020-10-05 14:14:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 12:34:38 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::EditDimensionLabels()
|
|
|
|
|
{
|
|
|
|
|
const QMap<MeasurementDimension, MeasurementDimension_p > dimensions = m->Dimensions();
|
|
|
|
|
|
|
|
|
|
DialogDimensionLabels dialog(dimensions, m->IsFullCircumference(), this);
|
|
|
|
|
if (dialog.exec() == QDialog::Rejected)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m->SetDimensionLabels(dialog.Labels());
|
|
|
|
|
|
|
|
|
|
MeasurementsWereSaved(false);
|
|
|
|
|
|
|
|
|
|
InitDimensionsBaseValue();
|
|
|
|
|
InitDimensionControls();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-14 12:26:24 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::DimensionCustomNames()
|
|
|
|
|
{
|
|
|
|
|
const QMap<MeasurementDimension, MeasurementDimension_p > dimensions = m->Dimensions();
|
|
|
|
|
|
|
|
|
|
DialogDimensionCustomNames dialog(dimensions, this);
|
|
|
|
|
if (dialog.exec() == QDialog::Rejected)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m->SetDimensionCustomNames(dialog.CustomNames());
|
|
|
|
|
|
|
|
|
|
MeasurementsWereSaved(false);
|
|
|
|
|
InitDimensionControls();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-12 16:19:53 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-10-19 13:43:20 +02:00
|
|
|
|
void TMainWindow::SetDefaultGUILanguage()
|
|
|
|
|
{
|
|
|
|
|
if (MApplication::VApp()->IsAppInGUIMode())
|
|
|
|
|
{
|
|
|
|
|
VTapeSettings *settings = MApplication::VApp()->TapeSettings();
|
|
|
|
|
if (not settings->IsLocaleSelected())
|
|
|
|
|
{
|
|
|
|
|
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
|
DialogSelectLanguage dialog(this);
|
|
|
|
|
QGuiApplication::restoreOverrideCursor();
|
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
|
{
|
|
|
|
|
QString locale = dialog.Locale();
|
|
|
|
|
settings->SetLocale(locale);
|
|
|
|
|
VAbstractApplication::VApp()->LoadTranslation(locale);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-12 16:19:53 +02:00
|
|
|
|
void TMainWindow::SetupMenu()
|
2015-07-10 13:14:55 +02:00
|
|
|
|
{
|
2015-07-12 17:56:34 +02:00
|
|
|
|
// File
|
2015-07-13 12:48:29 +02:00
|
|
|
|
connect(ui->actionNew, &QAction::triggered, this, &TMainWindow::FileNew);
|
|
|
|
|
ui->actionNew->setShortcuts(QKeySequence::New);
|
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
connect(ui->actionOpenIndividual, &QAction::triggered, this, &TMainWindow::OpenIndividual);
|
2017-07-12 20:21:48 +02:00
|
|
|
|
connect(ui->actionOpenMultisize, &QAction::triggered, this, &TMainWindow::OpenMultisize);
|
2015-07-25 14:59:40 +02:00
|
|
|
|
connect(ui->actionOpenTemplate, &QAction::triggered, this, &TMainWindow::OpenTemplate);
|
2015-10-15 14:37:10 +02:00
|
|
|
|
connect(ui->actionCreateFromExisting, &QAction::triggered, this, &TMainWindow::CreateFromExisting);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
|
|
|
|
connect(ui->actionSave, &QAction::triggered, this, &TMainWindow::FileSave);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
ui->actionSave->setShortcuts(QKeySequence::Save);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
|
|
|
|
connect(ui->actionSaveAs, &QAction::triggered, this, &TMainWindow::FileSaveAs);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
ui->actionSaveAs->setShortcuts(QKeySequence::SaveAs);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
2017-09-27 12:25:18 +02:00
|
|
|
|
connect(ui->actionExportToCSV, &QAction::triggered, this, &TMainWindow::ExportDataToCSV);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
connect(ui->actionImportFromCSV, &QAction::triggered, this, &TMainWindow::ImportDataFromCSV);
|
2017-05-30 18:52:38 +02:00
|
|
|
|
connect(ui->actionReadOnly, &QAction::triggered, this, [this](bool ro)
|
2017-02-04 12:28:47 +01:00
|
|
|
|
{
|
|
|
|
|
if (not mIsReadOnly)
|
|
|
|
|
{
|
|
|
|
|
m->SetReadOnly(ro);
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2017-02-04 12:28:47 +01:00
|
|
|
|
UpdatePadlock(ro);
|
|
|
|
|
UpdateWindowTitle();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
if (auto *action = qobject_cast< QAction * >(this->sender()))
|
2017-02-04 12:28:47 +01:00
|
|
|
|
{
|
|
|
|
|
action->setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-07-23 11:56:22 +02:00
|
|
|
|
connect(ui->actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
2019-09-06 21:18:18 +02:00
|
|
|
|
for (auto & recentFileAct : m_recentFileActs)
|
2016-02-18 12:18:14 +01:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
auto *action = new QAction(this);
|
|
|
|
|
recentFileAct = action;
|
2017-07-06 11:58:26 +02:00
|
|
|
|
connect(action, &QAction::triggered, this, [this]()
|
2016-07-18 21:58:14 +02:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
if (auto *senderAction = qobject_cast<QAction *>(sender()))
|
2016-07-18 21:58:14 +02:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
const QString filePath = senderAction->data().toString();
|
2016-07-18 21:58:14 +02:00
|
|
|
|
if (not filePath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
LoadFile(filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-01-06 12:29:57 +01:00
|
|
|
|
ui->menuFile->insertAction(ui->actionPreferences, recentFileAct);
|
|
|
|
|
recentFileAct->setVisible(false);
|
2016-02-18 12:18:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 21:18:18 +02:00
|
|
|
|
m_separatorAct = new QAction(this);
|
|
|
|
|
m_separatorAct->setSeparator(true);
|
|
|
|
|
m_separatorAct->setVisible(false);
|
|
|
|
|
ui->menuFile->insertAction(ui->actionPreferences, m_separatorAct );
|
2016-02-18 12:18:14 +01:00
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
|
connect(ui->actionQuit, &QAction::triggered, this, &TMainWindow::close);
|
|
|
|
|
ui->actionQuit->setShortcuts(QKeySequence::Quit);
|
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
|
// Measurements
|
|
|
|
|
connect(ui->actionAddCustom, &QAction::triggered, this, &TMainWindow::AddCustom);
|
|
|
|
|
connect(ui->actionAddKnown, &QAction::triggered, this, &TMainWindow::AddKnown);
|
2022-02-05 14:00:22 +01:00
|
|
|
|
connect(ui->actionAddSeparator, &QAction::triggered, this, &TMainWindow::AddSeparator);
|
2021-02-06 14:52:21 +01:00
|
|
|
|
connect(ui->actionDatabase, &QAction::triggered, MApplication::VApp(), &MApplication::ShowDataBase);
|
2015-08-11 16:52:18 +02:00
|
|
|
|
connect(ui->actionImportFromPattern, &QAction::triggered, this, &TMainWindow::ImportFromPattern);
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
|
// Window
|
|
|
|
|
connect(ui->menuWindow, &QMenu::aboutToShow, this, &TMainWindow::AboutToShowWindowMenu);
|
|
|
|
|
AboutToShowWindowMenu();
|
2015-07-10 13:14:55 +02:00
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
|
// Help
|
2017-05-30 18:52:38 +02:00
|
|
|
|
connect(ui->actionAboutQt, &QAction::triggered, this, [this]()
|
2016-12-21 19:45:14 +01:00
|
|
|
|
{
|
|
|
|
|
QMessageBox::aboutQt(this, tr("About Qt"));
|
|
|
|
|
});
|
2017-05-30 18:52:38 +02:00
|
|
|
|
connect(ui->actionAboutTape, &QAction::triggered, this, [this]()
|
2016-07-18 17:09:15 +02:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
auto *aboutDialog = new DialogAboutTape(this);
|
2016-07-18 17:09:15 +02:00
|
|
|
|
aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
aboutDialog->show();
|
|
|
|
|
});
|
2016-02-18 12:18:14 +01:00
|
|
|
|
|
|
|
|
|
//Actions for recent files loaded by a tape window application.
|
|
|
|
|
UpdateRecentFileActions();
|
|
|
|
|
|
2015-07-10 13:14:55 +02:00
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-16 11:38:54 +02:00
|
|
|
|
void TMainWindow::InitWindow()
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
|
SCASSERT(m != nullptr)
|
2015-07-13 12:48:29 +02:00
|
|
|
|
ui->labelToolTip->setVisible(false);
|
|
|
|
|
ui->tabWidget->setVisible(true);
|
2020-10-01 15:56:44 +02:00
|
|
|
|
ui->tabWidget->setCurrentIndex(0); // measurements
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
ui->plainTextEditNotes->setEnabled(true);
|
2015-08-18 13:53:30 +02:00
|
|
|
|
ui->toolBarGradation->setVisible(true);
|
2015-07-15 09:16:59 +02:00
|
|
|
|
|
2017-07-12 20:21:48 +02:00
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2020-10-01 18:26:56 +02:00
|
|
|
|
InitMenu();
|
2017-02-17 19:37:49 +01:00
|
|
|
|
ui->labelMType->setText(tr("Multisize measurements"));
|
2020-10-01 15:56:44 +02:00
|
|
|
|
|
|
|
|
|
InitDimensionsBaseValue();
|
2020-10-01 18:06:20 +02:00
|
|
|
|
HackDimensionBaseValue();
|
2015-07-14 18:28:50 +02:00
|
|
|
|
|
2015-09-03 12:31:23 +02:00
|
|
|
|
// Because Qt Designer doesn't know about our deleting we will create empty objects for correct
|
|
|
|
|
// working the retranslation UI
|
2015-07-13 12:48:29 +02:00
|
|
|
|
// Tab Measurements
|
2016-06-19 19:31:24 +02:00
|
|
|
|
HackWidget(&ui->horizontalLayoutValue);
|
|
|
|
|
HackWidget(&ui->plainTextEditFormula);
|
|
|
|
|
HackWidget(&ui->toolButtonExpr);
|
|
|
|
|
HackWidget(&ui->labelFormula);
|
|
|
|
|
HackWidget(&ui->pushButtonGrow);
|
2020-10-15 08:35:08 +02:00
|
|
|
|
HackWidget(&ui->labelDimension);
|
|
|
|
|
HackWidget(&ui->comboBoxDimension);
|
2015-09-03 12:31:23 +02:00
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
// Tab Information
|
2017-09-19 15:07:48 +02:00
|
|
|
|
HackWidget(&ui->lineEditCustomerName);
|
2016-06-19 19:31:24 +02:00
|
|
|
|
HackWidget(&ui->comboBoxGender);
|
|
|
|
|
HackWidget(&ui->lineEditEmail);
|
2017-09-19 15:07:48 +02:00
|
|
|
|
HackWidget(&ui->labelCustomerName);
|
2016-06-19 19:31:24 +02:00
|
|
|
|
HackWidget(&ui->labelBirthDate);
|
|
|
|
|
HackWidget(&ui->dateEditBirthDate);
|
|
|
|
|
HackWidget(&ui->labelGender);
|
|
|
|
|
HackWidget(&ui->labelEmail);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
|
2020-10-03 06:34:25 +02:00
|
|
|
|
InitDimensionControls();
|
|
|
|
|
ShowDimensionControls();
|
|
|
|
|
SetDimensionBases();
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
InitDimesionShifts();
|
|
|
|
|
|
2018-01-12 14:25:20 +01:00
|
|
|
|
connect(ui->doubleSpinBoxBaseValue, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
2015-07-25 08:10:56 +02:00
|
|
|
|
this, &TMainWindow::SaveMBaseValue);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
connect(ui->doubleSpinBoxCorrection, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
this, &TMainWindow::SaveMCorrectionValue);
|
|
|
|
|
|
|
|
|
|
connect(ui->doubleSpinBoxShiftA, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
this, &TMainWindow::SaveMShiftA);
|
|
|
|
|
connect(ui->doubleSpinBoxShiftB, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
this, &TMainWindow::SaveMShiftB);
|
|
|
|
|
connect(ui->doubleSpinBoxShiftC, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
this, &TMainWindow::SaveMShiftC);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
|
2020-10-03 17:45:21 +02:00
|
|
|
|
HackDimensionShifts();
|
|
|
|
|
|
2015-07-25 08:10:56 +02:00
|
|
|
|
SetDecimals();
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-14 18:28:50 +02:00
|
|
|
|
ui->labelMType->setText(tr("Individual measurements"));
|
|
|
|
|
|
2017-09-19 15:07:48 +02:00
|
|
|
|
ui->lineEditCustomerName->setEnabled(true);
|
2015-07-16 11:38:54 +02:00
|
|
|
|
ui->dateEditBirthDate->setEnabled(true);
|
2015-10-13 10:13:43 +02:00
|
|
|
|
ui->comboBoxGender->setEnabled(true);
|
2015-07-16 11:38:54 +02:00
|
|
|
|
ui->lineEditEmail->setEnabled(true);
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
// Tab Measurements
|
2016-06-19 19:31:24 +02:00
|
|
|
|
HackWidget(&ui->doubleSpinBoxBaseValue);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
HackWidget(&ui->doubleSpinBoxCorrection);
|
2016-06-19 19:31:24 +02:00
|
|
|
|
HackWidget(&ui->labelBaseValue);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
HackWidget(&ui->labelCorrection);
|
|
|
|
|
HackDimensionShifts();
|
2015-09-03 12:31:23 +02:00
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
// Tab Information
|
2020-10-01 18:06:20 +02:00
|
|
|
|
HackDimensionBaseValue();
|
2020-10-01 15:56:44 +02:00
|
|
|
|
HackWidget(&ui->frameBaseValue);
|
|
|
|
|
HackWidget(&ui->labelBaseValues);
|
2015-07-18 13:08:44 +02:00
|
|
|
|
|
2017-09-19 15:07:48 +02:00
|
|
|
|
ui->lineEditCustomerName->setText(m->Customer());
|
2015-07-18 13:08:44 +02:00
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
ui->comboBoxGender->clear();
|
|
|
|
|
InitGender(ui->comboBoxGender);
|
2015-10-13 10:13:43 +02:00
|
|
|
|
const qint32 index = ui->comboBoxGender->findData(static_cast<int>(m->Gender()));
|
|
|
|
|
ui->comboBoxGender->setCurrentIndex(index);
|
2015-07-18 13:08:44 +02:00
|
|
|
|
|
2017-05-23 15:01:41 +02:00
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const QLocale dateLocale = QLocale(VAbstractApplication::VApp()->Settings()->GetLocale());
|
2017-05-23 15:01:41 +02:00
|
|
|
|
ui->dateEditBirthDate->setLocale(dateLocale);
|
|
|
|
|
ui->dateEditBirthDate->setDisplayFormat(dateLocale.dateFormat());
|
|
|
|
|
ui->dateEditBirthDate->setDate(m->BirthDate());
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
|
ui->lineEditEmail->setText(m->Email());
|
|
|
|
|
|
2017-09-19 15:07:48 +02:00
|
|
|
|
connect(ui->lineEditCustomerName, &QLineEdit::editingFinished, this, &TMainWindow::SaveCustomerName);
|
2015-07-18 13:08:44 +02:00
|
|
|
|
connect(ui->lineEditEmail, &QLineEdit::editingFinished, this, &TMainWindow::SaveEmail);
|
2018-01-12 14:25:20 +01:00
|
|
|
|
connect(ui->comboBoxGender, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
2015-10-13 10:13:43 +02:00
|
|
|
|
&TMainWindow::SaveGender);
|
2015-07-18 13:08:44 +02:00
|
|
|
|
connect(ui->dateEditBirthDate, &QDateEdit::dateChanged, this, &TMainWindow::SaveBirthDate);
|
2015-07-21 18:24:47 +02:00
|
|
|
|
connect(ui->pushButtonGrow, &QPushButton::clicked, this, &TMainWindow::DeployFormula);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
this->formulaBaseHeight = ui->plainTextEditFormula->height();
|
|
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMValue,
|
|
|
|
|
Qt::UniqueConnection);
|
2015-07-24 14:06:53 +02:00
|
|
|
|
|
|
|
|
|
connect(ui->toolButtonExpr, &QToolButton::clicked, this, &TMainWindow::Fx);
|
2020-10-15 08:35:08 +02:00
|
|
|
|
|
|
|
|
|
InitMeasurementDimension();
|
|
|
|
|
connect(ui->comboBoxDimension, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
|
|
|
|
&TMainWindow::SaveMDimension);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
ui->comboBoxPMSystem->setEnabled(true);
|
|
|
|
|
ui->comboBoxPMSystem->clear();
|
|
|
|
|
InitPMSystems(ui->comboBoxPMSystem);
|
|
|
|
|
const qint32 index = ui->comboBoxPMSystem->findData(QLatin1Char('p')+m->PMSystem());
|
|
|
|
|
ui->comboBoxPMSystem->setCurrentIndex(index);
|
2018-01-12 14:25:20 +01:00
|
|
|
|
connect(ui->comboBoxPMSystem, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
2015-10-16 19:26:05 +02:00
|
|
|
|
&TMainWindow::SavePMSystem);
|
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
InitSearch();
|
2016-08-26 15:16:06 +02:00
|
|
|
|
|
2015-09-08 15:10:37 +02:00
|
|
|
|
ui->plainTextEditNotes->setPlainText(m->Notes());
|
|
|
|
|
connect(ui->plainTextEditNotes, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveNotes);
|
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
ui->actionAddCustom->setEnabled(true);
|
|
|
|
|
ui->actionAddKnown->setEnabled(true);
|
2022-02-05 14:00:22 +01:00
|
|
|
|
ui->actionAddSeparator->setEnabled(true);
|
2015-08-11 16:52:18 +02:00
|
|
|
|
ui->actionImportFromPattern->setEnabled(true);
|
2015-07-18 14:39:33 +02:00
|
|
|
|
ui->actionSaveAs->setEnabled(true);
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
2017-04-14 09:35:44 +02:00
|
|
|
|
ui->lineEditName->setValidator(new QRegularExpressionValidator(QRegularExpression(
|
2019-01-06 12:29:57 +01:00
|
|
|
|
QStringLiteral("^$|")+NameRegExp()),
|
2017-04-14 09:35:44 +02:00
|
|
|
|
this));
|
2015-07-22 11:47:51 +02:00
|
|
|
|
|
2015-07-22 08:41:04 +02:00
|
|
|
|
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &TMainWindow::Remove);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
connect(ui->toolButtonTop, &QToolButton::clicked, this, &TMainWindow::MoveTop);
|
2015-07-22 09:01:34 +02:00
|
|
|
|
connect(ui->toolButtonUp, &QToolButton::clicked, this, &TMainWindow::MoveUp);
|
|
|
|
|
connect(ui->toolButtonDown, &QToolButton::clicked, this, &TMainWindow::MoveDown);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
connect(ui->toolButtonBottom, &QToolButton::clicked, this, &TMainWindow::MoveBottom);
|
2015-07-22 08:41:04 +02:00
|
|
|
|
|
2017-04-14 09:35:44 +02:00
|
|
|
|
connect(ui->lineEditName, &QLineEdit::textEdited, this, &TMainWindow::SaveMName);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMDescription);
|
2015-12-01 15:56:05 +01:00
|
|
|
|
connect(ui->lineEditFullName, &QLineEdit::textEdited, this, &TMainWindow::SaveMFullName);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2017-05-30 18:52:38 +02:00
|
|
|
|
connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, this, [this]()
|
2016-12-21 19:45:14 +01:00
|
|
|
|
{
|
|
|
|
|
ShowInGraphicalShell(curFile);
|
|
|
|
|
});
|
2015-07-25 15:37:07 +02:00
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
InitPatternUnits();
|
|
|
|
|
InitMeasurementUnits();
|
|
|
|
|
|
|
|
|
|
ui->comboBoxMUnits->blockSignals(true);
|
|
|
|
|
ui->comboBoxMUnits->setCurrentIndex(-1);
|
|
|
|
|
ui->comboBoxMUnits->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
connect(ui->comboBoxMUnits, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &TMainWindow::SaveMUnits);
|
2015-08-18 13:53:30 +02:00
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
InitTable();
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 18:26:56 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitMenu()
|
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
|
|
|
|
{
|
2020-10-05 10:58:03 +02:00
|
|
|
|
// Measurements
|
|
|
|
|
ui->actionUseFullCircumference->setVisible(true);
|
|
|
|
|
ui->actionUseFullCircumference->setEnabled(true);
|
|
|
|
|
ui->actionUseFullCircumference->setChecked(m->IsFullCircumference());
|
|
|
|
|
connect(ui->actionUseFullCircumference, &QAction::triggered, this, &TMainWindow::FullCircumferenceChanged);
|
2020-10-01 18:26:56 +02:00
|
|
|
|
|
2020-10-05 10:58:03 +02:00
|
|
|
|
QAction *separator = new QAction(this);
|
|
|
|
|
separator->setSeparator(true);
|
|
|
|
|
ui->menuMeasurements->insertAction(ui->actionUseFullCircumference, separator);
|
2020-10-05 10:45:16 +02:00
|
|
|
|
|
2020-10-05 14:14:38 +02:00
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
2021-01-19 20:13:17 +01:00
|
|
|
|
if (dimensions.size() > 0)
|
2020-10-05 14:14:38 +02:00
|
|
|
|
{
|
2021-01-19 20:13:17 +01:00
|
|
|
|
ui->actionRestrictFirstDimension->setVisible(true);
|
|
|
|
|
ui->actionRestrictFirstDimension->setEnabled(true);
|
|
|
|
|
connect(ui->actionRestrictFirstDimension, &QAction::triggered, this, &TMainWindow::RestrictFirstDimesion);
|
2020-10-05 14:14:38 +02:00
|
|
|
|
|
2021-01-19 20:13:17 +01:00
|
|
|
|
if (dimensions.size() > 1)
|
2020-10-05 14:14:38 +02:00
|
|
|
|
{
|
2021-01-19 20:13:17 +01:00
|
|
|
|
ui->actionRestrictSecondDimension->setVisible(true);
|
|
|
|
|
ui->actionRestrictSecondDimension->setEnabled(true);
|
|
|
|
|
connect(ui->actionRestrictSecondDimension, &QAction::triggered, this,
|
|
|
|
|
&TMainWindow::RestrictSecondDimesion);
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
ui->actionRestrictThirdDimension->setVisible(true);
|
|
|
|
|
ui->actionRestrictThirdDimension->setEnabled(true);
|
|
|
|
|
connect(ui->actionRestrictThirdDimension, &QAction::triggered, this,
|
|
|
|
|
&TMainWindow::RestrictThirdDimesion);
|
|
|
|
|
}
|
2020-10-05 14:14:38 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 12:34:38 +02:00
|
|
|
|
ui->actionDimensionLabels->setVisible(true);
|
|
|
|
|
ui->actionDimensionLabels->setEnabled(true);
|
|
|
|
|
connect(ui->actionDimensionLabels, &QAction::triggered, this, &TMainWindow::EditDimensionLabels);
|
|
|
|
|
|
2022-02-14 12:26:24 +01:00
|
|
|
|
ui->actionDimensionCustomNames->setVisible(true);
|
|
|
|
|
ui->actionDimensionCustomNames->setEnabled(true);
|
|
|
|
|
connect(ui->actionDimensionCustomNames, &QAction::triggered, this, &TMainWindow::DimensionCustomNames);
|
|
|
|
|
|
2020-10-05 10:58:03 +02:00
|
|
|
|
// File
|
2020-10-05 10:45:16 +02:00
|
|
|
|
ui->actionExportToIndividual->setVisible(true);
|
|
|
|
|
ui->actionExportToIndividual->setEnabled(true);
|
|
|
|
|
connect(ui->actionExportToIndividual, &QAction::triggered, this, &TMainWindow::ExportToIndividual);
|
2020-10-01 18:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 15:56:44 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitDimensionsBaseValue()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
2021-05-07 10:19:06 +02:00
|
|
|
|
const QString unit = UnitsToStr(m->Units(), true);
|
2020-10-01 18:26:56 +02:00
|
|
|
|
const bool fc = m->IsFullCircumference();
|
2020-10-01 15:56:44 +02:00
|
|
|
|
|
2020-10-01 18:26:56 +02:00
|
|
|
|
auto DimensionsBaseValue = [this, dimensions, unit, fc](int index, QLabel *name, QLabel *base)
|
2020-10-01 15:56:44 +02:00
|
|
|
|
{
|
|
|
|
|
SCASSERT(name != nullptr)
|
|
|
|
|
SCASSERT(base != nullptr)
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > index)
|
|
|
|
|
{
|
|
|
|
|
MeasurementDimension_p dimension = dimensions.at(index);
|
2022-02-14 12:26:24 +01:00
|
|
|
|
name->setText(dimension->Name()+QChar(':'));
|
|
|
|
|
name->setToolTip(VAbstartMeasurementDimension::DimensionToolTip(dimension, m->IsFullCircumference()));
|
2020-10-01 15:56:44 +02:00
|
|
|
|
|
2020-10-08 12:34:38 +02:00
|
|
|
|
DimesionLabels labels = dimension->Labels();
|
|
|
|
|
|
|
|
|
|
if (labels.contains(dimension->BaseValue()) && not labels.value(dimension->BaseValue()).isEmpty())
|
|
|
|
|
{
|
|
|
|
|
base->setText(labels.value(dimension->BaseValue()));
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-10-01 15:56:44 +02:00
|
|
|
|
{
|
2022-07-19 19:00:34 +02:00
|
|
|
|
if (dimension->IsBodyMeasurement() || dimension->Type() == MeasurementDimension::X)
|
2020-10-01 18:26:56 +02:00
|
|
|
|
{
|
2020-10-08 12:34:38 +02:00
|
|
|
|
if (dimension->Type() != MeasurementDimension::X && fc)
|
|
|
|
|
{
|
|
|
|
|
base->setText(QString("%1 %2").arg(dimension->BaseValue()*2).arg(unit));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
base->setText(QString("%1 %2").arg(dimension->BaseValue()).arg(unit));
|
|
|
|
|
}
|
2020-10-01 18:26:56 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-10-08 12:34:38 +02:00
|
|
|
|
base->setText(QString::number(dimension->BaseValue()));
|
2020-10-01 18:26:56 +02:00
|
|
|
|
}
|
2020-10-01 15:56:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase);
|
|
|
|
|
DimensionsBaseValue(1, ui->labelDimensionB, ui->labelDimensionBBase);
|
|
|
|
|
DimensionsBaseValue(2, ui->labelDimensionC, ui->labelDimensionCBase);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 06:34:25 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p &dimension, QComboBox *control)
|
|
|
|
|
{
|
|
|
|
|
SCASSERT(control != nullptr)
|
|
|
|
|
|
|
|
|
|
const bool fc = m->IsFullCircumference();
|
2021-05-07 10:19:06 +02:00
|
|
|
|
const QString unit = UnitsToStr(m->Units(), true);
|
2020-10-03 06:34:25 +02:00
|
|
|
|
|
2021-01-18 19:43:53 +01:00
|
|
|
|
qreal current = -1;
|
2020-10-03 06:34:25 +02:00
|
|
|
|
if (control->currentIndex() != -1)
|
|
|
|
|
{
|
2021-01-18 19:43:53 +01:00
|
|
|
|
current = control->currentData().toDouble();
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
control->blockSignals(true);
|
|
|
|
|
control->clear();
|
|
|
|
|
|
2021-01-18 19:43:53 +01:00
|
|
|
|
const QVector<qreal> bases = DimensionRestrictedValues(index, dimension);
|
2020-10-08 12:34:38 +02:00
|
|
|
|
const DimesionLabels labels = dimension->Labels();
|
2020-10-06 17:00:53 +02:00
|
|
|
|
|
2020-10-03 06:34:25 +02:00
|
|
|
|
if (dimension->Type() == MeasurementDimension::X)
|
|
|
|
|
{
|
|
|
|
|
for(auto base : bases)
|
|
|
|
|
{
|
2020-10-08 12:34:38 +02:00
|
|
|
|
if (labels.contains(base) && not labels.value(base).isEmpty())
|
|
|
|
|
{
|
|
|
|
|
control->addItem(labels.value(base), base);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-07-23 09:47:52 +02:00
|
|
|
|
control->addItem(QStringLiteral("%1 %2").arg(base).arg(unit), base);
|
2020-10-08 12:34:38 +02:00
|
|
|
|
}
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-23 09:47:52 +02:00
|
|
|
|
else if (dimension->Type() == MeasurementDimension::Y || dimension->Type() == MeasurementDimension::W ||
|
|
|
|
|
dimension->Type() == MeasurementDimension::Z)
|
2020-10-03 06:34:25 +02:00
|
|
|
|
{
|
|
|
|
|
for(auto base : bases)
|
|
|
|
|
{
|
2020-10-08 12:34:38 +02:00
|
|
|
|
if (labels.contains(base) && not labels.value(base).isEmpty())
|
2020-10-03 06:34:25 +02:00
|
|
|
|
{
|
2020-10-08 12:34:38 +02:00
|
|
|
|
control->addItem(labels.value(base), base);
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-07-19 19:00:34 +02:00
|
|
|
|
if (dimension->IsBodyMeasurement())
|
2020-10-08 12:34:38 +02:00
|
|
|
|
{
|
2022-07-23 09:47:52 +02:00
|
|
|
|
control->addItem(QStringLiteral("%1 %2").arg(fc ? base*2 : base).arg(unit), base);
|
2020-10-08 12:34:38 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
control->addItem(QString::number(base), base);
|
|
|
|
|
}
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-07 16:14:12 +02:00
|
|
|
|
// after initialization the current index is 0. The signal for changing the index will not be triggered if not make
|
|
|
|
|
// it invalid first
|
|
|
|
|
control->setCurrentIndex(-1);
|
|
|
|
|
|
2020-10-03 06:34:25 +02:00
|
|
|
|
int i = control->findData(current);
|
|
|
|
|
if (i != -1)
|
|
|
|
|
{
|
|
|
|
|
control->setCurrentIndex(i);
|
|
|
|
|
control->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
control->blockSignals(false);
|
|
|
|
|
control->setCurrentIndex(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitDimensionControls()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
2021-05-07 10:19:06 +02:00
|
|
|
|
const QString unit = UnitsToStr(m->Units(), true);
|
2020-10-03 06:34:25 +02:00
|
|
|
|
|
2022-07-23 09:47:52 +02:00
|
|
|
|
auto InitControl = [this, dimensions](int index, QLabel *&name, QComboBox *&control)
|
2020-10-03 06:34:25 +02:00
|
|
|
|
{
|
|
|
|
|
if (dimensions.size() > index)
|
|
|
|
|
{
|
2022-02-14 12:26:24 +01:00
|
|
|
|
const MeasurementDimension_p& dimension = dimensions.at(index);
|
2020-10-03 06:34:25 +02:00
|
|
|
|
|
|
|
|
|
if (name == nullptr)
|
|
|
|
|
{
|
2022-02-14 12:26:24 +01:00
|
|
|
|
name = new QLabel(dimension->Name()+QChar(':'));
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-02-14 12:26:24 +01:00
|
|
|
|
name->setText(dimension->Name()+QChar(':'));
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
2022-02-14 12:26:24 +01:00
|
|
|
|
name->setToolTip(VAbstartMeasurementDimension::DimensionToolTip(dimension, m->IsFullCircumference()));
|
2020-10-03 06:34:25 +02:00
|
|
|
|
|
|
|
|
|
if (control == nullptr)
|
|
|
|
|
{
|
|
|
|
|
control = new QComboBox;
|
2022-02-12 16:42:32 +01:00
|
|
|
|
control->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InitDimensionGradation(index, dimension, control);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
InitControl(0, labelGradationDimensionA, gradationDimensionA);
|
|
|
|
|
InitControl(1, labelGradationDimensionB, gradationDimensionB);
|
|
|
|
|
InitControl(2, labelGradationDimensionC, gradationDimensionC);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitDimesionShifts()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
|
|
|
|
auto InitShift = [this, dimensions](int index, QLabel *name)
|
|
|
|
|
{
|
|
|
|
|
if (dimensions.size() > index)
|
|
|
|
|
{
|
|
|
|
|
MeasurementDimension_p dimension = dimensions.at(index);
|
|
|
|
|
|
2022-02-14 12:26:24 +01:00
|
|
|
|
name->setText(tr("Shift (%1):").arg(dimension->Name()));
|
|
|
|
|
name->setToolTip(VAbstartMeasurementDimension::DimensionToolTip(dimension, m->IsFullCircumference()));
|
2020-10-03 17:52:31 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
InitShift(0, ui->labelShiftA);
|
|
|
|
|
InitShift(1, ui->labelShiftB);
|
|
|
|
|
InitShift(2, ui->labelShiftC);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-16 11:38:54 +02:00
|
|
|
|
void TMainWindow::InitTable()
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2017-07-12 20:21:48 +02:00
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2015-09-29 17:46:00 +02:00
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnFormula, true );// formula
|
2020-10-03 17:52:31 +02:00
|
|
|
|
|
2021-03-26 15:27:17 +01:00
|
|
|
|
RetranslateTableHeaders();
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-29 17:46:00 +02:00
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnBaseValue, true );// base value
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnShiftA, true );
|
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnShiftB, true );
|
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnShiftC, true );
|
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnCorrection, true );
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
2015-07-21 17:28:20 +02:00
|
|
|
|
|
|
|
|
|
connect(ui->tableWidget, &QTableWidget::itemSelectionChanged, this, &TMainWindow::ShowMData);
|
2015-07-21 18:13:09 +02:00
|
|
|
|
|
|
|
|
|
ShowUnits();
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->resizeColumnsToContents();
|
|
|
|
|
ui->tableWidget->resizeRowsToContents();
|
2015-07-25 09:44:33 +02:00
|
|
|
|
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
|
2015-07-21 18:13:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowUnits()
|
|
|
|
|
{
|
2017-07-02 13:34:36 +02:00
|
|
|
|
const QString unit = UnitsToStr(mUnit);
|
2015-07-21 18:13:09 +02:00
|
|
|
|
|
2017-07-02 13:34:36 +02:00
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnCalcValue, UnitsToStr(pUnit));// calculated value
|
2015-09-29 17:46:00 +02:00
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnFormula, unit);// formula
|
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnBaseValue, unit);// base value
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnShiftA, unit);
|
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnShiftB, unit);
|
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnShiftC, unit);
|
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnCorrection, unit);
|
2015-07-21 18:13:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowHeaderUnits(QTableWidget *table, int column, const QString &unit)
|
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
|
SCASSERT(table != nullptr)
|
2015-07-21 18:13:09 +02:00
|
|
|
|
|
2015-08-18 13:53:30 +02:00
|
|
|
|
QString header = table->horizontalHeaderItem(column)->text();
|
2016-07-20 10:39:15 +02:00
|
|
|
|
const int index = header.indexOf(QLatin1String("("));
|
2015-08-18 13:53:30 +02:00
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
header.remove(index-1, 100);
|
|
|
|
|
}
|
2019-01-06 12:29:57 +01:00
|
|
|
|
const QString unitHeader = QStringLiteral("%1 (%2)").arg(header, unit);
|
2015-07-21 18:13:09 +02:00
|
|
|
|
table->horizontalHeaderItem(column)->setText(unitHeader);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
2015-07-18 14:39:33 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-08-01 18:25:36 +02:00
|
|
|
|
void TMainWindow::MeasurementsWereSaved(bool saved)
|
2015-07-18 14:39:33 +02:00
|
|
|
|
{
|
|
|
|
|
setWindowModified(!saved);
|
2017-02-04 12:28:47 +01:00
|
|
|
|
not mIsReadOnly ? ui->actionSave->setEnabled(!saved): ui->actionSave->setEnabled(false);
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetCurrentFile(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
curFile = fileName;
|
|
|
|
|
if (curFile.isEmpty())
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
ui->lineEditPathToFile->setText(QChar('<') + tr("Empty") + QChar('>'));
|
2015-12-01 15:38:09 +01:00
|
|
|
|
ui->lineEditPathToFile->setToolTip(tr("File was not saved yet."));
|
2016-06-18 15:57:07 +02:00
|
|
|
|
ui->lineEditPathToFile->setCursorPosition(0);
|
2015-07-25 15:37:07 +02:00
|
|
|
|
ui->pushButtonShowInExplorer->setEnabled(false);
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-12-01 15:38:09 +01:00
|
|
|
|
ui->lineEditPathToFile->setText(QDir::toNativeSeparators(curFile));
|
|
|
|
|
ui->lineEditPathToFile->setToolTip(QDir::toNativeSeparators(curFile));
|
2016-06-18 15:57:07 +02:00
|
|
|
|
ui->lineEditPathToFile->setCursorPosition(0);
|
2015-07-25 15:37:07 +02:00
|
|
|
|
ui->pushButtonShowInExplorer->setEnabled(true);
|
2021-02-06 14:52:21 +01:00
|
|
|
|
auto settings = MApplication::VApp()->TapeSettings();
|
2016-02-18 12:18:14 +01:00
|
|
|
|
QStringList files = settings->GetRecentFileList();
|
|
|
|
|
files.removeAll(fileName);
|
|
|
|
|
files.prepend(fileName);
|
|
|
|
|
while (files.size() > MaxRecentFiles)
|
|
|
|
|
{
|
|
|
|
|
files.removeLast();
|
|
|
|
|
}
|
|
|
|
|
settings->SetRecentFileList(files);
|
|
|
|
|
UpdateRecentFileActions();
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
2015-12-03 13:07:51 +01:00
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
UpdateWindowTitle();
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
bool TMainWindow::SaveMeasurements(const QString &fileName, QString &error)
|
|
|
|
|
{
|
|
|
|
|
const bool result = m->SaveDocument(fileName, error);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
SetCurrentFile(fileName);
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(result);
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2015-07-18 15:01:57 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
bool TMainWindow::MaybeSave()
|
|
|
|
|
{
|
|
|
|
|
if (this->isWindowModified())
|
|
|
|
|
{
|
2015-09-09 12:00:22 +02:00
|
|
|
|
if (curFile.isEmpty() && ui->tableWidget->rowCount() == 0)
|
|
|
|
|
{
|
|
|
|
|
return true;// Don't ask if file was created without modifications.
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-18 09:43:06 +01:00
|
|
|
|
QScopedPointer<QMessageBox> messageBox(new QMessageBox(tr("Unsaved changes"),
|
|
|
|
|
tr("Measurements have been modified.\n"
|
|
|
|
|
"Do you want to save your changes?"),
|
|
|
|
|
QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No,
|
|
|
|
|
QMessageBox::Cancel, this, Qt::Sheet));
|
2015-12-02 20:51:19 +01:00
|
|
|
|
|
|
|
|
|
messageBox->setDefaultButton(QMessageBox::Yes);
|
|
|
|
|
messageBox->setEscapeButton(QMessageBox::Cancel);
|
|
|
|
|
|
2017-09-24 09:33:49 +02:00
|
|
|
|
messageBox->setButtonText(QMessageBox::Yes, curFile.isEmpty() || mIsReadOnly ? tr("Save…") : tr("Save"));
|
2015-12-02 20:51:19 +01:00
|
|
|
|
messageBox->setButtonText(QMessageBox::No, tr("Don't Save"));
|
|
|
|
|
|
|
|
|
|
messageBox->setWindowModality(Qt::ApplicationModal);
|
2019-01-06 12:29:57 +01:00
|
|
|
|
const auto ret = static_cast<QMessageBox::StandardButton>(messageBox->exec());
|
2015-12-02 20:51:19 +01:00
|
|
|
|
|
|
|
|
|
switch (ret)
|
2015-07-18 15:01:57 +02:00
|
|
|
|
{
|
2015-12-02 20:51:19 +01:00
|
|
|
|
case QMessageBox::Yes:
|
2017-02-04 12:28:47 +01:00
|
|
|
|
if (mIsReadOnly)
|
|
|
|
|
{
|
|
|
|
|
return FileSaveAs();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return FileSave();
|
|
|
|
|
}
|
2015-12-02 20:51:19 +01:00
|
|
|
|
case QMessageBox::No:
|
|
|
|
|
return true;
|
|
|
|
|
case QMessageBox::Cancel:
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2015-07-18 15:01:57 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-09-29 16:04:24 +02:00
|
|
|
|
QTableWidgetItem *TMainWindow::AddCell(const QString &text, int row, int column, int aligment, bool ok)
|
2015-07-19 14:28:01 +02:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
auto *item = new QTableWidgetItem(text);
|
2015-08-01 15:00:33 +02:00
|
|
|
|
item->setTextAlignment(aligment);
|
2016-08-26 17:57:39 +02:00
|
|
|
|
item->setToolTip(text);
|
2015-07-21 19:26:33 +02:00
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
|
// 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);
|
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
if (not ok)
|
|
|
|
|
{
|
|
|
|
|
QBrush brush = item->foreground();
|
|
|
|
|
brush.setColor(Qt::red);
|
|
|
|
|
item->setForeground(brush);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
|
ui->tableWidget->setItem(row, column, item);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
|
|
|
|
|
return item;
|
2015-07-19 14:28:01 +02:00
|
|
|
|
}
|
2015-07-21 15:18:10 +02:00
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QTableWidgetItem *TMainWindow::AddSeparatorCell(const QString &text, int row, int column, int aligment, bool ok)
|
|
|
|
|
{
|
|
|
|
|
QTableWidgetItem *item = AddCell(text, row, column, aligment, ok);
|
|
|
|
|
|
|
|
|
|
QFont itemFont = item->font();
|
|
|
|
|
itemFont.setBold(true);
|
|
|
|
|
itemFont.setItalic(true);
|
|
|
|
|
item->setFont(itemFont);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 15:18:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-04-14 11:04:03 +02:00
|
|
|
|
void TMainWindow::RefreshData(bool freshCall)
|
2015-07-21 15:18:10 +02:00
|
|
|
|
{
|
2021-01-19 12:00:09 +01:00
|
|
|
|
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
|
|
|
|
|
2018-09-18 15:38:16 +02:00
|
|
|
|
data->ClearUniqueNames();
|
2022-02-05 14:00:22 +01:00
|
|
|
|
data->ClearVariables({VarType::Measurement, VarType::MeasurementSeparator});
|
2020-10-03 16:47:42 +02:00
|
|
|
|
m->ReadMeasurements(currentDimensionA, currentDimensionB, currentDimensionC);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
2017-04-14 11:04:03 +02:00
|
|
|
|
RefreshTable(freshCall);
|
2021-01-19 12:00:09 +01:00
|
|
|
|
|
|
|
|
|
QGuiApplication::restoreOverrideCursor();
|
2015-07-24 12:06:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-04-14 11:04:03 +02:00
|
|
|
|
void TMainWindow::RefreshTable(bool freshCall)
|
2015-07-24 12:06:39 +02:00
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->clearContents();
|
|
|
|
|
|
2016-05-03 22:16:57 +02:00
|
|
|
|
ShowUnits();
|
|
|
|
|
|
2020-10-05 10:45:16 +02:00
|
|
|
|
const QMap<int, QSharedPointer<VMeasurement> > orderedTable = OrderedMeasurments();
|
2015-07-24 12:06:39 +02:00
|
|
|
|
qint32 currentRow = -1;
|
|
|
|
|
QMap<int, QSharedPointer<VMeasurement> >::const_iterator iMap;
|
|
|
|
|
ui->tableWidget->setRowCount ( orderedTable.size() );
|
|
|
|
|
for (iMap = orderedTable.constBegin(); iMap != orderedTable.constEnd(); ++iMap)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
const QSharedPointer<VMeasurement> &meash = iMap.value();
|
2015-07-24 12:06:39 +02:00
|
|
|
|
currentRow++;
|
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
if (meash->GetType() == VarType::Measurement)
|
2015-07-24 12:06:39 +02:00
|
|
|
|
{
|
2022-02-05 14:00:22 +01:00
|
|
|
|
if (mType == MeasurementsType::Individual)
|
2015-09-29 17:46:00 +02:00
|
|
|
|
{
|
2022-02-05 14:00:22 +01:00
|
|
|
|
QTableWidgetItem *item = AddCell(VAbstractApplication::VApp()->TrVars()->MToUser(meash->GetName()),
|
|
|
|
|
currentRow, ColumnName, Qt::AlignVCenter); // name
|
|
|
|
|
item->setData(Qt::UserRole, meash->GetName());
|
2015-09-29 17:46:00 +02:00
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
AddCell(meash->GetGuiText(), currentRow, ColumnFullName, Qt::AlignVCenter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AddCell(VAbstractApplication::VApp()->TrVars()->GuiText(meash->GetName()), currentRow,
|
|
|
|
|
ColumnFullName, Qt::AlignVCenter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString calculatedValue;
|
|
|
|
|
if (meash->IsSpecialUnits())
|
|
|
|
|
{
|
|
|
|
|
calculatedValue = locale().toString(*meash->GetValue()) + degreeSymbol;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
calculatedValue = locale().toString(UnitConvertor(*meash->GetValue(), mUnit, pUnit));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddCell(calculatedValue, currentRow, ColumnCalcValue, Qt::AlignHCenter | Qt::AlignVCenter,
|
|
|
|
|
meash->IsFormulaOk()); // calculated value
|
|
|
|
|
|
|
|
|
|
QString formula =
|
|
|
|
|
VTranslateVars::TryFormulaToUser(meash->GetFormula(),
|
|
|
|
|
VAbstractApplication::VApp()->Settings()->GetOsSeparator());
|
|
|
|
|
|
|
|
|
|
AddCell(formula, currentRow, ColumnFormula, Qt::AlignVCenter); // formula
|
2020-10-03 16:47:42 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-02-05 14:00:22 +01:00
|
|
|
|
QTableWidgetItem *item = AddCell(VAbstractApplication::VApp()->TrVars()->MToUser(meash->GetName()),
|
|
|
|
|
currentRow, 0, Qt::AlignVCenter); // name
|
|
|
|
|
item->setData(Qt::UserRole, meash->GetName());
|
2020-10-03 16:47:42 +02:00
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
AddCell(meash->GetGuiText(), currentRow, ColumnFullName, Qt::AlignVCenter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AddCell(VAbstractApplication::VApp()->TrVars()->GuiText(meash->GetName()), currentRow,
|
|
|
|
|
ColumnFullName, Qt::AlignVCenter);
|
|
|
|
|
}
|
2015-07-21 15:18:10 +02:00
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
QString calculatedValue;
|
|
|
|
|
if (meash->IsSpecialUnits())
|
|
|
|
|
{
|
|
|
|
|
const qreal value = *data->DataVariables()->value(meash->GetName())->GetValue();
|
|
|
|
|
calculatedValue = locale().toString(value) + degreeSymbol;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const qreal value = UnitConvertor(*data->DataVariables()->value(meash->GetName())->GetValue(),
|
|
|
|
|
mUnit, pUnit);
|
|
|
|
|
calculatedValue = locale().toString(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddCell(calculatedValue, currentRow, ColumnCalcValue,
|
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter, meash->IsFormulaOk()); // calculated value
|
|
|
|
|
|
|
|
|
|
AddCell(locale().toString(meash->GetBase()), currentRow, ColumnBaseValue,
|
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter); // base value
|
|
|
|
|
|
|
|
|
|
AddCell(locale().toString(meash->GetShiftA()), currentRow, ColumnShiftA,
|
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
|
|
|
|
|
AddCell(locale().toString(meash->GetShiftB()), currentRow, ColumnShiftB,
|
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
|
|
|
|
|
AddCell(locale().toString(meash->GetShiftC()), currentRow, ColumnShiftC,
|
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
AddCell(locale()
|
|
|
|
|
.toString(meash->GetCorrection(currentDimensionA, currentDimensionB, currentDimensionC)),
|
|
|
|
|
currentRow, ColumnCorrection, Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
}
|
2015-07-24 12:06:39 +02:00
|
|
|
|
}
|
2022-02-05 14:00:22 +01:00
|
|
|
|
else if (meash->GetType() == VarType::MeasurementSeparator)
|
2015-07-24 12:06:39 +02:00
|
|
|
|
{
|
2022-02-17 17:44:03 +01:00
|
|
|
|
QTableWidgetItem *item = AddSeparatorCell(
|
|
|
|
|
VAbstractApplication::VApp()->TrVars()->MToUser(meash->GetName()), currentRow, ColumnName,
|
|
|
|
|
Qt::AlignVCenter); // name
|
2015-10-03 00:38:50 +02:00
|
|
|
|
item->setData(Qt::UserRole, meash->GetName());
|
2022-02-17 17:44:03 +01:00
|
|
|
|
AddCell(meash->GetDescription(), currentRow, ColumnFullName, Qt::AlignVCenter); // description
|
2015-08-01 15:00:33 +02:00
|
|
|
|
|
2022-02-05 14:00:22 +01:00
|
|
|
|
if (mType == MeasurementsType::Individual)
|
2015-09-29 17:46:00 +02:00
|
|
|
|
{
|
2022-02-05 14:00:22 +01:00
|
|
|
|
ui->tableWidget->setSpan(currentRow, 1, 1, 3);
|
2015-09-29 17:46:00 +02:00
|
|
|
|
}
|
2022-02-05 14:00:22 +01:00
|
|
|
|
else if (mType == MeasurementsType::Multisize)
|
2015-09-29 17:46:00 +02:00
|
|
|
|
{
|
2022-02-05 14:00:22 +01:00
|
|
|
|
ui->tableWidget->setSpan(currentRow, 1, 1, 8);
|
2015-09-29 17:46:00 +02:00
|
|
|
|
}
|
2015-07-24 12:06:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 11:04:03 +02:00
|
|
|
|
if (freshCall)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->resizeColumnsToContents();
|
|
|
|
|
ui->tableWidget->resizeRowsToContents();
|
|
|
|
|
}
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
2016-06-01 15:37:42 +02:00
|
|
|
|
|
2018-01-31 13:34:50 +01:00
|
|
|
|
ui->actionExportToCSV->setEnabled(ui->tableWidget->rowCount() > 0);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
}
|
2015-07-21 17:28:20 +02:00
|
|
|
|
|
2017-04-14 09:35:44 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString TMainWindow::GetCustomName() const
|
|
|
|
|
{
|
|
|
|
|
qint32 num = 1;
|
|
|
|
|
QString name;
|
|
|
|
|
do
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
name = CustomMSign + VAbstractApplication::VApp()->TrVars()->InternalVarToUser(measurement_) +
|
|
|
|
|
QString::number(num);
|
2017-04-14 09:35:44 +02:00
|
|
|
|
num++;
|
2019-01-06 12:29:57 +01:00
|
|
|
|
} while (not data->IsUnique(name));
|
2017-04-14 09:35:44 +02:00
|
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 17:28:20 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Controls()
|
|
|
|
|
{
|
|
|
|
|
if (ui->tableWidget->rowCount() > 0)
|
|
|
|
|
{
|
|
|
|
|
ui->toolButtonRemove->setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->toolButtonRemove->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->rowCount() >= 2)
|
|
|
|
|
{
|
|
|
|
|
if (ui->tableWidget->currentRow() == 0)
|
|
|
|
|
{
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonTop->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->toolButtonUp->setEnabled(false);
|
|
|
|
|
ui->toolButtonDown->setEnabled(true);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonBottom->setEnabled(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ui->tableWidget->currentRow() == ui->tableWidget->rowCount()-1)
|
|
|
|
|
{
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonTop->setEnabled(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->toolButtonUp->setEnabled(true);
|
|
|
|
|
ui->toolButtonDown->setEnabled(false);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonBottom->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonTop->setEnabled(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->toolButtonUp->setEnabled(true);
|
|
|
|
|
ui->toolButtonDown->setEnabled(true);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonBottom->setEnabled(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonTop->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->toolButtonUp->setEnabled(false);
|
|
|
|
|
ui->toolButtonDown->setEnabled(false);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonBottom->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MFields(bool enabled)
|
|
|
|
|
{
|
2015-09-09 11:45:30 +02:00
|
|
|
|
ui->lineEditName->setEnabled(enabled);
|
|
|
|
|
ui->plainTextEditDescription->setEnabled(enabled);
|
|
|
|
|
ui->lineEditFullName->setEnabled(enabled);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->comboBoxMUnits->setEnabled(enabled);
|
2015-09-09 11:45:30 +02:00
|
|
|
|
|
2017-07-12 20:21:48 +02:00
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
2015-07-21 17:28:20 +02:00
|
|
|
|
{
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setEnabled(enabled);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxShiftA->setEnabled(enabled);
|
|
|
|
|
ui->doubleSpinBoxShiftB->setEnabled(enabled);
|
|
|
|
|
ui->doubleSpinBoxShiftC->setEnabled(enabled);
|
|
|
|
|
ui->doubleSpinBoxCorrection->setEnabled(enabled);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-09 11:45:30 +02:00
|
|
|
|
ui->plainTextEditFormula->setEnabled(enabled);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->pushButtonGrow->setEnabled(enabled);
|
|
|
|
|
ui->toolButtonExpr->setEnabled(enabled);
|
2020-10-15 08:35:08 +02:00
|
|
|
|
ui->comboBoxDimension->setEnabled(enabled);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
2015-09-15 18:49:24 +02:00
|
|
|
|
|
|
|
|
|
ui->lineEditFind->setEnabled(enabled);
|
2016-08-26 15:16:06 +02:00
|
|
|
|
if (enabled && not ui->lineEditFind->text().isEmpty())
|
|
|
|
|
{
|
|
|
|
|
ui->toolButtonFindPrevious->setEnabled(enabled);
|
|
|
|
|
ui->toolButtonFindNext->setEnabled(enabled);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->toolButtonFindPrevious->setEnabled(false);
|
|
|
|
|
ui->toolButtonFindNext->setEnabled(false);
|
|
|
|
|
}
|
2019-12-05 09:27:33 +01:00
|
|
|
|
|
|
|
|
|
Controls();
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::UpdateWindowTitle()
|
|
|
|
|
{
|
|
|
|
|
QString showName;
|
|
|
|
|
bool isFileWritable = true;
|
|
|
|
|
if (not curFile.isEmpty())
|
|
|
|
|
{
|
2022-03-17 12:35:49 +01:00
|
|
|
|
//#ifdef Q_OS_WIN32
|
|
|
|
|
// qt_ntfs_permission_lookup++; // turn checking on
|
|
|
|
|
//#endif /*Q_OS_WIN32*/
|
2017-02-04 12:28:47 +01:00
|
|
|
|
isFileWritable = QFileInfo(curFile).isWritable();
|
2022-03-17 12:35:49 +01:00
|
|
|
|
//#ifdef Q_OS_WIN32
|
|
|
|
|
// qt_ntfs_permission_lookup--; // turn it off again
|
|
|
|
|
//#endif /*Q_OS_WIN32*/
|
2017-02-04 12:28:47 +01:00
|
|
|
|
showName = StrippedName(curFile);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-05-21 19:51:46 +02:00
|
|
|
|
int index = MApplication::VApp()->MainWindows().indexOf(this);
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
showName = tr("untitled %1").arg(index+1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
showName = tr("untitled");
|
|
|
|
|
}
|
2017-07-12 20:21:48 +02:00
|
|
|
|
mType == MeasurementsType::Multisize ? showName += QLatin1String(".vst") : showName += QLatin1String(".vit");
|
2017-02-04 12:28:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showName += QLatin1String("[*]");
|
|
|
|
|
|
|
|
|
|
if (mIsReadOnly || not isFileWritable)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
showName += QStringLiteral(" (") + tr("read only") + QChar(')');
|
2017-02-04 12:28:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setWindowTitle(showName);
|
|
|
|
|
setWindowFilePath(curFile);
|
|
|
|
|
|
|
|
|
|
#if defined(Q_OS_MAC)
|
2017-07-09 08:02:26 +02:00
|
|
|
|
static QIcon fileIcon = QIcon(QCoreApplication::applicationDirPath() +
|
2017-02-04 12:28:47 +01:00
|
|
|
|
QLatin1String("/../Resources/measurements.icns"));
|
|
|
|
|
QIcon icon;
|
|
|
|
|
if (not curFile.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (not isWindowModified())
|
|
|
|
|
{
|
|
|
|
|
icon = fileIcon;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
static QIcon darkIcon;
|
|
|
|
|
|
|
|
|
|
if (darkIcon.isNull())
|
|
|
|
|
{
|
|
|
|
|
darkIcon = QIcon(darkenPixmap(fileIcon.pixmap(16, 16)));
|
|
|
|
|
}
|
|
|
|
|
icon = darkIcon;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setWindowIcon(icon);
|
|
|
|
|
#endif //defined(Q_OS_MAC)
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 17:28:20 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString TMainWindow::ClearCustomName(const QString &name) const
|
|
|
|
|
{
|
|
|
|
|
QString clear = name;
|
2015-08-25 12:35:50 +02:00
|
|
|
|
const int index = clear.indexOf(CustomMSign);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
|
|
|
|
clear.remove(0, 1);
|
|
|
|
|
}
|
|
|
|
|
return clear;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 16:47:42 +02:00
|
|
|
|
bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label,
|
|
|
|
|
bool specialUnits)
|
2015-07-21 17:28:20 +02:00
|
|
|
|
{
|
2020-10-03 16:47:42 +02:00
|
|
|
|
const QString postfix = specialUnits ? degreeSymbol : UnitsToStr(pUnit);
|
|
|
|
|
|
2015-07-21 17:28:20 +02:00
|
|
|
|
if (formula.isEmpty())
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
label->setText(tr("Error") + QStringLiteral(" (") + postfix + QStringLiteral("). ") + tr("Empty field."));
|
2015-07-21 17:28:20 +02:00
|
|
|
|
label->setToolTip(tr("Empty field"));
|
2015-08-25 12:35:50 +02:00
|
|
|
|
return false;
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
2019-01-06 12:29:57 +01:00
|
|
|
|
|
|
|
|
|
try
|
2015-07-21 17:28:20 +02:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
// Replace line return character with spaces for calc if exist
|
|
|
|
|
QString f;
|
|
|
|
|
if (fromUser)
|
2015-07-21 17:28:20 +02:00
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
f = VAbstractApplication::VApp()->TrVars()
|
|
|
|
|
->FormulaFromUser(formula, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
2019-01-06 12:29:57 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
f = formula;
|
|
|
|
|
}
|
|
|
|
|
QScopedPointer<Calculator> cal(new Calculator());
|
|
|
|
|
qreal result = cal->EvalFormula(data->DataVariables(), f);
|
|
|
|
|
|
|
|
|
|
if (qIsInf(result) || qIsNaN(result))
|
2015-07-21 17:28:20 +02:00
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
label->setText(tr("Error") + " (" + postfix + ").");
|
|
|
|
|
label->setToolTip(tr("Invalid result. Value is infinite or NaN. Please, check your calculations."));
|
2015-08-25 12:35:50 +02:00
|
|
|
|
return false;
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
2019-01-06 12:29:57 +01:00
|
|
|
|
|
2020-10-03 16:47:42 +02:00
|
|
|
|
if (not specialUnits)
|
|
|
|
|
{
|
|
|
|
|
result = UnitConvertor(result, mUnit, pUnit);
|
|
|
|
|
}
|
2019-01-06 12:29:57 +01:00
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
|
label->setText(VAbstractApplication::VApp()->LocaleToString(result) + QChar(QChar::Space) +postfix);
|
2019-01-06 12:29:57 +01:00
|
|
|
|
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;
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-25 08:10:56 +02:00
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Open(const QString &pathTo, const QString &filter)
|
|
|
|
|
{
|
2020-12-17 17:43:15 +01:00
|
|
|
|
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), pathTo, filter, nullptr,
|
2021-02-06 14:52:21 +01:00
|
|
|
|
VAbstractApplication::VApp()->NativeFileDialog());
|
2015-07-25 14:59:40 +02:00
|
|
|
|
|
2016-09-27 11:27:52 +02:00
|
|
|
|
if (not mPath.isEmpty())
|
2015-07-25 14:59:40 +02:00
|
|
|
|
{
|
2016-09-27 11:27:52 +02:00
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
|
|
|
|
LoadFile(mPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
MApplication::VApp()->NewMainWindow()->LoadFile(mPath);
|
2016-09-27 11:27:52 +02:00
|
|
|
|
}
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 17:18:01 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-04 12:28:47 +01:00
|
|
|
|
void TMainWindow::UpdatePadlock(bool ro)
|
2015-07-25 17:18:01 +02:00
|
|
|
|
{
|
|
|
|
|
ui->actionReadOnly->setChecked(ro);
|
|
|
|
|
if (ro)
|
|
|
|
|
{
|
|
|
|
|
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_locked.png"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_opened.png"));
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
ui->actionReadOnly->setDisabled(mIsReadOnly);
|
2015-09-09 11:45:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-04 12:28:47 +01:00
|
|
|
|
void TMainWindow::MeasurementGUI()
|
2015-09-09 11:45:30 +02:00
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
|
if (const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName))
|
2015-07-25 17:18:01 +02:00
|
|
|
|
{
|
2017-02-04 12:28:47 +01:00
|
|
|
|
const bool isCustom = not (nameField->text().indexOf(CustomMSign) == 0);
|
|
|
|
|
ui->lineEditName->setReadOnly(isCustom);
|
|
|
|
|
ui->plainTextEditDescription->setReadOnly(isCustom);
|
|
|
|
|
ui->lineEditFullName->setReadOnly(isCustom);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
|
|
|
|
// Need to block signals for QLineEdit in readonly mode because it still emits
|
|
|
|
|
// QLineEdit::editingFinished signal.
|
2017-02-04 12:28:47 +01:00
|
|
|
|
ui->lineEditName->blockSignals(isCustom);
|
|
|
|
|
ui->lineEditFullName->blockSignals(isCustom);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
Controls(); // Buttons remove, up, down
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-01 19:09:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ReadSettings()
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const VTapeSettings *settings = MApplication::VApp()->TapeSettings();
|
2015-08-01 19:09:10 +02:00
|
|
|
|
|
2018-09-09 11:39:19 +02:00
|
|
|
|
if (settings->status() == QSettings::NoError)
|
|
|
|
|
{
|
|
|
|
|
restoreGeometry(settings->GetGeometry());
|
|
|
|
|
restoreState(settings->GetWindowState());
|
2021-09-24 13:57:30 +02:00
|
|
|
|
restoreState(settings->GetToolbarsState(), AppVersion());
|
2018-09-09 11:39:19 +02:00
|
|
|
|
|
|
|
|
|
// Text under tool buton icon
|
|
|
|
|
ToolBarStyles();
|
2017-04-12 14:50:48 +02:00
|
|
|
|
|
2018-09-09 11:39:19 +02:00
|
|
|
|
// Stack limit
|
2021-02-06 14:52:21 +01:00
|
|
|
|
//VAbstractApplication::VApp()->getUndoStack()->setUndoLimit(settings->GetUndoCount());
|
2018-09-09 11:39:19 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-21 08:28:15 +01:00
|
|
|
|
qWarning() << tr("Cannot read settings from a malformed .INI file.");
|
2018-09-09 11:39:19 +02:00
|
|
|
|
}
|
2015-08-01 19:09:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::WriteSettings()
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
VTapeSettings *settings = MApplication::VApp()->TapeSettings();
|
2015-10-28 15:22:36 +01:00
|
|
|
|
settings->SetGeometry(saveGeometry());
|
|
|
|
|
settings->SetWindowState(saveState());
|
2021-09-24 13:57:30 +02:00
|
|
|
|
settings->SetToolbarsState(saveState(AppVersion()));
|
2018-09-09 11:39:19 +02:00
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
settings->SetTapeSearchOptionMatchCase(m_search->IsMatchCase());
|
|
|
|
|
settings->SetTapeSearchOptionWholeWord(m_search->IsMatchWord());
|
|
|
|
|
settings->SetTapeSearchOptionRegexp(m_search->IsMatchRegexp());
|
|
|
|
|
settings->SetTapeSearchOptionUseUnicodeProperties(m_search->IsUseUnicodePreperties());
|
|
|
|
|
|
2018-09-09 11:39:19 +02:00
|
|
|
|
settings->sync();
|
|
|
|
|
if (settings->status() == QSettings::AccessError)
|
|
|
|
|
{
|
|
|
|
|
qWarning() << tr("Cannot save settings. Access denied.");
|
|
|
|
|
}
|
2015-08-01 19:09:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-11 16:52:18 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QStringList TMainWindow::FilterMeasurements(const QStringList &mNew, const QStringList &mFilter)
|
|
|
|
|
{
|
2020-01-16 18:09:23 +01:00
|
|
|
|
return ConvertToList(ConvertToSet<QString>(mNew).subtract(ConvertToSet<QString>(mFilter)));
|
2015-08-11 16:52:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 15:31:21 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::UpdatePatternUnit()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshTable();
|
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2015-09-15 18:49:24 +02:00
|
|
|
|
|
2015-08-18 15:31:21 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 14:37:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
bool TMainWindow::LoadFromExistingFile(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
2018-03-14 14:39:15 +01:00
|
|
|
|
if (not QFileInfo::exists(path))
|
2015-10-15 14:37:10 +02:00
|
|
|
|
{
|
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("File '%1' doesn't exist!").arg(path)));
|
2021-02-06 14:52:21 +01:00
|
|
|
|
if (MApplication::VApp()->IsTestMode())
|
2015-10-15 14:37:10 +02:00
|
|
|
|
{
|
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if file already opened
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const QList<TMainWindow*> list = MApplication::VApp()->MainWindows();
|
2021-05-21 17:08:37 +02:00
|
|
|
|
auto w = std::find_if(list.begin(), list.end(),
|
|
|
|
|
[path](TMainWindow *window) { return window->CurrentFile() == path; });
|
|
|
|
|
if (w != list.end())
|
2015-10-15 14:37:10 +02:00
|
|
|
|
{
|
2021-05-21 17:08:37 +02:00
|
|
|
|
(*w)->activateWindow();
|
|
|
|
|
close();
|
|
|
|
|
return false;
|
2015-10-15 14:37:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 01:58:39 +01:00
|
|
|
|
VlpCreateLock(lock, path);
|
2015-10-15 14:37:10 +02:00
|
|
|
|
|
|
|
|
|
if (not lock->IsLocked())
|
|
|
|
|
{
|
2021-05-21 17:08:37 +02:00
|
|
|
|
if (not IgnoreLocking(lock->GetLockError(), path, MApplication::VApp()->IsAppInGUIMode()))
|
2015-10-15 14:37:10 +02:00
|
|
|
|
{
|
2015-12-23 14:26:29 +01:00
|
|
|
|
return false;
|
2015-10-15 14:37:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
data = new VContainer(VAbstractApplication::VApp()->TrVars(), &mUnit, VContainer::UniqueNamespace());
|
2015-10-15 14:37:10 +02:00
|
|
|
|
|
|
|
|
|
m = new VMeasurements(data);
|
|
|
|
|
m->setXMLContent(path);
|
|
|
|
|
|
|
|
|
|
mType = m->Type();
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Unknown)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
throw VException(tr("File has unknown format."));
|
2015-10-15 14:37:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 09:29:03 +02:00
|
|
|
|
QScopedPointer<VAbstractMConverter> converter(
|
|
|
|
|
(mType == MeasurementsType::Individual) ? static_cast<VAbstractMConverter*>(new VVITConverter(path))
|
|
|
|
|
: static_cast<VAbstractMConverter*>(new VVSTConverter(path)));
|
2015-10-15 14:37:10 +02:00
|
|
|
|
|
2022-07-01 09:29:03 +02:00
|
|
|
|
m_curFileFormatVersion = converter->GetCurrentFormatVersion();
|
|
|
|
|
m_curFileFormatVersionStr = converter->GetFormatVersionStr();
|
|
|
|
|
m->setXMLContent(converter->Convert());// Read again after conversion
|
2019-01-06 12:29:57 +01:00
|
|
|
|
|
2015-10-15 14:37:10 +02:00
|
|
|
|
if (not m->IsDefinedKnownNamesValid())
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
throw VException(tr("File contains invalid known measurement(s)."));
|
2015-10-15 14:37:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 10:19:06 +02:00
|
|
|
|
mUnit = m->Units();
|
2015-10-15 14:37:10 +02:00
|
|
|
|
pUnit = mUnit;
|
|
|
|
|
|
2020-10-07 17:09:27 +02:00
|
|
|
|
currentDimensionA = m->DimensionABase();
|
|
|
|
|
currentDimensionB = m->DimensionBBase();
|
|
|
|
|
currentDimensionC = m->DimensionCBase();
|
2015-10-15 14:37:10 +02:00
|
|
|
|
|
|
|
|
|
ui->labelToolTip->setVisible(false);
|
|
|
|
|
ui->tabWidget->setVisible(true);
|
|
|
|
|
|
|
|
|
|
InitWindow();
|
|
|
|
|
|
|
|
|
|
m->ClearForExport();
|
2017-04-14 11:04:03 +02:00
|
|
|
|
const bool freshCall = true;
|
|
|
|
|
RefreshData(freshCall);
|
2015-10-15 14:37:10 +02:00
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->rowCount() > 0)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->selectRow(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lock.reset();// Now we can unlock the file
|
|
|
|
|
|
2017-02-04 12:28:47 +01:00
|
|
|
|
mIsReadOnly = m->IsReadOnly();
|
|
|
|
|
UpdatePadlock(mIsReadOnly);
|
|
|
|
|
MeasurementGUI();
|
2015-10-15 14:37:10 +02:00
|
|
|
|
}
|
|
|
|
|
catch (VException &e)
|
|
|
|
|
{
|
|
|
|
|
qCCritical(tMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
|
|
|
|
ui->labelToolTip->setVisible(true);
|
|
|
|
|
ui->tabWidget->setVisible(false);
|
|
|
|
|
delete m;
|
|
|
|
|
m = nullptr;
|
|
|
|
|
delete data;
|
|
|
|
|
data = nullptr;
|
|
|
|
|
lock.reset();
|
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
|
if (MApplication::VApp()->IsTestMode())
|
2015-10-15 14:37:10 +02:00
|
|
|
|
{
|
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
return MApplication::VApp()->NewMainWindow()->LoadFile(path);
|
2015-10-15 14:37:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-03 09:43:31 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::CreateWindowMenu(QMenu *menu)
|
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
|
SCASSERT(menu != nullptr)
|
2015-12-03 09:43:31 +01:00
|
|
|
|
|
2016-07-18 17:09:15 +02:00
|
|
|
|
QAction *action = menu->addAction(tr("&New Window"));
|
2018-04-02 15:43:02 +02:00
|
|
|
|
connect(action, &QAction::triggered, this, []()
|
2016-07-18 17:09:15 +02:00
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
|
MApplication::VApp()->NewMainWindow()->activateWindow();
|
2016-07-18 17:09:15 +02:00
|
|
|
|
});
|
2015-12-03 09:43:31 +01:00
|
|
|
|
action->setMenuRole(QAction::NoRole);
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const QList<TMainWindow*> windows = MApplication::VApp()->MainWindows();
|
2015-12-03 09:43:31 +01:00
|
|
|
|
for (int i = 0; i < windows.count(); ++i)
|
|
|
|
|
{
|
|
|
|
|
TMainWindow *window = windows.at(i);
|
|
|
|
|
|
2019-01-06 12:29:57 +01:00
|
|
|
|
QString title = QStringLiteral("%1. %2").arg(i+1).arg(window->windowTitle());
|
|
|
|
|
const int index = title.lastIndexOf(QLatin1String("[*]"));
|
2015-12-03 09:43:31 +01:00
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
2019-01-06 12:29:57 +01:00
|
|
|
|
window->isWindowModified() ? title.replace(index, 3, QChar('*')) : title.replace(index, 3, QString());
|
2015-12-03 09:43:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-22 08:21:01 +02:00
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
|
|
|
|
|
QAction *action = menu->addAction(title, this, SLOT(ShowWindow()));
|
|
|
|
|
#else
|
2021-05-20 17:33:53 +02:00
|
|
|
|
QAction *action = menu->addAction(title, this, &TMainWindow::ShowWindow);
|
2021-05-22 08:21:01 +02:00
|
|
|
|
#endif //QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
|
2015-12-03 09:43:31 +01:00
|
|
|
|
action->setData(i);
|
|
|
|
|
action->setCheckable(true);
|
|
|
|
|
action->setMenuRole(QAction::NoRole);
|
2015-12-05 10:50:32 +01:00
|
|
|
|
if (window->isActiveWindow())
|
2015-12-03 09:43:31 +01:00
|
|
|
|
{
|
|
|
|
|
action->setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-01 18:06:20 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::HackDimensionBaseValue()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
|
|
|
|
auto DimensionsBaseValue = [this, dimensions](int index, QLabel *name, QLabel *base)
|
|
|
|
|
{
|
|
|
|
|
SCASSERT(name != nullptr)
|
|
|
|
|
SCASSERT(base != nullptr)
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() <= index)
|
|
|
|
|
{
|
|
|
|
|
HackWidget(&name);
|
|
|
|
|
HackWidget(&base);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DimensionsBaseValue(0, ui->labelDimensionA, ui->labelDimensionABase);
|
|
|
|
|
DimensionsBaseValue(1, ui->labelDimensionB, ui->labelDimensionBBase);
|
|
|
|
|
DimensionsBaseValue(2, ui->labelDimensionC, ui->labelDimensionCBase);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::HackDimensionShifts()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
2020-10-03 17:45:21 +02:00
|
|
|
|
auto HackShift = [this, dimensions](int index, QLabel *&name, QDoubleSpinBox *&shift)
|
2020-10-03 17:52:31 +02:00
|
|
|
|
{
|
|
|
|
|
SCASSERT(name != nullptr)
|
|
|
|
|
SCASSERT(shift != nullptr)
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() <= index)
|
|
|
|
|
{
|
|
|
|
|
HackWidget(&name);
|
|
|
|
|
HackWidget(&shift);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HackShift(0, ui->labelShiftA, ui->doubleSpinBoxShiftA);
|
2020-10-03 17:45:21 +02:00
|
|
|
|
HackShift(1, ui->labelShiftB, ui->doubleSpinBoxShiftB);
|
|
|
|
|
HackShift(2, ui->labelShiftC, ui->doubleSpinBoxShiftC);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 13:34:50 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-02-07 10:00:25 +01:00
|
|
|
|
QString TMainWindow::CheckMName(const QString &name, const QSet<QString> &importedNames) const
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
{
|
2022-03-28 16:40:44 +02:00
|
|
|
|
throw VException(tr("Measurement name is empty."));
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-07 10:00:25 +01:00
|
|
|
|
if (importedNames.contains(name))
|
|
|
|
|
{
|
|
|
|
|
throw VException(tr("Imported file must not contain the same name twice."));
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 13:34:50 +01:00
|
|
|
|
if (name.indexOf(CustomMSign) == 0)
|
|
|
|
|
{
|
|
|
|
|
QRegularExpression rx(NameRegExp());
|
|
|
|
|
if (not rx.match(name).hasMatch())
|
|
|
|
|
{
|
2022-03-28 16:40:44 +02:00
|
|
|
|
throw VException(tr("Measurement '%1' doesn't match regex pattern.").arg(name));
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (not data->IsUnique(name))
|
|
|
|
|
{
|
2022-03-28 16:40:44 +02:00
|
|
|
|
throw VException(tr("Measurement '%1' already used in the file.").arg(name));
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-01-16 18:09:23 +01:00
|
|
|
|
if (not ConvertToSet<QString>(AllGroupNames()).contains(name))
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2022-03-28 16:40:44 +02:00
|
|
|
|
throw VException(tr("Measurement '%1' is not one of the known measurements.").arg(name));
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (not data->IsUnique(name))
|
|
|
|
|
{
|
2022-03-28 16:40:44 +02:00
|
|
|
|
throw VException(tr("Measurement '%1' already used in file.").arg(name));
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowError(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox messageBox(this);
|
|
|
|
|
messageBox.setIcon(QMessageBox::Critical);
|
|
|
|
|
messageBox.setText(text);
|
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
messageBox.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::RefreshDataAfterImport()
|
|
|
|
|
{
|
|
|
|
|
const int currentRow = ui->tableWidget->currentRow();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->AddRow(currentRow);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
RefreshData();
|
2021-11-22 14:24:48 +01:00
|
|
|
|
m_search->RefreshList(ui->lineEditFind->text());
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->selectRow(currentRow);
|
|
|
|
|
ui->actionExportToCSV->setEnabled(true);
|
2018-08-01 18:25:36 +02:00
|
|
|
|
MeasurementsWereSaved(false);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-10 18:31:23 +02:00
|
|
|
|
void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv, const QVector<int> &map)
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
|
|
|
|
const int columns = csv.columnCount();
|
|
|
|
|
const int rows = csv.rowCount();
|
|
|
|
|
|
|
|
|
|
if (columns < 2)
|
|
|
|
|
{
|
|
|
|
|
ShowError(tr("Individual measurements require at least 2 columns."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct IndividualMeasurement
|
|
|
|
|
{
|
|
|
|
|
IndividualMeasurement()
|
|
|
|
|
: name(),
|
2018-04-12 12:13:19 +02:00
|
|
|
|
value('0'),
|
2018-01-31 13:34:50 +01:00
|
|
|
|
fullName(),
|
|
|
|
|
description()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
QString name;
|
|
|
|
|
QString value;
|
|
|
|
|
QString fullName;
|
|
|
|
|
QString description;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVector<IndividualMeasurement> measurements;
|
2018-02-07 10:00:25 +01:00
|
|
|
|
QSet<QString> importedNames;
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
|
|
|
|
for(int i=0; i < rows; ++i)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const int nameColumn = map.at(static_cast<int>(IndividualMeasurementsColumns::Name));
|
|
|
|
|
const QString name = csv.text(i, nameColumn).simplified();
|
2018-02-06 14:46:20 +01:00
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
{
|
2022-03-28 16:40:44 +02:00
|
|
|
|
ShowError(tr("Error in row %1. The measurement name is empty.").arg(i));
|
2018-02-06 14:46:20 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 13:34:50 +01:00
|
|
|
|
IndividualMeasurement measurement;
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const QString mName = CheckMName(VAbstractApplication::VApp()->TrVars()->MFromUser(name), importedNames);
|
2018-02-07 10:00:25 +01:00
|
|
|
|
importedNames.insert(mName);
|
|
|
|
|
measurement.name = mName;
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const int valueColumn = map.at(static_cast<int>(IndividualMeasurementsColumns::Value));
|
2021-02-06 14:52:21 +01:00
|
|
|
|
measurement.value =
|
|
|
|
|
VTranslateVars::TryFormulaFromUser(csv.text(i, valueColumn),
|
|
|
|
|
VAbstractApplication::VApp()->Settings()->GetOsSeparator());
|
2020-10-10 18:31:23 +02:00
|
|
|
|
|
|
|
|
|
const bool custom = name.startsWith(CustomMSign);
|
2018-02-06 14:46:20 +01:00
|
|
|
|
if (columns > 2 && custom)
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const int fullNameColumn = map.at(static_cast<int>(IndividualMeasurementsColumns::FullName));
|
|
|
|
|
if (fullNameColumn >= 0)
|
|
|
|
|
{
|
|
|
|
|
measurement.fullName = csv.text(i, fullNameColumn).simplified();
|
|
|
|
|
}
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 14:46:20 +01:00
|
|
|
|
if (columns > 3 && custom)
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const int descriptionColumn = map.at(static_cast<int>(IndividualMeasurementsColumns::Description));
|
|
|
|
|
if (descriptionColumn >= 0)
|
|
|
|
|
{
|
|
|
|
|
measurement.description = csv.text(i, descriptionColumn).simplified();
|
|
|
|
|
}
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
measurements.append(measurement);
|
|
|
|
|
}
|
|
|
|
|
catch (VException &e)
|
|
|
|
|
{
|
|
|
|
|
ShowError(tr("Error in row %1.").arg(i) + QLatin1Char(' ') + e.ErrorMessage());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-06 12:29:57 +01:00
|
|
|
|
for(auto &im : qAsConst(measurements))
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
|
m->AddEmpty(im.name, im.value);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2018-04-02 19:38:56 +02:00
|
|
|
|
if (not im.fullName.isEmpty())
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
|
m->SetMFullName(im.name, im.fullName);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-02 19:38:56 +02:00
|
|
|
|
if (not im.description.isEmpty())
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
|
m->SetMDescription(im.name, im.description);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshDataAfterImport();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-10 18:31:23 +02:00
|
|
|
|
void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv, const QVector<int> &map)
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
|
|
|
|
const int columns = csv.columnCount();
|
|
|
|
|
const int rows = csv.rowCount();
|
|
|
|
|
|
|
|
|
|
if (columns < 4)
|
|
|
|
|
{
|
|
|
|
|
ShowError(tr("Multisize measurements require at least 4 columns."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-02 15:43:02 +02:00
|
|
|
|
auto ConverToDouble = [](QString text, const QString &error)
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2020-10-10 18:31:23 +02:00
|
|
|
|
text.replace(" ", QString());
|
2021-02-06 14:52:21 +01:00
|
|
|
|
text = VTranslateVars::TryFormulaFromUser(text, VAbstractApplication::VApp()->Settings()->GetOsSeparator());
|
2018-01-31 13:34:50 +01:00
|
|
|
|
bool ok = false;
|
2020-10-10 18:31:23 +02:00
|
|
|
|
|
2018-01-31 13:34:50 +01:00
|
|
|
|
const qreal value = QLocale::c().toDouble(text, &ok);
|
|
|
|
|
if (not ok)
|
|
|
|
|
{
|
|
|
|
|
throw VException(error);
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct MultisizeMeasurement
|
|
|
|
|
{
|
|
|
|
|
MultisizeMeasurement()
|
|
|
|
|
: name(),
|
|
|
|
|
fullName(),
|
|
|
|
|
description()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
QString name;
|
2019-01-06 12:29:57 +01:00
|
|
|
|
qreal base{0};
|
2020-10-10 18:31:23 +02:00
|
|
|
|
qreal shiftA{0};
|
|
|
|
|
qreal shiftB{0};
|
|
|
|
|
qreal shiftC{0};
|
2018-01-31 13:34:50 +01:00
|
|
|
|
QString fullName;
|
|
|
|
|
QString description;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVector<MultisizeMeasurement> measurements;
|
2018-02-07 10:00:25 +01:00
|
|
|
|
QSet<QString> importedNames;
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const QMap<MeasurementDimension, MeasurementDimension_p > dimensions = m->Dimensions();
|
|
|
|
|
|
2018-01-31 13:34:50 +01:00
|
|
|
|
for(int i=0; i < rows; ++i)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const int nameColumn = map.at(static_cast<int>(MultisizeMeasurementsColumns::Name));
|
|
|
|
|
const QString name = csv.text(i, nameColumn).simplified();
|
2018-02-06 14:46:20 +01:00
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
{
|
2022-03-28 16:40:44 +02:00
|
|
|
|
ShowError(tr("Error in row %1. The measurement name is empty.").arg(i));
|
2018-02-06 14:46:20 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-31 13:34:50 +01:00
|
|
|
|
MultisizeMeasurement measurement;
|
2021-02-06 14:52:21 +01:00
|
|
|
|
const QString mName = CheckMName(VAbstractApplication::VApp()->TrVars()->MFromUser(name), importedNames);
|
2018-02-07 10:00:25 +01:00
|
|
|
|
importedNames.insert(mName);
|
|
|
|
|
measurement.name = mName;
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const int baseValueColumn = map.at(static_cast<int>(MultisizeMeasurementsColumns::BaseValue));
|
|
|
|
|
measurement.base = ConverToDouble(csv.text(i, baseValueColumn),
|
|
|
|
|
tr("Cannot convert base value to double in column 2."));
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const int shiftAColumn = map.at(static_cast<int>(MultisizeMeasurementsColumns::ShiftA));
|
|
|
|
|
measurement.shiftA = ConverToDouble(csv.text(i, shiftAColumn),
|
|
|
|
|
tr("Cannot convert shift value to double in column %1.")
|
|
|
|
|
.arg(shiftAColumn));
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2020-10-10 18:31:23 +02:00
|
|
|
|
if (dimensions.size() > 1)
|
|
|
|
|
{
|
|
|
|
|
const int shiftBColumn = map.at(static_cast<int>(MultisizeMeasurementsColumns::ShiftB));
|
|
|
|
|
measurement.shiftB = ConverToDouble(csv.text(i, shiftBColumn),
|
|
|
|
|
tr("Cannot convert shift value to double in column %1.")
|
|
|
|
|
.arg(shiftBColumn));
|
|
|
|
|
}
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2020-10-10 18:31:23 +02:00
|
|
|
|
if (dimensions.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
const int shiftCColumn = map.at(static_cast<int>(MultisizeMeasurementsColumns::ShiftC));
|
|
|
|
|
measurement.shiftC = ConverToDouble(csv.text(i, shiftCColumn),
|
|
|
|
|
tr("Cannot convert shift value to double in column %1.")
|
|
|
|
|
.arg(shiftCColumn));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool custom = name.startsWith(CustomMSign);
|
2018-02-06 14:46:20 +01:00
|
|
|
|
if (columns > 4 && custom)
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const int fullNameColumn = map.at(static_cast<int>(MultisizeMeasurementsColumns::FullName));
|
|
|
|
|
if (fullNameColumn >= 0)
|
|
|
|
|
{
|
|
|
|
|
measurement.fullName = csv.text(i, fullNameColumn).simplified();
|
|
|
|
|
}
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-06 14:46:20 +01:00
|
|
|
|
if (columns > 5 && custom)
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2020-10-10 18:31:23 +02:00
|
|
|
|
const int descriptionColumn = map.at(static_cast<int>(MultisizeMeasurementsColumns::Description));
|
|
|
|
|
if (descriptionColumn >= 0)
|
|
|
|
|
{
|
|
|
|
|
measurement.description = csv.text(i, descriptionColumn).simplified();
|
|
|
|
|
}
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
measurements.append(measurement);
|
|
|
|
|
}
|
|
|
|
|
catch (VException &e)
|
|
|
|
|
{
|
|
|
|
|
ShowError(tr("Error in row %1.").arg(i) + QLatin1Char(' ') + e.ErrorMessage());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-06 12:29:57 +01:00
|
|
|
|
for(auto &mm : qAsConst(measurements))
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
|
m->AddEmpty(mm.name);
|
|
|
|
|
m->SetMBaseValue(mm.name, mm.base);
|
2020-10-10 18:31:23 +02:00
|
|
|
|
m->SetMShiftA(mm.name, mm.shiftA);
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > 1)
|
|
|
|
|
{
|
|
|
|
|
m->SetMShiftB(mm.name, mm.shiftB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
m->SetMShiftC(mm.name, mm.shiftC);
|
|
|
|
|
}
|
2018-01-31 13:34:50 +01:00
|
|
|
|
|
2018-04-02 19:38:56 +02:00
|
|
|
|
if (not mm.fullName.isEmpty())
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
|
m->SetMFullName(mm.name, mm.fullName);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-02 19:38:56 +02:00
|
|
|
|
if (not mm.description.isEmpty())
|
2018-01-31 13:34:50 +01:00
|
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
|
m->SetMDescription(mm.name, mm.description);
|
2018-01-31 13:34:50 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshDataAfterImport();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-14 10:53:08 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetCurrentPatternUnit()
|
|
|
|
|
{
|
|
|
|
|
if (comboBoxUnits)
|
|
|
|
|
{
|
|
|
|
|
comboBoxUnits->blockSignals(true);
|
|
|
|
|
const qint32 indexUnit = comboBoxUnits->findData(static_cast<int>(pUnit));
|
|
|
|
|
if (indexUnit != -1)
|
|
|
|
|
{
|
|
|
|
|
comboBoxUnits->setCurrentIndex(indexUnit);
|
|
|
|
|
}
|
|
|
|
|
comboBoxUnits->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 06:34:25 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowDimensionControls()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
|
|
|
|
auto ShowControl = [this, dimensions](int index, QLabel *name, QComboBox *control)
|
|
|
|
|
{
|
|
|
|
|
if (dimensions.size() > index)
|
|
|
|
|
{
|
|
|
|
|
SCASSERT(name != nullptr)
|
|
|
|
|
SCASSERT(control != nullptr)
|
|
|
|
|
|
|
|
|
|
ui->toolBarGradation->addWidget(name);
|
|
|
|
|
ui->toolBarGradation->addWidget(control);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ShowControl(0, labelGradationDimensionA, gradationDimensionA);
|
|
|
|
|
ShowControl(1, labelGradationDimensionB, gradationDimensionB);
|
|
|
|
|
ShowControl(2, labelGradationDimensionC, gradationDimensionC);
|
|
|
|
|
|
|
|
|
|
if (gradationDimensionA)
|
|
|
|
|
{
|
|
|
|
|
connect(gradationDimensionA, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &TMainWindow::DimensionABaseChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gradationDimensionB)
|
|
|
|
|
{
|
|
|
|
|
connect(gradationDimensionB, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &TMainWindow::DimensionBBaseChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gradationDimensionC)
|
|
|
|
|
{
|
|
|
|
|
connect(gradationDimensionC, QOverload<int>::of(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &TMainWindow::DimensionCBaseChanged);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetDimensionBases()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
2020-10-03 17:45:21 +02:00
|
|
|
|
if (dimensions.size() > 0)
|
|
|
|
|
{
|
|
|
|
|
MeasurementDimension_p dimension = dimensions.at(0);
|
|
|
|
|
currentDimensionA = dimension->BaseValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > 1)
|
|
|
|
|
{
|
|
|
|
|
MeasurementDimension_p dimension = dimensions.at(1);
|
|
|
|
|
currentDimensionB = dimension->BaseValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() > 2)
|
|
|
|
|
{
|
|
|
|
|
MeasurementDimension_p dimension = dimensions.at(2);
|
|
|
|
|
currentDimensionC = dimension->BaseValue();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 19:43:53 +01:00
|
|
|
|
auto SetBase = [dimensions](int index, QComboBox *control, qreal &value)
|
2020-10-03 06:34:25 +02:00
|
|
|
|
{
|
|
|
|
|
if (dimensions.size() > index)
|
|
|
|
|
{
|
|
|
|
|
SCASSERT(control != nullptr)
|
|
|
|
|
|
|
|
|
|
MeasurementDimension_p dimension = dimensions.at(index);
|
|
|
|
|
|
|
|
|
|
const qint32 i = control->findData(value);
|
|
|
|
|
if (i != -1)
|
|
|
|
|
{
|
|
|
|
|
control->setCurrentIndex(i);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-01-18 19:43:53 +01:00
|
|
|
|
value = control->currentData().toDouble();
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SetBase(0, gradationDimensionA, currentDimensionA);
|
|
|
|
|
SetBase(1, gradationDimensionB, currentDimensionB);
|
|
|
|
|
SetBase(2, gradationDimensionC, currentDimensionC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetCurrentDimensionValues()
|
|
|
|
|
{
|
|
|
|
|
const QList<MeasurementDimension_p> dimensions = m->Dimensions().values();
|
|
|
|
|
|
2021-01-18 19:43:53 +01:00
|
|
|
|
auto SetDimensionValue = [dimensions](int index, qreal &value)
|
2020-10-03 06:34:25 +02:00
|
|
|
|
{
|
|
|
|
|
if (dimensions.size() > index)
|
|
|
|
|
{
|
|
|
|
|
MeasurementDimension_p dimension = dimensions.at(index);
|
|
|
|
|
value = dimension->BaseValue();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SetDimensionValue(0, currentDimensionA);
|
|
|
|
|
SetDimensionValue(1, currentDimensionB);
|
|
|
|
|
SetDimensionValue(2, currentDimensionC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-01-18 19:43:53 +01:00
|
|
|
|
QVector<qreal> TMainWindow::DimensionRestrictedValues(int index, const MeasurementDimension_p &dimension)
|
2020-10-03 06:34:25 +02:00
|
|
|
|
{
|
2021-01-19 20:13:17 +01:00
|
|
|
|
VDimensionRestriction restriction;
|
2020-10-07 16:12:53 +02:00
|
|
|
|
if (index == 0)
|
2020-10-03 06:34:25 +02:00
|
|
|
|
{
|
2021-01-19 20:13:17 +01:00
|
|
|
|
restriction = m->Restriction(0);
|
|
|
|
|
}
|
|
|
|
|
else if (index == 1)
|
|
|
|
|
{
|
|
|
|
|
restriction = m->Restriction(currentDimensionA);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
restriction = m->Restriction(currentDimensionA, currentDimensionB);
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
2021-01-18 19:43:53 +01:00
|
|
|
|
|
|
|
|
|
const QVector<qreal> bases = dimension->ValidBases();
|
2020-10-07 17:09:27 +02:00
|
|
|
|
|
2021-01-19 20:13:17 +01:00
|
|
|
|
qreal min = bases.indexOf(restriction.GetMin()) != -1 ? restriction.GetMin() : dimension->MinValue();
|
|
|
|
|
qreal max = bases.indexOf(restriction.GetMax()) != -1 ? restriction.GetMax() : dimension->MaxValue();
|
2020-10-07 17:09:27 +02:00
|
|
|
|
|
|
|
|
|
if (min > max)
|
|
|
|
|
{
|
|
|
|
|
min = dimension->MinValue();
|
|
|
|
|
max = dimension->MaxValue();
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-19 20:13:17 +01:00
|
|
|
|
return VAbstartMeasurementDimension::ValidBases(min, max, dimension->Step(), restriction.GetExcludeValues());
|
2020-10-03 06:34:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 10:45:16 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QMap<int, QSharedPointer<VMeasurement> > TMainWindow::OrderedMeasurments() const
|
|
|
|
|
{
|
2022-02-05 14:00:22 +01:00
|
|
|
|
const QMap<QString, QSharedPointer<VMeasurement> > table = data->DataMeasurementsWithSeparators();
|
2020-10-05 10:45:16 +02:00
|
|
|
|
QMap<int, QSharedPointer<VMeasurement> > orderedTable;
|
|
|
|
|
QMap<QString, QSharedPointer<VMeasurement> >::const_iterator iterMap;
|
|
|
|
|
for (iterMap = table.constBegin(); iterMap != table.constEnd(); ++iterMap)
|
|
|
|
|
{
|
|
|
|
|
const QSharedPointer<VMeasurement> &meash = iterMap.value();
|
|
|
|
|
orderedTable.insert(meash->Index(), meash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return orderedTable;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 08:10:56 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetDecimals()
|
|
|
|
|
{
|
|
|
|
|
switch (mUnit)
|
|
|
|
|
{
|
|
|
|
|
case Unit::Cm:
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setDecimals(2);
|
2016-06-21 12:53:33 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setSingleStep(0.1);
|
|
|
|
|
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->setDecimals(2);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->setSingleStep(0.1);
|
2016-06-21 12:53:33 +02:00
|
|
|
|
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxShiftA->setDecimals(2);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxShiftA->setSingleStep(0.1);
|
|
|
|
|
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxShiftB->setDecimals(2);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxShiftB->setSingleStep(0.1);
|
|
|
|
|
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxShiftC->setDecimals(2);
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxShiftC->setSingleStep(0.1);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
break;
|
2021-01-18 19:43:53 +01:00
|
|
|
|
case Unit::Mm:
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setDecimals(1);
|
2021-01-18 19:43:53 +01:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setSingleStep(1);
|
|
|
|
|
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->setDecimals(1);
|
2021-01-18 19:43:53 +01:00
|
|
|
|
ui->doubleSpinBoxCorrection->setSingleStep(1);
|
|
|
|
|
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxShiftA->setDecimals(1);
|
2021-01-18 19:43:53 +01:00
|
|
|
|
ui->doubleSpinBoxShiftA->setSingleStep(1);
|
|
|
|
|
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxShiftB->setDecimals(1);
|
2021-01-18 19:43:53 +01:00
|
|
|
|
ui->doubleSpinBoxShiftB->setSingleStep(1);
|
|
|
|
|
|
2021-07-24 09:49:29 +02:00
|
|
|
|
ui->doubleSpinBoxShiftC->setDecimals(1);
|
2021-01-18 19:43:53 +01:00
|
|
|
|
ui->doubleSpinBoxShiftC->setSingleStep(1);
|
|
|
|
|
break;
|
2015-07-25 08:10:56 +02:00
|
|
|
|
case Unit::Inch:
|
|
|
|
|
ui->doubleSpinBoxBaseValue->setDecimals(5);
|
2016-06-21 12:53:33 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setSingleStep(0.00001);
|
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxCorrection->setDecimals(5);
|
|
|
|
|
ui->doubleSpinBoxCorrection->setSingleStep(0.00001);
|
|
|
|
|
|
|
|
|
|
ui->doubleSpinBoxShiftA->setDecimals(5);
|
|
|
|
|
ui->doubleSpinBoxShiftA->setSingleStep(0.00001);
|
2016-06-21 12:53:33 +02:00
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->doubleSpinBoxShiftB->setDecimals(5);
|
|
|
|
|
ui->doubleSpinBoxShiftB->setSingleStep(0.00001);
|
|
|
|
|
|
|
|
|
|
ui->doubleSpinBoxShiftC->setDecimals(5);
|
|
|
|
|
ui->doubleSpinBoxShiftC->setSingleStep(0.00001);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-25 15:37:07 +02:00
|
|
|
|
|
2015-08-18 13:53:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-10-03 17:52:31 +02:00
|
|
|
|
void TMainWindow::InitPatternUnits()
|
2015-08-18 13:53:30 +02:00
|
|
|
|
{
|
2015-10-16 19:26:05 +02:00
|
|
|
|
labelPatternUnit = new QLabel(tr("Pattern unit:"));
|
|
|
|
|
ui->toolBarGradation->addWidget(labelPatternUnit);
|
2015-08-18 13:53:30 +02:00
|
|
|
|
|
|
|
|
|
comboBoxUnits = new QComboBox(this);
|
2015-10-16 19:26:05 +02:00
|
|
|
|
InitComboBoxUnits();
|
2019-03-14 10:53:08 +01:00
|
|
|
|
SetCurrentPatternUnit();
|
2015-08-18 13:53:30 +02:00
|
|
|
|
|
2019-03-14 10:53:08 +01:00
|
|
|
|
connect(comboBoxUnits, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index)
|
2015-08-18 13:53:30 +02:00
|
|
|
|
{
|
2019-03-14 10:53:08 +01:00
|
|
|
|
pUnit = static_cast<Unit>(comboBoxUnits->itemData(index).toInt());
|
2015-08-18 13:53:30 +02:00
|
|
|
|
|
2019-03-14 10:53:08 +01:00
|
|
|
|
UpdatePatternUnit();
|
|
|
|
|
});
|
2015-08-18 13:53:30 +02:00
|
|
|
|
|
|
|
|
|
ui->toolBarGradation->addWidget(comboBoxUnits);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitComboBoxUnits()
|
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
|
SCASSERT(comboBoxUnits != nullptr)
|
2017-07-02 13:34:36 +02:00
|
|
|
|
comboBoxUnits->addItem(UnitsToStr(Unit::Cm, true), QVariant(static_cast<int>(Unit::Cm)));
|
|
|
|
|
comboBoxUnits->addItem(UnitsToStr(Unit::Mm, true), QVariant(static_cast<int>(Unit::Mm)));
|
|
|
|
|
comboBoxUnits->addItem(UnitsToStr(Unit::Inch, true), QVariant(static_cast<int>(Unit::Inch)));
|
2015-10-16 19:26:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitMeasurementUnits()
|
|
|
|
|
{
|
2020-11-22 08:32:33 +01:00
|
|
|
|
if (not m)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-03 17:52:31 +02:00
|
|
|
|
ui->comboBoxMUnits->blockSignals(true);
|
|
|
|
|
|
|
|
|
|
int current = -1;
|
|
|
|
|
if (ui->comboBoxMUnits->currentIndex() != -1)
|
|
|
|
|
{
|
|
|
|
|
current = ui->comboBoxMUnits->currentData().toInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString units;
|
2021-05-07 10:19:06 +02:00
|
|
|
|
switch (m->Units())
|
2020-10-03 17:52:31 +02:00
|
|
|
|
{
|
|
|
|
|
case Unit::Mm:
|
|
|
|
|
units = tr("Millimeters");
|
|
|
|
|
break;
|
|
|
|
|
case Unit::Inch:
|
|
|
|
|
units = tr("Inches");
|
|
|
|
|
break;
|
|
|
|
|
case Unit::Cm:
|
|
|
|
|
units = tr("Centimeters");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
units = "<Invalid>";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->comboBoxMUnits->clear();
|
|
|
|
|
ui->comboBoxMUnits->addItem(units, QVariant(static_cast<int>(MUnits::Table)));
|
|
|
|
|
ui->comboBoxMUnits->addItem(tr("Degrees"), QVariant(static_cast<int>(MUnits::Degrees)));
|
|
|
|
|
|
|
|
|
|
int i = ui->comboBoxMUnits->findData(current);
|
|
|
|
|
if (i != -1)
|
|
|
|
|
{
|
|
|
|
|
ui->comboBoxMUnits->setCurrentIndex(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->comboBoxMUnits->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitGender(QComboBox *gender)
|
|
|
|
|
{
|
2016-12-20 19:57:20 +01:00
|
|
|
|
SCASSERT(gender != nullptr)
|
2015-10-16 19:26:05 +02:00
|
|
|
|
gender->addItem(tr("unknown", "gender"), QVariant(static_cast<int>(GenderType::Unknown)));
|
|
|
|
|
gender->addItem(tr("male", "gender"), QVariant(static_cast<int>(GenderType::Male)));
|
|
|
|
|
gender->addItem(tr("female", "gender"), QVariant(static_cast<int>(GenderType::Female)));
|
|
|
|
|
}
|
2016-06-19 19:31:24 +02:00
|
|
|
|
|
2020-10-15 08:35:08 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitMeasurementDimension()
|
|
|
|
|
{
|
|
|
|
|
ui->comboBoxDimension->blockSignals(true);
|
|
|
|
|
|
|
|
|
|
int current = -1;
|
|
|
|
|
if (ui->comboBoxDimension->currentIndex() != -1)
|
|
|
|
|
{
|
|
|
|
|
current = ui->comboBoxDimension->currentData().toInt();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->comboBoxDimension->clear();
|
|
|
|
|
|
|
|
|
|
ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::N), QVariant(static_cast<int>(IMD::N)));
|
|
|
|
|
ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::X), QVariant(static_cast<int>(IMD::X)));
|
|
|
|
|
ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::Y), QVariant(static_cast<int>(IMD::Y)));
|
|
|
|
|
ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::W), QVariant(static_cast<int>(IMD::W)));
|
|
|
|
|
ui->comboBoxDimension->addItem(VMeasurements::IMDName(IMD::Z), QVariant(static_cast<int>(IMD::Z)));
|
|
|
|
|
|
|
|
|
|
int i = ui->comboBoxDimension->findData(current);
|
|
|
|
|
if (i != -1)
|
|
|
|
|
{
|
|
|
|
|
ui->comboBoxDimension->setCurrentIndex(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->comboBoxDimension->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-22 14:24:48 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitSearch()
|
|
|
|
|
{
|
|
|
|
|
VTapeSettings *settings = MApplication::VApp()->TapeSettings();
|
|
|
|
|
m_search->SetUseUnicodePreperties(settings->GetTapeSearchOptionUseUnicodeProperties());
|
|
|
|
|
m_search->SetMatchWord(settings->GetTapeSearchOptionWholeWord());
|
|
|
|
|
m_search->SetMatchRegexp(settings->GetTapeSearchOptionRegexp());
|
|
|
|
|
m_search->SetMatchCase(settings->GetTapeSearchOptionMatchCase());
|
|
|
|
|
|
|
|
|
|
ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder());
|
|
|
|
|
|
|
|
|
|
UpdateSearchControlsTooltips();
|
|
|
|
|
|
|
|
|
|
connect(ui->lineEditFind, &QLineEdit::textChanged, this, [this] (const QString &term){m_search->Find(term);});
|
|
|
|
|
connect(ui->lineEditFind, &QLineEdit::editingFinished, this, [this]()
|
|
|
|
|
{
|
|
|
|
|
SaveSearchRequest();
|
|
|
|
|
InitSearchHistory();
|
|
|
|
|
m_search->Find(ui->lineEditFind->text());
|
|
|
|
|
});
|
|
|
|
|
connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this]()
|
|
|
|
|
{
|
|
|
|
|
SaveSearchRequest();
|
|
|
|
|
InitSearchHistory();
|
|
|
|
|
m_search->FindPrevious();
|
|
|
|
|
ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount()));
|
|
|
|
|
});
|
|
|
|
|
connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this]()
|
|
|
|
|
{
|
|
|
|
|
SaveSearchRequest();
|
|
|
|
|
InitSearchHistory();
|
|
|
|
|
m_search->FindNext();
|
|
|
|
|
ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount()));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state)
|
|
|
|
|
{
|
|
|
|
|
ui->toolButtonFindPrevious->setEnabled(state);
|
|
|
|
|
ui->toolButtonFindNext->setEnabled(state);
|
|
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
|
{
|
|
|
|
|
ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount()));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->labelResults->setText(tr("0 results"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPalette palette;
|
|
|
|
|
|
|
|
|
|
if (not state && not ui->lineEditFind->text().isEmpty())
|
|
|
|
|
{
|
|
|
|
|
palette.setColor(QPalette::Text, Qt::red);
|
|
|
|
|
ui->lineEditFind->setPalette(palette);
|
|
|
|
|
|
|
|
|
|
palette.setColor(QPalette::Active, ui->labelResults->foregroundRole(), Qt::red);
|
|
|
|
|
palette.setColor(QPalette::Inactive, ui->labelResults->foregroundRole(), Qt::red);
|
|
|
|
|
ui->labelResults->setPalette(palette);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->lineEditFind->setPalette(palette);
|
|
|
|
|
ui->labelResults->setPalette(palette);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(ui->toolButtonCaseSensitive, &QToolButton::toggled, this, [this](bool checked)
|
|
|
|
|
{
|
|
|
|
|
m_search->SetMatchCase(checked);
|
|
|
|
|
m_search->Find(ui->lineEditFind->text());
|
|
|
|
|
ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(ui->toolButtonWholeWord, &QToolButton::toggled, this, [this](bool checked)
|
|
|
|
|
{
|
|
|
|
|
m_search->SetMatchWord(checked);
|
|
|
|
|
m_search->Find(ui->lineEditFind->text());
|
|
|
|
|
ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(ui->toolButtonRegexp, &QToolButton::toggled, this, [this](bool checked)
|
|
|
|
|
{
|
|
|
|
|
m_search->SetMatchRegexp(checked);
|
|
|
|
|
|
|
|
|
|
if (checked)
|
|
|
|
|
{
|
|
|
|
|
ui->toolButtonWholeWord->blockSignals(true);
|
|
|
|
|
ui->toolButtonWholeWord->setChecked(false);
|
|
|
|
|
ui->toolButtonWholeWord->blockSignals(false);
|
|
|
|
|
ui->toolButtonWholeWord->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
ui->toolButtonUseUnicodeProperties->setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->toolButtonWholeWord->setEnabled(true);
|
|
|
|
|
ui->toolButtonUseUnicodeProperties->blockSignals(true);
|
|
|
|
|
ui->toolButtonUseUnicodeProperties->setChecked(false);
|
|
|
|
|
ui->toolButtonUseUnicodeProperties->blockSignals(false);
|
|
|
|
|
ui->toolButtonUseUnicodeProperties->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
m_search->Find(ui->lineEditFind->text());
|
|
|
|
|
ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(ui->toolButtonUseUnicodeProperties, &QToolButton::toggled, this, [this](bool checked)
|
|
|
|
|
{
|
|
|
|
|
m_search->SetUseUnicodePreperties(checked);
|
|
|
|
|
m_search->Find(ui->lineEditFind->text());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
m_searchHistory->setStyleSheet(QStringLiteral("QMenu { menu-scrollable: 1; }"));
|
|
|
|
|
InitSearchHistory();
|
|
|
|
|
ui->pushButtonSearch->setMenu(m_searchHistory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitSearchHistory()
|
|
|
|
|
{
|
|
|
|
|
QStringList searchHistory = MApplication::VApp()->TapeSettings()->GetTapeSearchHistory();
|
|
|
|
|
m_searchHistory->clear();
|
|
|
|
|
for (const auto& term : searchHistory)
|
|
|
|
|
{
|
|
|
|
|
QAction *action = m_searchHistory->addAction(term);
|
|
|
|
|
action->setData(term);
|
|
|
|
|
connect(action, &QAction::triggered, this, [this]()
|
|
|
|
|
{
|
|
|
|
|
auto *action = qobject_cast<QAction *>(sender());
|
|
|
|
|
if (action != nullptr)
|
|
|
|
|
{
|
|
|
|
|
QString term = action->data().toString();
|
|
|
|
|
ui->lineEditFind->setText(term);
|
|
|
|
|
m_search->Find(term);
|
|
|
|
|
ui->lineEditFind->setFocus();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveSearchRequest()
|
|
|
|
|
{
|
|
|
|
|
QStringList searchHistory = MApplication::VApp()->TapeSettings()->GetTapeSearchHistory();
|
|
|
|
|
QString term = ui->lineEditFind->text();
|
|
|
|
|
if (term.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchHistory.removeAll(term);
|
|
|
|
|
searchHistory.prepend(term);
|
|
|
|
|
while (searchHistory.size() > VTableSearch::MaxHistoryRecords)
|
|
|
|
|
{
|
|
|
|
|
searchHistory.removeLast();
|
|
|
|
|
}
|
|
|
|
|
MApplication::VApp()->TapeSettings()->SetTapeSearchHistory(searchHistory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::UpdateSearchControlsTooltips()
|
|
|
|
|
{
|
|
|
|
|
auto UpdateToolTip = [](QAbstractButton *button)
|
|
|
|
|
{
|
2022-05-28 14:14:50 +02:00
|
|
|
|
if (button->toolTip().contains(QLatin1String("%1")))
|
|
|
|
|
{
|
|
|
|
|
button->setToolTip(button->toolTip().arg(button->shortcut().toString(QKeySequence::NativeText)));
|
|
|
|
|
}
|
2021-11-22 14:24:48 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UpdateToolTip(ui->toolButtonCaseSensitive);
|
|
|
|
|
UpdateToolTip(ui->toolButtonWholeWord);
|
|
|
|
|
UpdateToolTip(ui->toolButtonRegexp);
|
|
|
|
|
UpdateToolTip(ui->toolButtonUseUnicodeProperties);
|
|
|
|
|
UpdateToolTip(ui->pushButtonSearch);
|
|
|
|
|
UpdateToolTip(ui->toolButtonFindPrevious);
|
|
|
|
|
UpdateToolTip(ui->toolButtonFindNext);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 15:27:17 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::RetranslateTableHeaders()
|
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Multisize)
|
|
|
|
|
{
|
|
|
|
|
const QList< MeasurementDimension_p > dimensions = m->Dimensions().values();
|
|
|
|
|
|
|
|
|
|
if (not dimensions.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
const MeasurementDimension_p& dimension = dimensions.at(0);
|
|
|
|
|
ui->tableWidget->horizontalHeaderItem(ColumnShiftA)->setText(
|
2022-02-14 12:26:24 +01:00
|
|
|
|
tr("%1 shift").arg(dimension->Name()));
|
2021-03-26 15:27:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() < 2)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnShiftB, true );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const MeasurementDimension_p &dimension = dimensions.at(1);
|
|
|
|
|
ui->tableWidget->horizontalHeaderItem(ColumnShiftB)->setText(
|
2022-02-14 12:26:24 +01:00
|
|
|
|
tr("%1 shift").arg(dimension->Name()));
|
2021-03-26 15:27:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dimensions.size() < 3)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnShiftC, true );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const MeasurementDimension_p &dimension = dimensions.at(2);
|
|
|
|
|
ui->tableWidget->horizontalHeaderItem(ColumnShiftC)->setText(
|
2022-02-14 12:26:24 +01:00
|
|
|
|
tr("%1 shift").arg(dimension->Name()));
|
2021-03-26 15:27:17 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-19 19:31:24 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
template <class T>
|
|
|
|
|
void TMainWindow::HackWidget(T **widget)
|
|
|
|
|
{
|
|
|
|
|
delete *widget;
|
|
|
|
|
*widget = new T();
|
|
|
|
|
hackedWidgets.append(*widget);
|
|
|
|
|
}
|