Commit ca4be197 authored by Jaroslaw Kobus's avatar Jaroslaw Kobus
Browse files

Revert "Replace virtual isModified method with a getter/setter/notifier"

This doesn't fix the issue with cleaning the clear state of undo stack.
This introduced the issue when ui file is opened it's marked as modified.
It reverts 59c90e00
and d0c537ca



Change-Id: Ifd4ff8483d6c297461632de500a4502b1fd0871f
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent a25a855b
...@@ -76,20 +76,17 @@ DocumentController::DocumentController(QObject *parent) : ...@@ -76,20 +76,17 @@ DocumentController::DocumentController(QObject *parent) :
{ {
// project controller // project controller
connect(m_projectController, &ProjectController::changed, this, &DocumentController::changed); connect(m_projectController, &ProjectController::changed, this, &DocumentController::changed);
connect(m_projectController, &ProjectController::modificationChanged, this, &DocumentController::modificationChanged);
// model controller // model controller
m_modelController->setUndoController(m_undoController); m_modelController->setUndoController(m_undoController);
connect(m_modelController, &ModelController::modified, [this](){ connect(m_modelController, &ModelController::modified,
m_projectController->setModified(true); m_projectController, &ProjectController::setModified);
});
// diagram controller // diagram controller
m_diagramController->setModelController(m_modelController); m_diagramController->setModelController(m_modelController);
m_diagramController->setUndoController(m_undoController); m_diagramController->setUndoController(m_undoController);
connect(m_diagramController, &DiagramController::modified, [this](){ connect(m_diagramController, &DiagramController::modified,
m_projectController->setModified(true); m_projectController, &ProjectController::setModified);
});
// diagram scene controller // diagram scene controller
m_diagramSceneController->setModelController(m_modelController); m_diagramSceneController->setModelController(m_modelController);
......
...@@ -61,7 +61,6 @@ public: ...@@ -61,7 +61,6 @@ public:
signals: signals:
void changed(); void changed();
void modificationChanged(bool modified);
void modelClipboardChanged(bool isEmpty); void modelClipboardChanged(bool isEmpty);
void diagramClipboardChanged(bool isEmpty); void diagramClipboardChanged(bool isEmpty);
......
...@@ -43,7 +43,8 @@ ProjectIsModifiedException::ProjectIsModifiedException() ...@@ -43,7 +43,8 @@ ProjectIsModifiedException::ProjectIsModifiedException()
} }
ProjectController::ProjectController(QObject *parent) ProjectController::ProjectController(QObject *parent)
: QObject(parent) : QObject(parent),
m_isModified(false)
{ {
} }
...@@ -58,7 +59,7 @@ void ProjectController::newProject(const QString &fileName) ...@@ -58,7 +59,7 @@ void ProjectController::newProject(const QString &fileName)
rootPackage->setName(tr("Model")); rootPackage->setName(tr("Model"));
m_project->setRootPackage(rootPackage); m_project->setRootPackage(rootPackage);
m_project->setFileName(fileName); m_project->setFileName(fileName);
setModified(false); m_isModified = false;
emit fileNameChanged(m_project->fileName()); emit fileNameChanged(m_project->fileName());
emit changed(); emit changed();
} }
...@@ -67,18 +68,17 @@ void ProjectController::setFileName(const QString &fileName) ...@@ -67,18 +68,17 @@ void ProjectController::setFileName(const QString &fileName)
{ {
if (fileName != m_project->fileName()) { if (fileName != m_project->fileName()) {
m_project->setFileName(fileName); m_project->setFileName(fileName);
setModified(true); setModified();
emit fileNameChanged(m_project->fileName()); emit fileNameChanged(m_project->fileName());
} }
} }
void ProjectController::setModified(bool modified) void ProjectController::setModified()
{ {
if (m_isModified == modified) if (!m_isModified) {
return; m_isModified = true;
emit changed();
m_isModified = modified; }
emit modificationChanged(modified);
} }
void ProjectController::load() void ProjectController::load()
...@@ -89,7 +89,7 @@ void ProjectController::load() ...@@ -89,7 +89,7 @@ void ProjectController::load()
throw NoFileNameException(); throw NoFileNameException();
ProjectSerializer serializer; ProjectSerializer serializer;
serializer.load(m_project->fileName(), m_project.data()); serializer.load(m_project->fileName(), m_project.data());
setModified(false); m_isModified = false;
emit changed(); emit changed();
} }
...@@ -99,7 +99,7 @@ void ProjectController::save() ...@@ -99,7 +99,7 @@ void ProjectController::save()
throw NoFileNameException(); throw NoFileNameException();
ProjectSerializer serializer; ProjectSerializer serializer;
serializer.save(m_project->fileName(), m_project.data()); serializer.save(m_project->fileName(), m_project.data());
setModified(false); m_isModified = false;
emit changed(); emit changed();
} }
......
...@@ -58,7 +58,6 @@ public: ...@@ -58,7 +58,6 @@ public:
signals: signals:
void changed(); void changed();
void fileNameChanged(const QString &fileName); void fileNameChanged(const QString &fileName);
void modificationChanged(bool modified);
public: public:
Project *project() const { return m_project.data(); } Project *project() const { return m_project.data(); }
...@@ -66,7 +65,7 @@ public: ...@@ -66,7 +65,7 @@ public:
void newProject(const QString &fileName); void newProject(const QString &fileName);
void setFileName(const QString &fileName); void setFileName(const QString &fileName);
void setModified(bool modified); void setModified();
void load(); void load();
void save(); void save();
...@@ -74,7 +73,7 @@ public: ...@@ -74,7 +73,7 @@ public:
private: private:
QScopedPointer<Project> m_project; QScopedPointer<Project> m_project;
bool m_isModified = false; bool m_isModified;
}; };
} // namespace qmt } // namespace qmt
...@@ -43,12 +43,8 @@ AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *ed ...@@ -43,12 +43,8 @@ AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *ed
setId(Constants::ANDROID_MANIFEST_EDITOR_ID); setId(Constants::ANDROID_MANIFEST_EDITOR_ID);
setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE)); setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
setSuspendAllowed(false); setSuspendAllowed(false);
connect(editorWidget, &AndroidManifestEditorWidget::modificationChanged, connect(editorWidget, &AndroidManifestEditorWidget::guiChanged,
this, &Core::IDocument::setModified); this, &Core::IDocument::changed);
connect(this, &Core::IDocument::modificationChanged,
editorWidget, &AndroidManifestEditorWidget::setModified);
setModified(editorWidget->isModified());
} }
bool AndroidManifestDocument::save(QString *errorString, const QString &fileName, bool autoSave) bool AndroidManifestDocument::save(QString *errorString, const QString &fileName, bool autoSave)
...@@ -59,6 +55,11 @@ bool AndroidManifestDocument::save(QString *errorString, const QString &fileName ...@@ -59,6 +55,11 @@ bool AndroidManifestDocument::save(QString *errorString, const QString &fileName
return result; return result;
} }
bool AndroidManifestDocument::isModified() const
{
return TextDocument::isModified() || m_editorWidget->isModified();
}
bool AndroidManifestDocument::isSaveAsAllowed() const bool AndroidManifestDocument::isSaveAsAllowed() const
{ {
return false; return false;
......
...@@ -39,6 +39,7 @@ public: ...@@ -39,6 +39,7 @@ public:
bool save(QString *errorString, const QString &fileName = QString(), bool save(QString *errorString, const QString &fileName = QString(),
bool autoSave = false) override; bool autoSave = false) override;
bool isModified() const override;
bool isSaveAsAllowed() const override; bool isSaveAsAllowed() const override;
private: private:
......
...@@ -101,7 +101,7 @@ Project *androidProject(const Utils::FileName &fileName) ...@@ -101,7 +101,7 @@ Project *androidProject(const Utils::FileName &fileName)
AndroidManifestEditorWidget::AndroidManifestEditorWidget() AndroidManifestEditorWidget::AndroidManifestEditorWidget()
: QStackedWidget(), : QStackedWidget(),
m_modified(false), m_dirty(false),
m_stayClean(false) m_stayClean(false)
{ {
m_textEditorWidget = new AndroidManifestTextEditorWidget(this); m_textEditorWidget = new AndroidManifestTextEditorWidget(this);
...@@ -138,7 +138,7 @@ void AndroidManifestEditorWidget::initializePage() ...@@ -138,7 +138,7 @@ void AndroidManifestEditorWidget::initializePage()
QGroupBox *packageGroupBox = new QGroupBox(mainWidget); QGroupBox *packageGroupBox = new QGroupBox(mainWidget);
topLayout->addWidget(packageGroupBox); topLayout->addWidget(packageGroupBox);
auto setDirtyFunc = [this] { setModified(); }; auto setDirtyFunc = [this] { setDirty(); };
packageGroupBox->setTitle(tr("Package")); packageGroupBox->setTitle(tr("Package"));
{ {
QFormLayout *formLayout = new QFormLayout(); QFormLayout *formLayout = new QFormLayout();
...@@ -206,7 +206,7 @@ void AndroidManifestEditorWidget::initializePage() ...@@ -206,7 +206,7 @@ void AndroidManifestEditorWidget::initializePage()
connect(m_packageNameLineEdit, &QLineEdit::textEdited, connect(m_packageNameLineEdit, &QLineEdit::textEdited,
this, &AndroidManifestEditorWidget::setPackageName); this, &AndroidManifestEditorWidget::setPackageName);
connect(m_versionCode, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), connect(m_versionCode, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &AndroidManifestEditorWidget::setModified); this, &AndroidManifestEditorWidget::setDirty);
connect(m_versionNameLinedit, &QLineEdit::textEdited, connect(m_versionNameLinedit, &QLineEdit::textEdited,
this, setDirtyFunc); this, setDirtyFunc);
connect(m_androidMinSdkVersion, connect(m_androidMinSdkVersion,
...@@ -524,17 +524,17 @@ void AndroidManifestEditorWidget::updateAfterFileLoad() ...@@ -524,17 +524,17 @@ void AndroidManifestEditorWidget::updateAfterFileLoad()
setActivePage(Source); setActivePage(Source);
} }
void AndroidManifestEditorWidget::setModified(bool modified) void AndroidManifestEditorWidget::setDirty(bool dirty)
{ {
if (m_stayClean || modified == m_modified) if (m_stayClean || dirty == m_dirty)
return; return;
m_modified = modified; m_dirty = dirty;
emit modificationChanged(modified); emit guiChanged();
} }
bool AndroidManifestEditorWidget::isModified() const bool AndroidManifestEditorWidget::isModified() const
{ {
return m_modified return m_dirty
|| !m_hIconPath.isEmpty() || !m_hIconPath.isEmpty()
|| !m_mIconPath.isEmpty() || !m_mIconPath.isEmpty()
|| !m_lIconPath.isEmpty(); || !m_lIconPath.isEmpty();
...@@ -819,7 +819,7 @@ void AndroidManifestEditorWidget::syncToWidgets(const QDomDocument &doc) ...@@ -819,7 +819,7 @@ void AndroidManifestEditorWidget::syncToWidgets(const QDomDocument &doc)
updateAddRemovePermissionButtons(); updateAddRemovePermissionButtons();
m_stayClean = false; m_stayClean = false;
m_modified = false; m_dirty = false;
} }
int extractVersion(const QString &string) int extractVersion(const QString &string)
...@@ -862,7 +862,7 @@ void AndroidManifestEditorWidget::syncToEditor() ...@@ -862,7 +862,7 @@ void AndroidManifestEditorWidget::syncToEditor()
m_textEditorWidget->setPlainText(result); m_textEditorWidget->setPlainText(result);
m_textEditorWidget->document()->setModified(true); m_textEditorWidget->document()->setModified(true);
m_modified = false; m_dirty = false;
} }
namespace { namespace {
...@@ -1253,7 +1253,7 @@ void AndroidManifestEditorWidget::setLDPIIcon() ...@@ -1253,7 +1253,7 @@ void AndroidManifestEditorWidget::setLDPIIcon()
return; return;
m_lIconPath = file; m_lIconPath = file;
m_lIconButton->setIcon(QIcon(file)); m_lIconButton->setIcon(QIcon(file));
setModified(true); setDirty(true);
} }
void AndroidManifestEditorWidget::setMDPIIcon() void AndroidManifestEditorWidget::setMDPIIcon()
...@@ -1263,7 +1263,7 @@ void AndroidManifestEditorWidget::setMDPIIcon() ...@@ -1263,7 +1263,7 @@ void AndroidManifestEditorWidget::setMDPIIcon()
return; return;
m_mIconPath = file; m_mIconPath = file;
m_mIconButton->setIcon(QIcon(file)); m_mIconButton->setIcon(QIcon(file));
setModified(true); setDirty(true);
} }
void AndroidManifestEditorWidget::setHDPIIcon() void AndroidManifestEditorWidget::setHDPIIcon()
...@@ -1273,12 +1273,12 @@ void AndroidManifestEditorWidget::setHDPIIcon() ...@@ -1273,12 +1273,12 @@ void AndroidManifestEditorWidget::setHDPIIcon()
return; return;
m_hIconPath = file; m_hIconPath = file;
m_hIconButton->setIcon(QIcon(file)); m_hIconButton->setIcon(QIcon(file));
setModified(true); setDirty(true);
} }
void AndroidManifestEditorWidget::defaultPermissionOrFeatureCheckBoxClicked() void AndroidManifestEditorWidget::defaultPermissionOrFeatureCheckBoxClicked()
{ {
setModified(true); setDirty(true);
} }
void AndroidManifestEditorWidget::updateAddRemovePermissionButtons() void AndroidManifestEditorWidget::updateAddRemovePermissionButtons()
...@@ -1293,7 +1293,7 @@ void AndroidManifestEditorWidget::addPermission() ...@@ -1293,7 +1293,7 @@ void AndroidManifestEditorWidget::addPermission()
{ {
m_permissionsModel->addPermission(m_permissionsComboBox->currentText()); m_permissionsModel->addPermission(m_permissionsComboBox->currentText());
updateAddRemovePermissionButtons(); updateAddRemovePermissionButtons();
setModified(true); setDirty(true);
} }
void AndroidManifestEditorWidget::removePermission() void AndroidManifestEditorWidget::removePermission()
...@@ -1302,7 +1302,7 @@ void AndroidManifestEditorWidget::removePermission() ...@@ -1302,7 +1302,7 @@ void AndroidManifestEditorWidget::removePermission()
if (idx.isValid()) if (idx.isValid())
m_permissionsModel->removePermission(idx.row()); m_permissionsModel->removePermission(idx.row());
updateAddRemovePermissionButtons(); updateAddRemovePermissionButtons();
setModified(true); setDirty(true);
} }
void AndroidManifestEditorWidget::setPackageName() void AndroidManifestEditorWidget::setPackageName()
...@@ -1312,7 +1312,7 @@ void AndroidManifestEditorWidget::setPackageName() ...@@ -1312,7 +1312,7 @@ void AndroidManifestEditorWidget::setPackageName()
bool valid = checkPackageName(packageName); bool valid = checkPackageName(packageName);
m_packageNameWarning->setVisible(!valid); m_packageNameWarning->setVisible(!valid);
m_packageNameWarningIcon->setVisible(!valid); m_packageNameWarningIcon->setVisible(!valid);
setModified(true); setDirty(true);
} }
......
...@@ -101,10 +101,10 @@ public: ...@@ -101,10 +101,10 @@ public:
Core::IEditor *editor() const; Core::IEditor *editor() const;
TextEditor::TextEditorWidget *textEditorWidget() const; TextEditor::TextEditorWidget *textEditorWidget() const;
void setModified(bool modified = true); void setDirty(bool dirty = true);
signals: signals:
void modificationChanged(bool modified); void guiChanged();
protected: protected:
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject *obj, QEvent *event);
...@@ -150,7 +150,7 @@ private: ...@@ -150,7 +150,7 @@ private:
QString parseComment(QXmlStreamReader &reader, QXmlStreamWriter &writer); QString parseComment(QXmlStreamReader &reader, QXmlStreamWriter &writer);
void parseUnknownElement(QXmlStreamReader &reader, QXmlStreamWriter &writer); void parseUnknownElement(QXmlStreamReader &reader, QXmlStreamWriter &writer);
bool m_modified; // indicates that we need to call syncToEditor() bool m_dirty; // indicates that we need to call syncToEditor()
bool m_stayClean; bool m_stayClean;
int m_errorLine; int m_errorLine;
int m_errorColumn; int m_errorColumn;
......
...@@ -320,6 +320,12 @@ public: ...@@ -320,6 +320,12 @@ public:
} }
public: public:
bool isModified() const override
{
return isTemporary()/*e.g. memory view*/ ? false
: m_widget->isModified();
}
bool isFileReadOnly() const override { bool isFileReadOnly() const override {
const FileName fn = filePath(); const FileName fn = filePath();
if (fn.isEmpty()) if (fn.isEmpty())
...@@ -385,12 +391,7 @@ public: ...@@ -385,12 +391,7 @@ public:
connect(m_addressEdit, &QLineEdit::editingFinished, connect(m_addressEdit, &QLineEdit::editingFinished,
this, &BinEditor::jumpToAddress); this, &BinEditor::jumpToAddress);
connect(widget, &BinEditorWidget::modificationChanged, connect(widget, &BinEditorWidget::modificationChanged,
m_file, &IDocument::setModified); m_file, &IDocument::changed);
connect(m_file, &IDocument::modificationChanged,
widget, &BinEditorWidget::setModified);
m_file->setModified(widget->isModified());
updateCursorPosition(widget->cursorPosition()); updateCursorPosition(widget->cursorPosition());
} }
......
...@@ -1052,7 +1052,6 @@ void DocumentManager::checkForReload() ...@@ -1052,7 +1052,6 @@ void DocumentManager::checkForReload()
documentsToClose << document; documentsToClose << document;
} else if (defaultBehavior == IDocument::IgnoreAll) { } else if (defaultBehavior == IDocument::IgnoreAll) {
// content change or removed, but settings say ignore // content change or removed, but settings say ignore
document->setModified(true);
success = document->reload(&errorString, IDocument::FlagIgnore, type); success = document->reload(&errorString, IDocument::FlagIgnore, type);
// either the default behavior is to always ask, // either the default behavior is to always ask,
// or the ReloadUnmodified default behavior didn't kick in, // or the ReloadUnmodified default behavior didn't kick in,
...@@ -1070,7 +1069,6 @@ void DocumentManager::checkForReload() ...@@ -1070,7 +1069,6 @@ void DocumentManager::checkForReload()
// content change, IDocument wants to ask user // content change, IDocument wants to ask user
if (previousReloadAnswer == ReloadNone) { if (previousReloadAnswer == ReloadNone) {
// answer already given, ignore // answer already given, ignore
document->setModified(true);
success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents); success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents);
} else if (previousReloadAnswer == ReloadAll) { } else if (previousReloadAnswer == ReloadAll) {
// answer already given, reload // answer already given, reload
...@@ -1086,7 +1084,6 @@ void DocumentManager::checkForReload() ...@@ -1086,7 +1084,6 @@ void DocumentManager::checkForReload()
break; break;
case ReloadSkipCurrent: case ReloadSkipCurrent:
case ReloadNone: case ReloadNone:
document->setModified(true);
success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents); success = document->reload(&errorString, IDocument::FlagIgnore, IDocument::TypeContents);
break; break;
case CloseCurrent: case CloseCurrent:
......
...@@ -79,7 +79,6 @@ public: ...@@ -79,7 +79,6 @@ public:
bool hasWriteWarning = false; bool hasWriteWarning = false;
bool restored = false; bool restored = false;
bool isSuspendAllowed = false; bool isSuspendAllowed = false;
bool isModified = false;
}; };
} // namespace Internal } // namespace Internal
...@@ -201,17 +200,7 @@ bool IDocument::shouldAutoSave() const ...@@ -201,17 +200,7 @@ bool IDocument::shouldAutoSave() const
bool IDocument::isModified() const bool IDocument::isModified() const
{ {
return d->isModified; return false;
}
void IDocument::setModified(bool modified)
{
if (d->isModified == modified)
return;
d->isModified = modified;
emit modificationChanged(modified);
emit changed();
} }
bool IDocument::isSaveAsAllowed() const bool IDocument::isSaveAsAllowed() const
......
...@@ -106,9 +106,6 @@ public: ...@@ -106,9 +106,6 @@ public:
bool isTemporary() const; bool isTemporary() const;
void setTemporary(bool temporary); void setTemporary(bool temporary);
bool isModified() const;
void setModified(bool modified);
virtual QString fallbackSaveAsPath() const; virtual QString fallbackSaveAsPath() const;
virtual QString fallbackSaveAsFileName() const; virtual QString fallbackSaveAsFileName() const;
...@@ -116,6 +113,7 @@ public: ...@@ -116,6 +113,7 @@ public:
void setMimeType(const QString &mimeType); void setMimeType(const QString &mimeType);
virtual bool shouldAutoSave() const; virtual bool shouldAutoSave() const;
virtual bool isModified() const;
virtual bool isSaveAsAllowed() const; virtual bool isSaveAsAllowed() const;
bool isSuspendAllowed() const; bool isSuspendAllowed() const;
void setSuspendAllowed(bool value); void setSuspendAllowed(bool value);
...@@ -138,8 +136,6 @@ signals: ...@@ -138,8 +136,6 @@ signals:
// For meta data changes: file name, modified state, ...