Warn a user when need to update a file format version.

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2017-04-12 09:49:05 +03:00
parent f384639ac3
commit a1caf972a9
12 changed files with 163 additions and 28 deletions

View File

@ -75,7 +75,7 @@ enum {ColumnName = 0, ColumnFullName, ColumnCalcValue, ColumnFormula, ColumnBase
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
TMainWindow::TMainWindow(QWidget *parent) TMainWindow::TMainWindow(QWidget *parent)
:QMainWindow(parent), : VAbstractMainWindow(parent),
ui(new Ui::TMainWindow), ui(new Ui::TMainWindow),
m(nullptr), m(nullptr),
data(nullptr), data(nullptr),
@ -270,11 +270,15 @@ bool TMainWindow::LoadFile(const QString &path)
if (mType == MeasurementsType::Standard) if (mType == MeasurementsType::Standard)
{ {
VVSTConverter converter(path); VVSTConverter converter(path);
m_curFileFormatVersion = converter.GetCurrentFormatVarsion();
m_curFileFormatVersionStr = converter.GetVersionStr();
m->setXMLContent(converter.Convert());// Read again after conversion m->setXMLContent(converter.Convert());// Read again after conversion
} }
else else
{ {
VVITConverter converter(path); VVITConverter converter(path);
m_curFileFormatVersion = converter.GetCurrentFormatVarsion();
m_curFileFormatVersionStr = converter.GetVersionStr();
m->setXMLContent(converter.Convert());// Read again after conversion m->setXMLContent(converter.Convert());// Read again after conversion
} }
@ -337,6 +341,13 @@ bool TMainWindow::LoadFile(const QString &path)
return true; return true;
} }
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ShowToolTip(const QString &toolTip)
{
Q_UNUSED(toolTip)
// do nothing
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::FileNew() void TMainWindow::FileNew()
{ {
@ -645,6 +656,19 @@ bool TMainWindow::FileSave()
} }
else else
{ {
if (mType == MeasurementsType::Standard
&& m_curFileFormatVersion < VVSTConverter::MeasurementMaxVer
&& not ContinueFormatRewrite(m_curFileFormatVersionStr, VVSTConverter::MeasurementMaxVerStr))
{
return false;
}
else if (mType == MeasurementsType::Individual
&& m_curFileFormatVersion < VVITConverter::MeasurementMaxVer
&& 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*/
@ -703,6 +727,19 @@ bool TMainWindow::FileSave()
messageBox.exec(); messageBox.exec();
return false; return false;
} }
else
{
if (mType == MeasurementsType::Standard)
{
m_curFileFormatVersion = VVSTConverter::MeasurementMaxVer;
m_curFileFormatVersionStr = VVSTConverter::MeasurementMaxVerStr;
}
else
{
m_curFileFormatVersion = VVITConverter::MeasurementMaxVer;
m_curFileFormatVersionStr = VVITConverter::MeasurementMaxVerStr;
}
}
} }
return true; return true;
} }
@ -2794,12 +2831,14 @@ bool TMainWindow::LoadFromExistingFile(const QString &path)
if (mType == MeasurementsType::Standard) if (mType == MeasurementsType::Standard)
{ {
VException e(tr("Export standard measurements not supported.")); VException e(tr("Export from standard measurements is not supported."));
throw e; throw e;
} }
else else
{ {
VVITConverter converter(path); VVITConverter converter(path);
m_curFileFormatVersion = converter.GetCurrentFormatVarsion();
m_curFileFormatVersionStr = converter.GetVersionStr();
m->setXMLContent(converter.Convert());// Read again after conversion m->setXMLContent(converter.Convert());// Read again after conversion
} }

View File

@ -29,13 +29,13 @@
#ifndef TMAINWINDOW_H #ifndef TMAINWINDOW_H
#define TMAINWINDOW_H #define TMAINWINDOW_H
#include <QMainWindow>
#include <QTableWidget> #include <QTableWidget>
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include "../vmisc/vlockguard.h" #include "../vmisc/vlockguard.h"
#include "../vformat/vmeasurements.h" #include "../vformat/vmeasurements.h"
#include "../vmisc/vtablesearch.h" #include "../vmisc/vtablesearch.h"
#include "../vwidgets/vabstractmainwindow.h"
namespace Ui namespace Ui
{ {
@ -44,7 +44,7 @@ namespace Ui
class QLabel; class QLabel;
class TMainWindow : public QMainWindow class TMainWindow : public VAbstractMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -62,6 +62,9 @@ public:
bool LoadFile(const QString &path); bool LoadFile(const QString &path);
public slots:
virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE;
protected: protected:
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE;

View File

@ -140,6 +140,8 @@ void ConfigDialog::showEvent(QShowEvent *event)
resize(sz); resize(sz);
} }
okButton->setFocus();
isInitialized = true;//first show windows are held isInitialized = true;//first show windows are held
} }

