Refactoring. Fixing static analyzers warnings.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-01-06 13:29:57 +02:00
parent 753e9c76f5
commit ba08ed4d1d
4 changed files with 199 additions and 225 deletions

View File

@ -100,7 +100,7 @@ TMainWindow::TMainWindow(QWidget *parent)
dockDiagramVisible(true), dockDiagramVisible(true),
isInitialized(false), isInitialized(false),
mIsReadOnly(false), mIsReadOnly(false),
recentFileActs(), recentFileActs(QVector<QAction *>(MaxRecentFiles)),
separatorAct(nullptr), separatorAct(nullptr),
hackedWidgets() hackedWidgets()
{ {
@ -123,11 +123,7 @@ TMainWindow::TMainWindow(QWidget *parent)
ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu); ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu); ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu);
//MSVC doesn't support int arrays in initializer list recentFileActs.fill(nullptr);
for (int i = 0; i < MaxRecentFiles; ++i)
{
recentFileActs[i] = nullptr;
}
SetupMenu(); SetupMenu();
UpdateWindowTitle(); UpdateWindowTitle();
@ -259,8 +255,7 @@ bool TMainWindow::LoadFile(const QString &path)
if (mType == MeasurementsType::Unknown) if (mType == MeasurementsType::Unknown)
{ {
VException e(tr("File has unknown format.")); throw VException(tr("File has unknown format."));
throw e;
} }
if (mType == MeasurementsType::Multisize) if (mType == MeasurementsType::Multisize)
@ -280,8 +275,7 @@ bool TMainWindow::LoadFile(const QString &path)
if (not m->IsDefinedKnownNamesValid()) if (not m->IsDefinedKnownNamesValid())
{ {
VException e(tr("File contains invalid known measurement(s).")); throw VException(tr("File contains invalid known measurement(s)."));
throw e;
} }
mUnit = m->MUnit(); mUnit = m->MUnit();
@ -399,8 +393,8 @@ void TMainWindow::FileNew()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::OpenIndividual() void TMainWindow::OpenIndividual()
{ {
const QString filter = tr("Individual measurements") + QLatin1String(" (*.vit);;") + tr("Multisize measurements") + const QString filter = tr("Individual measurements") + QStringLiteral(" (*.vit);;") + tr("Multisize measurements") +
QLatin1String(" (*.vst);;") + tr("All files") + QLatin1String(" (*.*)"); QStringLiteral(" (*.vst);;") + tr("All files") + QStringLiteral(" (*.*)");
//Use standard path to individual measurements //Use standard path to individual measurements
const QString pathTo = qApp->TapeSettings()->GetPathIndividualMeasurements(); const QString pathTo = qApp->TapeSettings()->GetPathIndividualMeasurements();
@ -415,16 +409,15 @@ void TMainWindow::OpenIndividual()
if (usedNotExistedDir) if (usedNotExistedDir)
{ {
QDir directory(pathTo); QDir(pathTo).rmpath(QChar('.'));
directory.rmpath(QChar('.'));
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::OpenMultisize() void TMainWindow::OpenMultisize()
{ {
const QString filter = tr("Multisize measurements") + QLatin1String(" (*.vst);;") + tr("Individual measurements") + const QString filter = tr("Multisize measurements") + QStringLiteral(" (*.vst);;") + tr("Individual measurements") +
QLatin1String(" (*.vit);;") + tr("All files") + QLatin1String(" (*.*)"); QStringLiteral(" (*.vit);;") + tr("All files") + QStringLiteral(" (*.*)");
//Use standard path to multisize measurements //Use standard path to multisize measurements
QString pathTo = qApp->TapeSettings()->GetPathMultisizeMeasurements(); QString pathTo = qApp->TapeSettings()->GetPathMultisizeMeasurements();
pathTo = VCommonSettings::PrepareMultisizeTables(pathTo); pathTo = VCommonSettings::PrepareMultisizeTables(pathTo);
@ -435,8 +428,8 @@ void TMainWindow::OpenMultisize()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::OpenTemplate() void TMainWindow::OpenTemplate()
{ {
const QString filter = tr("Measurements") + QLatin1String(" (*.vst *.vit);;") + tr("All files") + const QString filter = tr("Measurements") + QStringLiteral(" (*.vst *.vit);;") + tr("All files") +
QLatin1String(" (*.*)"); QStringLiteral(" (*.*)");
//Use standard path to template files //Use standard path to template files
QString pathTo = qApp->TapeSettings()->GetPathTemplate(); QString pathTo = qApp->TapeSettings()->GetPathTemplate();
pathTo = VCommonSettings::PrepareStandardTemplates(pathTo); pathTo = VCommonSettings::PrepareStandardTemplates(pathTo);
@ -452,7 +445,7 @@ void TMainWindow::OpenTemplate()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::CreateFromExisting() void TMainWindow::CreateFromExisting()
{ {
const QString filter = tr("Individual measurements") + QLatin1String(" (*.vit)"); const QString filter = tr("Individual measurements") + QStringLiteral(" (*.vit)");
//Use standard path to individual measurements //Use standard path to individual measurements
const QString pathTo = qApp->TapeSettings()->GetPathIndividualMeasurements(); const QString pathTo = qApp->TapeSettings()->GetPathIndividualMeasurements();
@ -479,8 +472,7 @@ void TMainWindow::CreateFromExisting()
if (usedNotExistedDir) if (usedNotExistedDir)
{ {
QDir directory(pathTo); QDir(pathTo).rmpath(QChar('.'));
directory.rmpath(QChar('.'));
} }
} }
@ -492,7 +484,7 @@ void TMainWindow::Preferences()
if (guard.isNull()) if (guard.isNull())
{ {
QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); QGuiApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
DialogTapePreferences *preferences = new DialogTapePreferences(this); auto *preferences = new DialogTapePreferences(this);
// QScopedPointer needs to be sure any exception will never block guard // QScopedPointer needs to be sure any exception will never block guard
QScopedPointer<DialogTapePreferences> dlg(preferences); QScopedPointer<DialogTapePreferences> dlg(preferences);
guard = preferences; guard = preferences;
@ -620,12 +612,12 @@ void TMainWindow::showEvent(QShowEvent *event)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool TMainWindow::eventFilter(QObject *object, QEvent *event) bool TMainWindow::eventFilter(QObject *object, QEvent *event)
{ {
if (QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(object)) if (auto *plainTextEdit = qobject_cast<QPlainTextEdit *>(object))
{ {
if (event->type() == QEvent::KeyPress) if (event->type() == QEvent::KeyPress)
{ {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); auto *keyEvent = static_cast<QKeyEvent *>(event);
if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier)) if ((keyEvent->key() == Qt::Key_Period) && ((keyEvent->modifiers() & Qt::KeypadModifier) != 0u))
{ {
if (qApp->Settings()->GetOsSeparator()) if (qApp->Settings()->GetOsSeparator())
{ {
@ -639,12 +631,12 @@ bool TMainWindow::eventFilter(QObject *object, QEvent *event)
} }
} }
} }
else if (QLineEdit *textEdit = qobject_cast<QLineEdit *>(object)) else if (auto *textEdit = qobject_cast<QLineEdit *>(object))
{ {
if (event->type() == QEvent::KeyPress) if (event->type() == QEvent::KeyPress)
{ {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); auto *keyEvent = static_cast<QKeyEvent *>(event);
if ((keyEvent->key() == Qt::Key_Period) && (keyEvent->modifiers() & Qt::KeypadModifier)) if ((keyEvent->key() == Qt::Key_Period) && ((keyEvent->modifiers() & Qt::KeypadModifier) != 0u))
{ {
if (qApp->Settings()->GetOsSeparator()) if (qApp->Settings()->GetOsSeparator())
{ {
@ -658,12 +650,9 @@ bool TMainWindow::eventFilter(QObject *object, QEvent *event)
} }
} }
} }
else
{ // pass the event on to the parent class
// pass the event on to the parent class return QMainWindow::eventFilter(object, event);
return QMainWindow::eventFilter(object, event);
}
return false;// pass the event to the widget
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -723,93 +712,90 @@ bool TMainWindow::FileSave()
{ {
return FileSaveAs(); return FileSaveAs();
} }
else
if (mType == MeasurementsType::Multisize
&& m_curFileFormatVersion < VVSTConverter::MeasurementMaxVer
&& not ContinueFormatRewrite(m_curFileFormatVersionStr, VVSTConverter::MeasurementMaxVerStr))
{ {
if (mType == MeasurementsType::Multisize return false;
&& m_curFileFormatVersion < VVSTConverter::MeasurementMaxVer }
&& not ContinueFormatRewrite(m_curFileFormatVersionStr, VVSTConverter::MeasurementMaxVerStr))
{ if (mType == MeasurementsType::Individual
return false; && m_curFileFormatVersion < VVITConverter::MeasurementMaxVer
} && not ContinueFormatRewrite(m_curFileFormatVersionStr, VVITConverter::MeasurementMaxVerStr))
else if (mType == MeasurementsType::Individual {
&& m_curFileFormatVersion < VVITConverter::MeasurementMaxVer return false;
&& not ContinueFormatRewrite(m_curFileFormatVersionStr, VVITConverter::MeasurementMaxVerStr)) }
{
return false;
}
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
qt_ntfs_permission_lookup++; // turn checking on qt_ntfs_permission_lookup++; // turn checking on
#endif /*Q_OS_WIN32*/ #endif /*Q_OS_WIN32*/
const bool isFileWritable = QFileInfo(curFile).isWritable(); const bool isFileWritable = QFileInfo(curFile).isWritable();
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
qt_ntfs_permission_lookup--; // turn it off again qt_ntfs_permission_lookup--; // turn it off again
#endif /*Q_OS_WIN32*/ #endif /*Q_OS_WIN32*/
if (not isFileWritable) if (not isFileWritable)
{ {
QMessageBox messageBox(this); QMessageBox messageBox(this);
messageBox.setIcon(QMessageBox::Question); messageBox.setIcon(QMessageBox::Question);
messageBox.setText(tr("The measurements document has no write permissions.")); messageBox.setText(tr("The measurements document has no write permissions."));
messageBox.setInformativeText("Do you want to change the premissions?"); messageBox.setInformativeText(tr("Do you want to change the premissions?"));
messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
messageBox.setDefaultButton(QMessageBox::Yes); messageBox.setDefaultButton(QMessageBox::Yes);
if (messageBox.exec() == QMessageBox::Yes) if (messageBox.exec() == QMessageBox::Yes)
{ {
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
qt_ntfs_permission_lookup++; // turn checking on qt_ntfs_permission_lookup++; // turn checking on
#endif /*Q_OS_WIN32*/ #endif /*Q_OS_WIN32*/
bool changed = QFile::setPermissions(curFile, bool changed = QFile::setPermissions(curFile,
QFileInfo(curFile).permissions() | QFileDevice::WriteUser); QFileInfo(curFile).permissions() | QFileDevice::WriteUser);
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
qt_ntfs_permission_lookup--; // turn it off again qt_ntfs_permission_lookup--; // turn it off again
#endif /*Q_OS_WIN32*/ #endif /*Q_OS_WIN32*/
if (not changed) if (not changed)
{
QMessageBox messageBox(this);
messageBox.setIcon(QMessageBox::Warning);
messageBox.setText(tr("Cannot set permissions for %1 to writable.").arg(curFile));
messageBox.setInformativeText(tr("Could not save the file."));
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
return false;
}
}
else
{ {
messageBox.setIcon(QMessageBox::Warning);
messageBox.setText(tr("Cannot set permissions for %1 to writable.").arg(curFile));
messageBox.setInformativeText(tr("Could not save the file."));
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.exec();
return false; return false;
} }
} }
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;
}
else else
{ {
if (mType == MeasurementsType::Multisize) return false;
{
m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer;
m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr;
}
else
{
m_curFileFormatVersion = VVITConverter::MeasurementMaxVer;
m_curFileFormatVersionStr = VVITConverter::MeasurementMaxVerStr;
}
} }
} }
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;
}
return true; return true;
} }
@ -821,14 +807,14 @@ bool TMainWindow::FileSaveAs()
QString suffix; QString suffix;
if (mType == MeasurementsType::Individual) if (mType == MeasurementsType::Individual)
{ {
filters = tr("Individual measurements") + QLatin1String(" (*.vit)"); filters = tr("Individual measurements") + QStringLiteral(" (*.vit)");
suffix = QLatin1String("vit"); suffix = QStringLiteral("vit");
fName += QChar('.') + suffix; fName += QChar('.') + suffix;
} }
else else
{ {
filters = tr("Multisize measurements") + QLatin1String(" (*.vst)"); filters = tr("Multisize measurements") + QStringLiteral(" (*.vst)");
suffix = QLatin1String("vst"); suffix = QStringLiteral("vst");
fName += QChar('.') + suffix; fName += QChar('.') + suffix;
} }
@ -857,14 +843,13 @@ bool TMainWindow::FileSaveAs()
usedNotExistedDir = directory.mkpath(QChar('.')); usedNotExistedDir = directory.mkpath(QChar('.'));
} }
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QLatin1String("/") + fName, filters); QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir + QChar('/') + fName, filters);
auto RemoveTempDir = [usedNotExistedDir, dir]() auto RemoveTempDir = [usedNotExistedDir, dir]()
{ {
if (usedNotExistedDir) if (usedNotExistedDir)
{ {
QDir directory(dir); QDir(dir).rmpath(QChar('.'));
directory.rmpath(QChar('.'));
} }
}; };
@ -901,7 +886,7 @@ bool TMainWindow::FileSaveAs()
QString error; QString error;
bool result = SaveMeasurements(fileName, error); bool result = SaveMeasurements(fileName, error);
if (result == false) if (not result)
{ {
QMessageBox messageBox; QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning); messageBox.setIcon(QMessageBox::Warning);
@ -943,7 +928,7 @@ void TMainWindow::AboutToShowWindowMenu()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ShowWindow() const void TMainWindow::ShowWindow() const
{ {
if (QAction *action = qobject_cast<QAction*>(sender())) if (auto *action = qobject_cast<QAction*>(sender()))
{ {
const QVariant v = action->data(); const QVariant v = action->data();
if (v.canConvert<int>()) if (v.canConvert<int>())
@ -964,8 +949,8 @@ void TMainWindow::ImportDataFromCSV()
return; return;
} }
const QString filters = tr("Comma-Separated Values") + QLatin1String(" (*.csv)"); const QString filters = tr("Comma-Separated Values") + QStringLiteral(" (*.csv)");
const QString suffix("csv"); const QString suffix = QStringLiteral("csv");
QString fileName = QFileDialog::getOpenFileName(this, tr("Import from CSV"), QDir::homePath(), filters, nullptr QString fileName = QFileDialog::getOpenFileName(this, tr("Import from CSV"), QDir::homePath(), filters, nullptr
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
@ -1287,7 +1272,7 @@ void TMainWindow::Fx()
return; return;
} }
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this); auto *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this);
dialog->setWindowTitle(tr("Edit measurement")); dialog->setWindowTitle(tr("Edit measurement"));
dialog->SetMeasurementsMode(); dialog->SetMeasurementsMode();
dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText(), true)); dialog->SetFormula(qApp->TrVars()->TryFormulaFromUser(ui->plainTextEditFormula->toPlainText(), true));
@ -1298,7 +1283,7 @@ void TMainWindow::Fx()
{ {
// Fix the bug #492. https://bitbucket.org/dismine/valentina/issues/492/valentina-crashes-when-add-an-increment // 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. // Because of the bug need to take QTableWidgetItem twice time. Previous update "killed" the pointer.
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName); nameField = ui->tableWidget->item(row, ColumnName);
m->SetMValue(nameField->data(Qt::UserRole).toString(), dialog->GetFormula()); m->SetMValue(nameField->data(Qt::UserRole).toString(), dialog->GetFormula());
MeasurementsWereSaved(false); MeasurementsWereSaved(false);
@ -1630,14 +1615,14 @@ void TMainWindow::DeployFormula()
{ {
ui->plainTextEditFormula->setFixedHeight(DIALOG_MAX_FORMULA_HEIGHT); ui->plainTextEditFormula->setFixedHeight(DIALOG_MAX_FORMULA_HEIGHT);
//Set icon from theme (internal for Windows system) //Set icon from theme (internal for Windows system)
ui->pushButtonGrow->setIcon(QIcon::fromTheme("go-next", ui->pushButtonGrow->setIcon(QIcon::fromTheme(QStringLiteral("go-next"),
QIcon(":/icons/win.icon.theme/16x16/actions/go-next.png"))); QIcon(":/icons/win.icon.theme/16x16/actions/go-next.png")));
} }
else else
{ {
ui->plainTextEditFormula->setFixedHeight(formulaBaseHeight); ui->plainTextEditFormula->setFixedHeight(formulaBaseHeight);
//Set icon from theme (internal for Windows system) //Set icon from theme (internal for Windows system)
ui->pushButtonGrow->setIcon(QIcon::fromTheme("go-down", ui->pushButtonGrow->setIcon(QIcon::fromTheme(QStringLiteral("go-down"),
QIcon(":/icons/win.icon.theme/16x16/actions/go-down.png"))); QIcon(":/icons/win.icon.theme/16x16/actions/go-down.png")));
} }
@ -1690,7 +1675,7 @@ void TMainWindow::SaveMName(const QString &text)
QString name = newName; QString name = newName;
do do
{ {
name = name + QLatin1String("_") + QString().number(num); name = name + QChar('_') + QString::number(num);
num++; num++;
} while (not data->IsUnique(name)); } while (not data->IsUnique(name));
newName = name; newName = name;
@ -1971,7 +1956,7 @@ void TMainWindow::SetupMenu()
} }
else else
{ {
if (QAction *action = qobject_cast< QAction * >(this->sender())) if (auto *action = qobject_cast< QAction * >(this->sender()))
{ {
action->setChecked(true); action->setChecked(true);
} }
@ -1979,24 +1964,23 @@ void TMainWindow::SetupMenu()
}); });
connect(ui->actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences); connect(ui->actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences);
for (int i = 0; i < MaxRecentFiles; ++i) for (auto & recentFileAct : recentFileActs)
{ {
QAction *action = new QAction(this); auto *action = new QAction(this);
recentFileActs[i] = action; recentFileAct = action;
connect(action, &QAction::triggered, this, [this]() connect(action, &QAction::triggered, this, [this]()
{ {
QAction *action = qobject_cast<QAction *>(sender()); if (auto *senderAction = qobject_cast<QAction *>(sender()))
if (action)
{ {
const QString filePath = action->data().toString(); const QString filePath = senderAction->data().toString();
if (not filePath.isEmpty()) if (not filePath.isEmpty())
{ {
LoadFile(filePath); LoadFile(filePath);
} }
} }
}); });
ui->menuFile->insertAction(ui->actionPreferences, recentFileActs[i]); ui->menuFile->insertAction(ui->actionPreferences, recentFileAct);
recentFileActs[i]->setVisible(false); recentFileAct->setVisible(false);
} }
separatorAct = new QAction(this); separatorAct = new QAction(this);
@ -2031,7 +2015,7 @@ void TMainWindow::SetupMenu()
}); });
connect(ui->actionAboutTape, &QAction::triggered, this, [this]() connect(ui->actionAboutTape, &QAction::triggered, this, [this]()
{ {
DialogAboutTape *aboutDialog = new DialogAboutTape(this); auto *aboutDialog = new DialogAboutTape(this);
aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true); aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true);
aboutDialog->show(); aboutDialog->show();
}); });
@ -2188,7 +2172,7 @@ void TMainWindow::InitWindow()
ui->actionSaveAs->setEnabled(true); ui->actionSaveAs->setEnabled(true);
ui->lineEditName->setValidator(new QRegularExpressionValidator(QRegularExpression( ui->lineEditName->setValidator(new QRegularExpressionValidator(QRegularExpression(
QLatin1String("^$|")+NameRegExp()), QStringLiteral("^$|")+NameRegExp()),
this)); this));
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &TMainWindow::Remove); connect(ui->toolButtonRemove, &QToolButton::clicked, this, &TMainWindow::Remove);
@ -2257,7 +2241,7 @@ void TMainWindow::ShowHeaderUnits(QTableWidget *table, int column, const QString
{ {
header.remove(index-1, 100); header.remove(index-1, 100);
} }
const QString unitHeader = QString("%1 (%2)").arg(header, unit); const QString unitHeader = QStringLiteral("%1 (%2)").arg(header, unit);
table->horizontalHeaderItem(column)->setText(unitHeader); table->horizontalHeaderItem(column)->setText(unitHeader);
} }
@ -2274,7 +2258,7 @@ void TMainWindow::SetCurrentFile(const QString &fileName)
curFile = fileName; curFile = fileName;
if (curFile.isEmpty()) if (curFile.isEmpty())
{ {
ui->lineEditPathToFile->setText(QLatin1String("<") + tr("Empty") + QLatin1String(">")); ui->lineEditPathToFile->setText(QChar('<') + tr("Empty") + QChar('>'));
ui->lineEditPathToFile->setToolTip(tr("File was not saved yet.")); ui->lineEditPathToFile->setToolTip(tr("File was not saved yet."));
ui->lineEditPathToFile->setCursorPosition(0); ui->lineEditPathToFile->setCursorPosition(0);
ui->pushButtonShowInExplorer->setEnabled(false); ui->pushButtonShowInExplorer->setEnabled(false);
@ -2335,7 +2319,7 @@ bool TMainWindow::MaybeSave()
messageBox->setButtonText(QMessageBox::No, tr("Don't Save")); messageBox->setButtonText(QMessageBox::No, tr("Don't Save"));
messageBox->setWindowModality(Qt::ApplicationModal); messageBox->setWindowModality(Qt::ApplicationModal);
const QMessageBox::StandardButton ret = static_cast<QMessageBox::StandardButton>(messageBox->exec()); const auto ret = static_cast<QMessageBox::StandardButton>(messageBox->exec());
switch (ret) switch (ret)
{ {
@ -2362,7 +2346,7 @@ bool TMainWindow::MaybeSave()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QTableWidgetItem *TMainWindow::AddCell(const QString &text, int row, int column, int aligment, bool ok) QTableWidgetItem *TMainWindow::AddCell(const QString &text, int row, int column, int aligment, bool ok)
{ {
QTableWidgetItem *item = new QTableWidgetItem(text); auto *item = new QTableWidgetItem(text);
item->setTextAlignment(aligment); item->setTextAlignment(aligment);
item->setToolTip(text); item->setToolTip(text);
@ -2388,7 +2372,7 @@ QComboBox *TMainWindow::SetGradationList(QLabel *label, const QStringList &list)
{ {
ui->toolBarGradation->addWidget(label); ui->toolBarGradation->addWidget(label);
QComboBox *comboBox = new QComboBox; auto *comboBox = new QComboBox;
comboBox->addItems(list); comboBox->addItems(list);
ui->toolBarGradation->addWidget(comboBox); ui->toolBarGradation->addWidget(comboBox);
@ -2398,7 +2382,7 @@ QComboBox *TMainWindow::SetGradationList(QLabel *label, const QStringList &list)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetDefaultHeight(int value) void TMainWindow::SetDefaultHeight(int value)
{ {
const qint32 index = gradationHeights->findText(QString("%1").arg(value)); const qint32 index = gradationHeights->findText(QString::number(value));
if (index != -1) if (index != -1)
{ {
gradationHeights->setCurrentIndex(index); gradationHeights->setCurrentIndex(index);
@ -2412,7 +2396,7 @@ void TMainWindow::SetDefaultHeight(int value)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetDefaultSize(int value) void TMainWindow::SetDefaultSize(int value)
{ {
const qint32 index = gradationSizes->findText(QString("%1").arg(value)); const qint32 index = gradationSizes->findText(QString::number(value));
if (index != -1) if (index != -1)
{ {
gradationSizes->setCurrentIndex(index); gradationSizes->setCurrentIndex(index);
@ -2446,7 +2430,7 @@ void TMainWindow::RefreshTable(bool freshCall)
QMap<QString, QSharedPointer<VMeasurement> >::const_iterator iterMap; QMap<QString, QSharedPointer<VMeasurement> >::const_iterator iterMap;
for (iterMap = table.constBegin(); iterMap != table.constEnd(); ++iterMap) for (iterMap = table.constBegin(); iterMap != table.constEnd(); ++iterMap)
{ {
QSharedPointer<VMeasurement> meash = iterMap.value(); const QSharedPointer<VMeasurement> &meash = iterMap.value();
orderedTable.insert(meash->Index(), meash); orderedTable.insert(meash->Index(), meash);
} }
@ -2455,7 +2439,7 @@ void TMainWindow::RefreshTable(bool freshCall)
ui->tableWidget->setRowCount ( orderedTable.size() ); ui->tableWidget->setRowCount ( orderedTable.size() );
for (iMap = orderedTable.constBegin(); iMap != orderedTable.constEnd(); ++iMap) for (iMap = orderedTable.constBegin(); iMap != orderedTable.constEnd(); ++iMap)
{ {
QSharedPointer<VMeasurement> meash = iMap.value(); const QSharedPointer<VMeasurement> &meash = iMap.value();
currentRow++; currentRow++;
if (mType == MeasurementsType::Individual) if (mType == MeasurementsType::Individual)
@ -2530,9 +2514,9 @@ QString TMainWindow::GetCustomName() const
QString name; QString name;
do do
{ {
name = CustomMSign + qApp->TrVars()->InternalVarToUser(measurement_) + QString().number(num); name = CustomMSign + qApp->TrVars()->InternalVarToUser(measurement_) + QString::number(num);
num++; num++;
} while (data->IsUnique(name) == false); } while (not data->IsUnique(name));
return name; return name;
} }
@ -2641,7 +2625,7 @@ void TMainWindow::UpdateWindowTitle()
if (mIsReadOnly || not isFileWritable) if (mIsReadOnly || not isFileWritable)
{ {
showName += QLatin1String(" (") + tr("read only") + QLatin1String(")"); showName += QStringLiteral(" (") + tr("read only") + QChar(')');
} }
setWindowTitle(showName); setWindowTitle(showName);
@ -2690,46 +2674,44 @@ bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer
const QString postfix = UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch) const QString postfix = UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch)
if (formula.isEmpty()) if (formula.isEmpty())
{ {
label->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field.")); label->setText(tr("Error") + QStringLiteral(" (") + postfix + QStringLiteral("). ") + tr("Empty field."));
label->setToolTip(tr("Empty field")); label->setToolTip(tr("Empty field"));
return false; return false;
} }
else
try
{ {
try // Replace line return character with spaces for calc if exist
QString f;
if (fromUser)
{ {
// Replace line return character with spaces for calc if exist f = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
QString f;
if (fromUser)
{
f = qApp->TrVars()->FormulaFromUser(formula, qApp->Settings()->GetOsSeparator());
}
else
{
f = formula;
}
QScopedPointer<Calculator> cal(new Calculator());
qreal result = cal->EvalFormula(data->DataVariables(), f);
if (qIsInf(result) || qIsNaN(result))
{
label->setText(tr("Error") + " (" + postfix + ").");
label->setToolTip(tr("Invalid result. Value is infinite or NaN. Please, check your calculations."));
return false;
}
result = UnitConvertor(result, mUnit, pUnit);
label->setText(qApp->LocaleToString(result) + QChar(QChar::Space) +postfix);
label->setToolTip(tr("Value"));
return true;
} }
catch (qmu::QmuParserError &e) else
{ {
label->setText(tr("Error") + " (" + postfix + "). " + tr("Parser error: %1").arg(e.GetMsg())); f = formula;
label->setToolTip(tr("Parser error: %1").arg(e.GetMsg())); }
QScopedPointer<Calculator> cal(new Calculator());
qreal result = cal->EvalFormula(data->DataVariables(), f);
if (qIsInf(result) || qIsNaN(result))
{
label->setText(tr("Error") + " (" + postfix + ").");
label->setToolTip(tr("Invalid result. Value is infinite or NaN. Please, check your calculations."));
return false; return false;
} }
result = UnitConvertor(result, mUnit, pUnit);
label->setText(qApp->LocaleToString(result) + QChar(QChar::Space) +postfix);
label->setToolTip(tr("Value"));
return true;
}
catch (qmu::QmuParserError &e)
{
label->setText(tr("Error") + " (" + postfix + "). " + tr("Parser error: %1").arg(e.GetMsg()));
label->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
return false;
} }
} }
@ -2896,27 +2878,22 @@ bool TMainWindow::LoadFromExistingFile(const QString &path)
if (mType == MeasurementsType::Unknown) if (mType == MeasurementsType::Unknown)
{ {
VException e(tr("File has unknown format.")); throw VException(tr("File has unknown format."));
throw e;
} }
if (mType == MeasurementsType::Multisize) if (mType == MeasurementsType::Multisize)
{ {
VException e(tr("Export from multisize measurements is not supported.")); throw VException (tr("Export from multisize measurements is not supported."));
throw e;
}
else
{
VVITConverter converter(path);
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
m_curFileFormatVersionStr = converter.GetFormatVersionStr();
m->setXMLContent(converter.Convert());// Read again after conversion
} }
VVITConverter converter(path);
m_curFileFormatVersion = converter.GetCurrentFormatVersion();
m_curFileFormatVersionStr = converter.GetFormatVersionStr();
m->setXMLContent(converter.Convert());// Read again after conversion
if (not m->IsDefinedKnownNamesValid()) if (not m->IsDefinedKnownNamesValid())
{ {
VException e(tr("File contains invalid known measurement(s).")); throw VException(tr("File contains invalid known measurement(s)."));
throw e;
} }
mUnit = m->MUnit(); mUnit = m->MUnit();
@ -2981,16 +2958,16 @@ void TMainWindow::UpdateRecentFileActions()
for (int i = 0; i < numRecentFiles; ++i) for (int i = 0; i < numRecentFiles; ++i)
{ {
const QString text = QString("&%1. %2").arg(i + 1).arg(StrippedName(files.at(i))); const QString text = QStringLiteral("&%1. %2").arg(i + 1).arg(StrippedName(files.at(i)));
qCDebug(tMainWindow, "file %i = %s", numRecentFiles, qUtf8Printable(text)); qCDebug(tMainWindow, "file %i = %s", numRecentFiles, qUtf8Printable(text));
recentFileActs[i]->setText(text); recentFileActs.at(i)->setText(text);
recentFileActs[i]->setData(files.at(i)); recentFileActs.at(i)->setData(files.at(i));
recentFileActs[i]->setVisible(true); recentFileActs.at(i)->setVisible(true);
} }
for (int j = numRecentFiles; j < MaxRecentFiles; ++j) for(auto &recentFileAct : recentFileActs)
{ {
recentFileActs[j]->setVisible(false); recentFileAct->setVisible(false);
} }
separatorAct->setVisible(numRecentFiles>0); separatorAct->setVisible(numRecentFiles>0);
@ -3014,11 +2991,11 @@ void TMainWindow::CreateWindowMenu(QMenu *menu)
{ {
TMainWindow *window = windows.at(i); TMainWindow *window = windows.at(i);
QString title = QString("%1. %2").arg(i+1).arg(window->windowTitle()); QString title = QStringLiteral("%1. %2").arg(i+1).arg(window->windowTitle());
const int index = title.lastIndexOf("[*]"); const int index = title.lastIndexOf(QLatin1String("[*]"));
if (index != -1) if (index != -1)
{ {
window->isWindowModified() ? title.replace(index, 3, "*") : title.replace(index, 3, QString()); window->isWindowModified() ? title.replace(index, 3, QChar('*')) : title.replace(index, 3, QString());
} }
QAction *action = menu->addAction(title, this, SLOT(ShowWindow())); QAction *action = menu->addAction(title, this, SLOT(ShowWindow()));
@ -3231,7 +3208,7 @@ void TMainWindow::ImportIndividualMeasurements(const QxtCsvModel &csv)
} }
} }
for(auto im : qAsConst(measurements)) for(auto &im : qAsConst(measurements))
{ {
m->AddEmpty(im.name, im.value); m->AddEmpty(im.name, im.value);
@ -3278,17 +3255,14 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv)
{ {
MultisizeMeasurement() MultisizeMeasurement()
: name(), : name(),
base(0),
heightIncrease(0),
sizeIncrease(0),
fullName(), fullName(),
description() description()
{} {}
QString name; QString name;
qreal base; qreal base{0};
qreal heightIncrease; qreal heightIncrease{0};
qreal sizeIncrease; qreal sizeIncrease{0};
QString fullName; QString fullName;
QString description; QString description;
}; };
@ -3341,7 +3315,7 @@ void TMainWindow::ImportMultisizeMeasurements(const QxtCsvModel &csv)
} }
} }
for(auto mm : qAsConst(measurements)) for(auto &mm : qAsConst(measurements))
{ {
m->AddEmpty(mm.name); m->AddEmpty(mm.name);
m->SetMBaseValue(mm.name, mm.base); m->SetMBaseValue(mm.name, mm.base);

View File

@ -154,7 +154,7 @@ private:
bool isInitialized; bool isInitialized;
bool mIsReadOnly; bool mIsReadOnly;
enum { MaxRecentFiles = 5 }; enum { MaxRecentFiles = 5 };
QAction *recentFileActs[MaxRecentFiles]; QVector<QAction *> recentFileActs;
QAction *separatorAct; QAction *separatorAct;
QVector<QObject *> hackedWidgets; QVector<QObject *> hackedWidgets;

View File

@ -40,7 +40,7 @@
* @brief VException constructor exception * @brief VException constructor exception
* @param error string with error * @param error string with error
*/ */
VException::VException(const QString &error) VException::VException(const QString &error) V_NOEXCEPT_EXPR (true)
:QException(), error(error), moreInfo(QString()) :QException(), error(error), moreInfo(QString())
{ {
Q_ASSERT_X(not error.isEmpty(), Q_FUNC_INFO, "Error message is empty"); Q_ASSERT_X(not error.isEmpty(), Q_FUNC_INFO, "Error message is empty");
@ -51,11 +51,12 @@ VException::VException(const QString &error)
* @brief VException copy constructor * @brief VException copy constructor
* @param e exception * @param e exception
*/ */
VException::VException(const VException &e):error(e.WhatUtf8()), moreInfo(e.MoreInformation()) VException::VException(const VException &e) V_NOEXCEPT_EXPR (true)
:error(e.WhatUtf8()), moreInfo(e.MoreInformation())
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VException &VException::operator=(const VException &e) VException &VException::operator=(const VException &e) V_NOEXCEPT_EXPR (true)
{ {
if ( &e == this ) if ( &e == this )
{ {
@ -87,20 +88,19 @@ void VException::AddMoreInformation(const QString &info)
{ {
return; return;
} }
moreInfo = QString("%1\n%2").arg(moreInfo, info);
moreInfo = QStringLiteral("%1\n%2").arg(moreInfo, info);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VException::MoreInfo(const QString &detInfo) const QString VException::MoreInfo(const QString &detInfo) const
{ {
if (moreInfo.isEmpty() == false) if (not moreInfo.isEmpty())
{ {
return QString("%1\n%2").arg(moreInfo, detInfo); return QStringLiteral("%1\n%2").arg(moreInfo, detInfo);
}
else
{
return detInfo;
} }
return detInfo;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -135,19 +135,19 @@ Q_NORETURN void VException::raise() const
} }
//-----------------------------------------VExceptionToolWasDeleted---------------------------------------------------- //-----------------------------------------VExceptionToolWasDeleted----------------------------------------------------
VExceptionToolWasDeleted::VExceptionToolWasDeleted(const QString &error) VExceptionToolWasDeleted::VExceptionToolWasDeleted(const QString &error) V_NOEXCEPT_EXPR (true)
:VException(error) :VException(error)
{ {
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VExceptionToolWasDeleted::VExceptionToolWasDeleted(const VExceptionToolWasDeleted &e) VExceptionToolWasDeleted::VExceptionToolWasDeleted(const VExceptionToolWasDeleted &e) V_NOEXCEPT_EXPR (true)
:VException(e) :VException(e)
{ {
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VExceptionToolWasDeleted &VExceptionToolWasDeleted::operator=(const VExceptionToolWasDeleted &e) VExceptionToolWasDeleted &VExceptionToolWasDeleted::operator=(const VExceptionToolWasDeleted &e) V_NOEXCEPT_EXPR (true)
{ {
if ( &e == this ) if ( &e == this )
{ {

View File

@ -43,9 +43,9 @@ class VException : public QException
{ {
Q_DECLARE_TR_FUNCTIONS(VException) Q_DECLARE_TR_FUNCTIONS(VException)
public: public:
explicit VException(const QString &error); explicit VException(const QString &error) V_NOEXCEPT_EXPR (true);
VException(const VException &e); VException(const VException &e) V_NOEXCEPT_EXPR (true);
VException &operator=(const VException &e); VException &operator=(const VException &e) V_NOEXCEPT_EXPR (true);
virtual ~VException() V_NOEXCEPT_EXPR (true) Q_DECL_EQ_DEFAULT; virtual ~VException() V_NOEXCEPT_EXPR (true) Q_DECL_EQ_DEFAULT;
Q_NORETURN virtual void raise() const override; Q_NORETURN virtual void raise() const override;
@ -94,9 +94,9 @@ class VExceptionToolWasDeleted : public VException
{ {
Q_DECLARE_TR_FUNCTIONS(VExceptionToolDeleted) Q_DECLARE_TR_FUNCTIONS(VExceptionToolDeleted)
public: public:
explicit VExceptionToolWasDeleted(const QString &error); explicit VExceptionToolWasDeleted(const QString &error) V_NOEXCEPT_EXPR (true);
VExceptionToolWasDeleted(const VExceptionToolWasDeleted &e); VExceptionToolWasDeleted(const VExceptionToolWasDeleted &e) V_NOEXCEPT_EXPR (true);
VExceptionToolWasDeleted &operator=(const VExceptionToolWasDeleted &e); VExceptionToolWasDeleted &operator=(const VExceptionToolWasDeleted &e) V_NOEXCEPT_EXPR (true);
virtual ~VExceptionToolWasDeleted() V_NOEXCEPT_EXPR (true) Q_DECL_EQ_DEFAULT; virtual ~VExceptionToolWasDeleted() V_NOEXCEPT_EXPR (true) Q_DECL_EQ_DEFAULT;
Q_NORETURN virtual void raise() const override; Q_NORETURN virtual void raise() const override;