Fixed issue #167. Window modified indication disappears even we have unsaved

change.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-12-18 13:57:03 +02:00
parent 3beb8a8b7c
commit b2ec130d7e
5 changed files with 51 additions and 17 deletions

View file

@ -142,11 +142,6 @@ void DialogPatternProperties::Apply()
//---------------------------------------------------------------------------------------------------------------------
void DialogPatternProperties::Ok()
{
if (descriptionChanged || gradationChanged || defaultChanged)
{
emit doc->patternChanged(false);
}
if (descriptionChanged)
{
SaveDescription();

View file

@ -2590,8 +2590,9 @@ void MainWindow::PatternWasModified(bool saved)
{
if (guiEnabled)
{
setWindowModified(!saved);
ui->actionSave->setEnabled(!saved);
const bool state = doc->IsModified() || !saved;
setWindowModified(state);
ui->actionSave->setEnabled(state);
isLayoutStale = true;
}
}
@ -2883,7 +2884,7 @@ bool MainWindow::SavePattern(const QString &fileName, QString &error)
const bool result = doc->SaveDocument(fileName, error);
if (result)
{
if (tempInfo.suffix() != "autosave")
if (tempInfo.suffix() != QLatin1Literal("autosave"))
{
setCurrentFile(fileName);
helpLabel->setText(tr("File saved"));
@ -3528,13 +3529,7 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu
if (guiEnabled)
{ // No errors occurred
bool patternModified = this->isWindowModified();
setCurrentFile(fileName);
if (patternModified)
{
//For situation where was fixed wrong formula need return for document status was modified.
PatternWasModified(!patternModified);
}
helpLabel->setText(tr("File loaded"));
qCDebug(vMainWindow, "File loaded.");

View file

@ -310,12 +310,18 @@ bool VPattern::SaveDocument(const QString &fileName, QString &error) const
}
catch (const VExceptionWrongId &e)
{
qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error no unique id.")),
qCCritical(vXML, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Error not unique id.")),
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
return false;
}
return VDomDocument::SaveDocument(fileName, error);
const bool saved = VAbstractPattern::SaveDocument(fileName, error);
if (saved && QFileInfo(fileName).suffix() != QLatin1Literal("autosave"))
{
modified = false;
}
return saved;
}
//---------------------------------------------------------------------------------------------------------------------
@ -977,6 +983,7 @@ void VPattern::ParseToolEndLine(VMainGraphicsScene *scene, QDomElement &domEleme
{
SetAttribute(domElement, AttrLength, f);
SetAttribute(domElement, AttrAngle, angleFix);
modified = true;
haveLiteChange();
}
}
@ -1021,6 +1028,7 @@ void VPattern::ParseToolAlongLine(VMainGraphicsScene *scene, QDomElement &domEle
if (f != formula)
{
SetAttribute(domElement, AttrLength, f);
modified = true;
haveLiteChange();
}
}
@ -1066,6 +1074,7 @@ void VPattern::ParseToolShoulderPoint(VMainGraphicsScene *scene, QDomElement &do
if (f != formula)
{
SetAttribute(domElement, AttrLength, f);
modified = true;
haveLiteChange();
}
}
@ -1111,6 +1120,7 @@ void VPattern::ParseToolNormal(VMainGraphicsScene *scene, QDomElement &domElemen
if (f != formula)
{
SetAttribute(domElement, AttrLength, f);
modified = true;
haveLiteChange();
}
}
@ -1156,6 +1166,7 @@ void VPattern::ParseToolBisector(VMainGraphicsScene *scene, QDomElement &domElem
if (f != formula)
{
SetAttribute(domElement, AttrLength, f);
modified = true;
haveLiteChange();
}
}
@ -1229,6 +1240,7 @@ void VPattern::ParseToolPointOfContact(VMainGraphicsScene *scene, QDomElement &d
if (f != radius)
{
SetAttribute(domElement, AttrRadius, f);
modified = true;
haveLiteChange();
}
}
@ -1389,6 +1401,7 @@ void VPattern::ParseToolCutSpline(VMainGraphicsScene *scene, QDomElement &domEle
if (f != formula)
{
SetAttribute(domElement, AttrLength, f);
modified = true;
haveLiteChange();
}
}
@ -1433,6 +1446,7 @@ void VPattern::ParseToolCutSplinePath(VMainGraphicsScene *scene, QDomElement &do
if (f != formula)
{
SetAttribute(domElement, AttrLength, f);
modified = true;
haveLiteChange();
}
}
@ -1474,6 +1488,7 @@ void VPattern::ParseToolCutArc(VMainGraphicsScene *scene, QDomElement &domElemen
if (f != formula)
{
SetAttribute(domElement, AttrLength, f);
modified = true;
haveLiteChange();
}
}
@ -1522,6 +1537,7 @@ void VPattern::ParseToolLineIntersectAxis(VMainGraphicsScene *scene, QDomElement
if (angleFix != angle)
{
SetAttribute(domElement, AttrAngle, angleFix);
modified = true;
haveLiteChange();
}
}
@ -1570,6 +1586,7 @@ void VPattern::ParseToolCurveIntersectAxis(VMainGraphicsScene *scene, QDomElemen
if (angleFix != angle)
{
SetAttribute(domElement, AttrAngle, angleFix);
modified = true;
haveLiteChange();
}
}
@ -1652,6 +1669,7 @@ void VPattern::ParseToolPointOfIntersectionCircles(VMainGraphicsScene *scene, QD
{
SetAttribute(domElement, AttrC1Center, c1R);
SetAttribute(domElement, AttrC2Center, c2R);
modified = true;
haveLiteChange();
}
}
@ -1692,6 +1710,7 @@ void VPattern::ParseToolPointFromCircleAndTangent(VMainGraphicsScene *scene, QDo
if (cR != cRadius)
{
SetAttribute(domElement, AttrCCenter, cR);
modified = true;
haveLiteChange();
}
}
@ -1940,6 +1959,7 @@ void VPattern::ParseToolArc(VMainGraphicsScene *scene, QDomElement &domElement,
SetAttribute(domElement, AttrRadius, r);
SetAttribute(domElement, AttrAngle1, f1Fix);
SetAttribute(domElement, AttrAngle2, f2Fix);
modified = true;
haveLiteChange();
}
}
@ -2011,6 +2031,7 @@ void VPattern::ParseToolArcWithLength(VMainGraphicsScene *scene, QDomElement &do
SetAttribute(domElement, AttrRadius, r);
SetAttribute(domElement, AttrAngle1, f1Fix);
SetAttribute(domElement, AttrLength, lengthFix);
modified = true;
haveLiteChange();
}
}
@ -2268,6 +2289,7 @@ void VPattern::SetAuthor(const QString &text)
{
CheckTagExists(TagAuthor);
setTagText(TagAuthor, text);
modified = true;
emit patternChanged(false);
}
@ -2481,6 +2503,7 @@ void VPattern::SetDefCustom(bool value)
if (domElement.isNull() == false)
{
SetAttribute(domElement, AttrCustom, value);
modified = true;
}
else
{
@ -2539,6 +2562,7 @@ void VPattern::SetDefCustomHeight(int value)
{
SetAttribute(domElement, AttrDefHeight, value);
}
modified = true;
}
else
{
@ -2597,6 +2621,7 @@ void VPattern::SetDefCustomSize(int value)
{
SetAttribute(domElement, AttrDefSize, value);
}
modified = true;
}
else
{

View file

@ -107,7 +107,7 @@ const QString VAbstractPattern::IncrementDescription = QStringLiteral("descripti
//---------------------------------------------------------------------------------------------------------------------
VAbstractPattern::VAbstractPattern(QObject *parent)
: QObject(parent), VDomDocument(), nameActivPP(QString()), cursor(0), tools(QHash<quint32, VDataTool*>()),
history(QVector<VToolRecord>()), patternPieces(QStringList())
history(QVector<VToolRecord>()), patternPieces(QStringList()), modified(false)
{}
//---------------------------------------------------------------------------------------------------------------------
@ -673,6 +673,7 @@ void VAbstractPattern::SetGradationHeights(const QMap<GHeights, bool> &options)
SetAttribute(domElement, AttrH188, options.value(GHeights::H188));
SetAttribute(domElement, AttrH194, options.value(GHeights::H194));
modified = true;
emit patternChanged(false);
return;
break;
@ -816,6 +817,7 @@ void VAbstractPattern::SetGradationSizes(const QMap<GSizes, bool> &options)
SetAttribute(domElement, AttrS54, options.value(GSizes::S54));
SetAttribute(domElement, AttrS56, options.value(GSizes::S56));
modified = true;
emit patternChanged(false);
return;
break;
@ -839,6 +841,7 @@ void VAbstractPattern::SetDescription(const QString &text)
{
CheckTagExists(TagDescription);
setTagText(TagDescription, text);
modified = true;
emit patternChanged(false);
}
@ -853,6 +856,7 @@ void VAbstractPattern::SetNotes(const QString &text)
{
CheckTagExists(TagNotes);
setTagText(TagNotes, text);
modified = true;
emit patternChanged(false);
}
@ -1243,3 +1247,13 @@ bool VAbstractPattern::IsFunction(const QString &token) const
return false;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief IsModified state of the document for cases that do not cover QUndoStack.
* @return true if the document was modified without using QUndoStack.
*/
bool VAbstractPattern::IsModified() const
{
return modified;
}

View file

@ -103,6 +103,8 @@ public:
QString GetVersion() const;
void SetVersion();
bool IsModified() const;
static const QString TagPattern;
static const QString TagCalculation;
static const QString TagModeling;
@ -237,6 +239,9 @@ protected:
/** @brief patternPieces list of patern pieces names for combobox*/
QStringList patternPieces;
/** @brief modified keep state of the document for cases that do not cover QUndoStack*/
mutable bool modified;
void ToolExists(const quint32 &id) const;
void SetActivPP(const QString& name);