View File

@ -59,7 +59,7 @@ ConfigurationPage::ConfigurationPage(QWidget *parent)
unitChanged(false), unitChanged(false),
labelLangChanged(false), labelLangChanged(false),
sendReportCheck(nullptr), sendReportCheck(nullptr),
askPointDeletionCheck(nullptr), resetWarningsButton(nullptr),
toolBarStyleCheck(nullptr), toolBarStyleCheck(nullptr),
saveGroup(nullptr), saveGroup(nullptr),
intervalLabel(nullptr), intervalLabel(nullptr),
@ -112,7 +112,6 @@ void ConfigurationPage::Apply()
settings->SetOsSeparator(osOptionCheck->isChecked()); settings->SetOsSeparator(osOptionCheck->isChecked());
settings->SetSendReportState(sendReportCheck->isChecked()); settings->SetSendReportState(sendReportCheck->isChecked());
settings->SetConfirmItemDelete(askPointDeletionCheck->isChecked());
settings->SetToolBarStyle(toolBarStyleCheck->isChecked()); settings->SetToolBarStyle(toolBarStyleCheck->isChecked());
if (langChanged || systemChanged) if (langChanged || systemChanged)
@ -366,11 +365,16 @@ QGroupBox *ConfigurationPage::DrawGroup()
{ {
drawGroup = new QGroupBox(tr("Pattern Editing")); drawGroup = new QGroupBox(tr("Pattern Editing"));
askPointDeletionCheck = new QCheckBox(tr("Confirm item deletion")); resetWarningsButton = new QPushButton(tr("Reset warnings"));
askPointDeletionCheck->setChecked(qApp->ValentinaSettings()->GetConfirmItemDelete()); QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(resetWarningsButton->sizePolicy().hasHeightForWidth());
resetWarningsButton->setSizePolicy(sizePolicy);
connect(resetWarningsButton, &QPushButton::released, this, &ConfigurationPage::ResetWarnings);
QVBoxLayout *editLayout = new QVBoxLayout; QVBoxLayout *editLayout = new QVBoxLayout;
editLayout->addWidget(askPointDeletionCheck); editLayout->addWidget(resetWarningsButton);
drawGroup->setLayout(editLayout); drawGroup->setLayout(editLayout);
return drawGroup; return drawGroup;
@ -422,14 +426,23 @@ void ConfigurationPage::changeEvent(QEvent *event)
RetranslateUi(); RetranslateUi();
} }
// remember to call base class implementation // remember to call base class implementation
QWidget::changeEvent(event); QWidget::changeEvent(event);
}
//---------------------------------------------------------------------------------------------------------------------
void ConfigurationPage::ResetWarnings()
{
VSettings *settings = qApp->ValentinaSettings();
settings->SetConfirmItemDelete(true);
settings->SetConfirmFormatRewriting(true);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void ConfigurationPage::RetranslateUi() void ConfigurationPage::RetranslateUi()
{ {
toolBarStyleCheck->setText(tr("The text appears under the icon (recommended for beginners).")); toolBarStyleCheck->setText(tr("The text appears under the icon (recommended for beginners)."));
askPointDeletionCheck->setText(tr("Confirm item deletion")); resetWarningsButton->setText(tr("Reset warnings"));
saveGroup->setTitle(tr("Save")); saveGroup->setTitle(tr("Save"));
autoSaveCheck->setText(tr("Auto-save modified pattern")); autoSaveCheck->setText(tr("Auto-save modified pattern"));
@ -477,7 +490,7 @@ void ConfigurationPage::RetranslateUi()
"Crash_reports\">kind of information</a> we collect.")); "Crash_reports\">kind of information</a> we collect."));
drawGroup->setTitle(tr("Pattern Editing")); drawGroup->setTitle(tr("Pattern Editing"));
askPointDeletionCheck->setText(tr("Confirm item deletion")); resetWarningsButton->setText(tr("Confirm item deletion"));
toolBarGroup->setTitle(tr("Toolbar")); toolBarGroup->setTitle(tr("Toolbar"));
toolBarStyleCheck->setText(tr("The text appears under the icon (recommended for beginners).")); toolBarStyleCheck->setText(tr("The text appears under the icon (recommended for beginners)."));
} }

View File

@ -31,6 +31,7 @@
#include <QObject> #include <QObject>
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QPushButton>
#include <QWidget> #include <QWidget>
class QCheckBox; class QCheckBox;
@ -52,6 +53,8 @@ public slots:
void LabelLangChanged(); void LabelLangChanged();
protected: protected:
virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE; virtual void changeEvent(QEvent* event) Q_DECL_OVERRIDE;
private slots:
void ResetWarnings();
private: private:
Q_DISABLE_COPY(ConfigurationPage) Q_DISABLE_COPY(ConfigurationPage)
QCheckBox *autoSaveCheck; QCheckBox *autoSaveCheck;
@ -65,7 +68,7 @@ private:
bool unitChanged; bool unitChanged;
bool labelLangChanged; bool labelLangChanged;
QCheckBox *sendReportCheck; QCheckBox *sendReportCheck;
QCheckBox *askPointDeletionCheck; QPushButton *resetWarningsButton;
QCheckBox *toolBarStyleCheck; QCheckBox *toolBarStyleCheck;
QGroupBox *saveGroup; QGroupBox *saveGroup;

View File

@ -2563,6 +2563,11 @@ bool MainWindow::Save()
} }
else else
{ {
if (m_curFileFormatVersion < VPatternConverter::PatternMaxVer
&& not ContinueFormatRewrite(m_curFileFormatVersionStr, VPatternConverter::PatternMaxVerStr))
{
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*/
@ -2614,6 +2619,8 @@ bool MainWindow::Save()
if (result) if (result)
{ {
QFile::remove(curFile + autosavePrefix); QFile::remove(curFile + autosavePrefix);
m_curFileFormatVersion = VPatternConverter::PatternMaxVer;
m_curFileFormatVersionStr = VPatternConverter::PatternMaxVerStr;
} }
else else
{ {
@ -4090,6 +4097,8 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu
try try
{ {
VPatternConverter converter(fileName); VPatternConverter converter(fileName);
m_curFileFormatVersion = converter.GetCurrentFormatVarsion();
m_curFileFormatVersionStr = converter.GetVersionStr();
doc->setXMLContent(converter.Convert()); doc->setXMLContent(converter.Convert());
if (!customMeasureFile.isEmpty()) if (!customMeasureFile.isEmpty())
{ {

View File

@ -86,6 +86,12 @@ QString VAbstractConverter::Convert()
return m_convertedFileName; return m_convertedFileName;
} }
//---------------------------------------------------------------------------------------------------------------------
int VAbstractConverter::GetCurrentFormatVarsion() const
{
return m_ver;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VAbstractConverter::GetVersionStr() const QString VAbstractConverter::GetVersionStr() const
{ {

View File

@ -55,6 +55,9 @@ public:
QString Convert(); QString Convert();
int GetCurrentFormatVarsion() const;
QString GetVersionStr() const;
static int GetVersion(const QString &version); static int GetVersion(const QString &version);
protected: protected:
@ -87,8 +90,6 @@ private:
QTemporaryFile m_tmpFile; QTemporaryFile m_tmpFile;
QString GetVersionStr() const;
static void ValidateVersion(const QString &version); static void ValidateVersion(const QString &version);
void ReserveFile() const; void ReserveFile() const;

View File

@ -46,15 +46,16 @@ const QString settingPathsIndividualMeasurements = QStringLiteral("paths/individ
const QString settingPathsStandardMeasurements = QStringLiteral("paths/standard_measurements"); const QString settingPathsStandardMeasurements = QStringLiteral("paths/standard_measurements");
const QString settingPathsTemplates = QStringLiteral("paths/templates"); const QString settingPathsTemplates = QStringLiteral("paths/templates");
const QString settingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator"); const QString settingConfigurationOsSeparator = QStringLiteral("configuration/osSeparator");
const QString settingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state"); const QString settingConfigurationAutosaveState = QStringLiteral("configuration/autosave/state");
const QString settingConfigurationAutosaveTime = QStringLiteral("configuration/autosave/time"); const QString settingConfigurationAutosaveTime = QStringLiteral("configuration/autosave/time");
const QString settingConfigurationSendReportState = QStringLiteral("configuration/send_report/state"); const QString settingConfigurationSendReportState = QStringLiteral("configuration/send_report/state");
const QString settingConfigurationLocale = QStringLiteral("configuration/locale"); const QString settingConfigurationLocale = QStringLiteral("configuration/locale");
const QString settingPMSystemCode = QStringLiteral("configuration/pmscode"); const QString settingPMSystemCode = QStringLiteral("configuration/pmscode");
const QString settingConfigurationUnit = QStringLiteral("configuration/unit"); const QString settingConfigurationUnit = QStringLiteral("configuration/unit");
const QString settingConfigurationConfirmItemDeletion = QStringLiteral("configuration/confirm_item_deletion"); const QString settingConfigurationConfirmItemDeletion = QStringLiteral("configuration/confirm_item_deletion");
const QString settingConfigurationToolBarStyle = QStringLiteral("configuration/tool_bar_style"); const QString settingConfigurationConfirmFormatRewriting = QStringLiteral("configuration/confirm_format_rewriting");
const QString settingConfigurationToolBarStyle = QStringLiteral("configuration/tool_bar_style");
const QString settingPatternUser = QStringLiteral("pattern/user"); const QString settingPatternUser = QStringLiteral("pattern/user");
const QString settingPatternUndo = QStringLiteral("pattern/undo"); const QString settingPatternUndo = QStringLiteral("pattern/undo");
@ -392,6 +393,18 @@ void VCommonSettings::SetConfirmItemDelete(const bool &value)
setValue(settingConfigurationConfirmItemDeletion, value); setValue(settingConfigurationConfirmItemDeletion, value);
} }
//---------------------------------------------------------------------------------------------------------------------
bool VCommonSettings::GetConfirmFormatRewriting() const
{
return value(settingConfigurationConfirmFormatRewriting, 1).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
void VCommonSettings::SetConfirmFormatRewriting(const bool &value)
{
setValue(settingConfigurationConfirmFormatRewriting, value);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VCommonSettings::GetToolBarStyle() const bool VCommonSettings::GetToolBarStyle() const
{ {

View File

@ -90,6 +90,9 @@ public:
bool GetConfirmItemDelete() const; bool GetConfirmItemDelete() const;
void SetConfirmItemDelete(const bool &value); void SetConfirmItemDelete(const bool &value);
bool GetConfirmFormatRewriting() const;
void SetConfirmFormatRewriting(const bool &value);
bool GetToolBarStyle() const; bool GetToolBarStyle() const;
void SetToolBarStyle(const bool &value); void SetToolBarStyle(const bool &value);

View File

@ -27,10 +27,44 @@
*************************************************************************/ *************************************************************************/
#include "vabstractmainwindow.h" #include "vabstractmainwindow.h"
#include "../vpropertyexplorer/checkablemessagebox.h"
#include "../vmisc/vabstractapplication.h"
VAbstractMainWindow::VAbstractMainWindow(QWidget *parent) : QMainWindow(parent) #include <QStyle>
VAbstractMainWindow::VAbstractMainWindow(QWidget *parent)
: QMainWindow(parent),
m_curFileFormatVersion(0x0),
m_curFileFormatVersionStr(QLatin1String("0.0.0"))
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstractMainWindow::~VAbstractMainWindow() bool VAbstractMainWindow::ContinueFormatRewrite(const QString &currentFormatVersion,
{} const QString &maxFormatVersion)
{
if (qApp->Settings()->GetConfirmFormatRewriting())
{
Utils::CheckableMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Confirm format rewriting"));
msgBox.setText(tr("This file is using previous format version v%1. The current is v%2. "
"Saving the file with this app version will update the format version for this "
"file. This may prevent you from be abale to open the file with older app versions. "
"Do you really want to continue?").arg(currentFormatVersion).arg(maxFormatVersion));
msgBox.setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
msgBox.setDefaultButton(QDialogButtonBox::No);
msgBox.setIconPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion).pixmap(32, 32));
int dialogResult = msgBox.exec();
if (dialogResult == QDialog::Accepted)
{
qApp->Settings()->SetConfirmFormatRewriting(not msgBox.isChecked());
return true;
}
else
{
return false;
}
}
return true;
}

View File

@ -40,10 +40,19 @@ class VAbstractMainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit VAbstractMainWindow(QWidget *parent = nullptr); explicit VAbstractMainWindow(QWidget *parent = nullptr);
virtual ~VAbstractMainWindow() Q_DECL_OVERRIDE; virtual ~VAbstractMainWindow() Q_DECL_EQ_DEFAULT;
public slots: public slots:
virtual void ShowToolTip(const QString &toolTip)=0; virtual void ShowToolTip(const QString &toolTip)=0;
protected:
int m_curFileFormatVersion;
QString m_curFileFormatVersionStr;
bool ContinueFormatRewrite(const QString &currentFormatVersion, const QString &maxFormatVersion);
private:
Q_DISABLE_COPY(VAbstractMainWindow)
}; };
#endif // VABSTRACTMAINWINDOW_H #endif // VABSTRACTMAINWINDOW_H