From e0d23abd9122102731e636046c1cdff84ecf874a Mon Sep 17 00:00:00 2001 From: xavier Date: Sat, 7 Jul 2012 19:45:32 +0000 Subject: [PATCH] Projects are now displayed with a [Modified] tag after their properties were edited. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1901 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/projectconfigpages.cpp | 45 ++++++++++++++++++++++++++---- sources/projectview.cpp | 11 ++++---- sources/qetproject.cpp | 50 +++++++++++++++++++++++++++++++--- sources/qetproject.h | 6 ++++ 4 files changed, 98 insertions(+), 14 deletions(-) diff --git a/sources/projectconfigpages.cpp b/sources/projectconfigpages.cpp index ea12c533f..110f92f41 100644 --- a/sources/projectconfigpages.cpp +++ b/sources/projectconfigpages.cpp @@ -105,8 +105,23 @@ QIcon ProjectMainConfigPage::icon() const { Apply the configuration after user input */ void ProjectMainConfigPage::applyProjectConf() { - project_ -> setTitle(title_value_ -> text()); - project_ -> setProjectProperties(project_variables_ -> context()); + bool modified_project = false; + + QString new_title = title_value_ -> text(); + if (project_ -> title() != new_title) { + project_ -> setTitle(new_title); + modified_project = true; + } + + DiagramContext new_properties = project_variables_ -> context(); + if (project_ -> projectProperties() != new_properties) { + project_ -> setProjectProperties(new_properties); + modified_project = true; + } + + if (modified_project) { + project_ -> setModified(true); + } } /** @@ -202,9 +217,29 @@ QIcon ProjectNewDiagramConfigPage::icon() const { Apply the configuration after user input */ void ProjectNewDiagramConfigPage::applyProjectConf() { - project_ -> setDefaultBorderProperties(border_ -> borderProperties()); - project_ -> setDefaultTitleBlockProperties(titleblock_ -> titleBlockProperties()); - project_ -> setDefaultConductorProperties(conductor_ -> conductorProperties()); + bool modified_project = false; + + BorderProperties new_border_prop = border_ -> borderProperties(); + if (project_ -> defaultBorderProperties() != new_border_prop) { + project_ -> setDefaultBorderProperties(border_ -> borderProperties()); + modified_project = true; + } + + TitleBlockProperties new_tbt_prop = titleblock_ -> titleBlockProperties(); + if (project_ -> defaultTitleBlockProperties() != new_tbt_prop) { + project_ -> setDefaultTitleBlockProperties(titleblock_ -> titleBlockProperties()); + modified_project = true; + } + + ConductorProperties new_conductor_prop = conductor_ -> conductorProperties(); + if (project_ -> defaultConductorProperties() != new_conductor_prop) { + project_ -> setDefaultConductorProperties(conductor_ -> conductorProperties()); + modified_project = true; + } + + if (modified_project) { + project_ -> setModified(modified_project); + } } /** diff --git a/sources/projectview.cpp b/sources/projectview.cpp index 0e898c83f..a28a3563b 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -106,6 +106,7 @@ void ProjectView::setProject(QETProject *project) { if (!project_) { project_ = project; connect(project_, SIGNAL(projectTitleChanged(QETProject *, const QString &)), this, SLOT(updateWindowTitle())); + connect(project_, SIGNAL(projectModified (QETProject *, bool)), this, SLOT(updateWindowTitle())); connect(project_, SIGNAL(readOnlyChanged (QETProject *, bool)), this, SLOT(adjustReadOnlyState())); adjustReadOnlyState(); loadDiagrams(); @@ -562,6 +563,7 @@ void ProjectView::exportProject() { @return true si l'enregistrement a reussi, false sinon */ bool ProjectView::save() { + bool result = false; if (project_) { if (project_ -> filePath().isEmpty()) { // le projet n'est pas encore enregistre dans un fichier @@ -572,16 +574,15 @@ bool ProjectView::save() { if (DiagramView *current_view = currentDiagram()) { if (Diagram *diagram = current_view -> diagram()) { diagram -> write(); - updateWindowTitle(); - return(true); + result = true; } } else { // s'il n'y a pas de schema, on appelle directement la methode write() - project_ -> write(); + result = project_ -> write(); } - return(true); } - return(false); + updateWindowTitle(); + return(result); } /** diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 5b59e32d5..ba475ac7c 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -40,6 +40,7 @@ QETProject::QETProject(int diagrams, QObject *parent) : QObject(parent), collection_(0), project_qet_version_(-1), + modified_(false), read_only_(false), titleblocks_(this) { @@ -69,6 +70,7 @@ QETProject::QETProject(const QString &path, QObject *parent) : QObject(parent), collection_(0), project_qet_version_(-1), + modified_(false), read_only_(false), titleblocks_(this) { @@ -107,6 +109,7 @@ QETProject::QETProject(const QDomElement &xml_element, QObject *parent) : QObject(parent), collection_(0), project_qet_version_(-1), + modified_(false), read_only_(false), titleblocks_(this) { @@ -264,6 +267,14 @@ QString QETProject::pathNameTitle() const { ) ).arg(final_title); } + if (modified_) { + final_title = QString( + tr( + "%1 [modifi\351]", + "displayed title for a modified project - %1 is a displayable title" + ) + ).arg(final_title); + } return(final_title); } @@ -478,6 +489,8 @@ bool QETProject::write() { bool writing = QET::writeXmlFile(document_root_, file_path_, &error_message); if (!writing) { qDebug() << qPrintable(QString("QETProject::write() : %1 [%2]").arg(error_message).arg(QET::pointerString(this))); + } else { + setModified(false); } return(writing); } @@ -834,6 +847,17 @@ void QETProject::diagramOrderChanged(int old_index, int new_index) { emit(projectDiagramsOrderChanged(this, old_index, new_index)); } +/** + Mark this project as modified and emit the projectModified() signal. +*/ +void QETProject::setModified(bool modified) { + if (modified_ != modified) { + modified_ = modified; + emit(projectModified(this, modified_)); + emit(projectInformationsChanged(this)); + } +} + /** Set up signals/slots connections related to the title block templates collection. @@ -1121,6 +1145,16 @@ NamesList QETProject::namesListForIntegrationCategory() { return(names); } +/** + @return true if project options (title, project-wide properties, settings + for new diagrams, ...) were modified, false otherwise. +*/ +bool QETProject::projectOptionsWereModified() { + // unlike similar methods, this method does not compare the content against + // expected values; instead, we just check whether we have been set as modified. + return(modified_); +} + /** Cette methode sert a reperer un projet vide, c-a-d un projet identique a ce que l'on obtient en faisant Fichier > Nouveau. @@ -1149,6 +1183,16 @@ bool QETProject::embeddedCollectionWasModified() { return(false); } +/** + @return true if the embedded title block templates collection was modified, + false otherwise. +*/ +bool QETProject::titleBlockTemplateCollectionWasModified() { + // we do not expect a new project to embed any title block template (this may + // change in the future though). + return(titleblocks_.templates().count()); +} + /** Cette methode sert a reperer un projet vide, c-a-d un projet identique a ce que l'on obtient en faisant Fichier > Nouveau. @@ -1189,12 +1233,10 @@ void QETProject::setProjectProperties(const DiagramContext &context) { @see diagramsWereModified(), embeddedCollectionWasModified() */ bool QETProject::projectWasModified() { - // il doit avoir un titre vide - if (!title().isEmpty()) return(true); - - // ni ses schemas ni sa collection embarquee ne doivent avoir ete modifies + if (projectOptionsWereModified()) return(true); if (diagramsWereModified()) return(true); if (embeddedCollectionWasModified()) return(true); + if (titleBlockTemplateCollectionWasModified()) return(true); return(false); } diff --git a/sources/qetproject.h b/sources/qetproject.h index 890ee165a..5c842c3de 100644 --- a/sources/qetproject.h +++ b/sources/qetproject.h @@ -113,7 +113,9 @@ class QETProject : public QObject { void cleanUnusedElements(MoveElementsHandler *); void cleanEmptyCategories(MoveElementsHandler *); bool projectWasModified(); + bool projectOptionsWereModified(); bool embeddedCollectionWasModified(); + bool titleBlockTemplateCollectionWasModified(); bool diagramsWereModified(); DiagramContext projectProperties(); void setProjectProperties(const DiagramContext &); @@ -123,6 +125,7 @@ class QETProject : public QObject { Diagram *addNewDiagram(); void removeDiagram(Diagram *); void diagramOrderChanged(int, int); + void setModified(bool); signals: void projectFilePathChanged(QETProject *, const QString &); @@ -130,6 +133,7 @@ class QETProject : public QObject { void projectInformationsChanged(QETProject *); void diagramAdded(QETProject *, Diagram *); void diagramRemoved(QETProject *, Diagram *); + void projectModified(QETProject *, bool); void projectDiagramsOrderChanged(QETProject *, int, int); void elementIntegrated(QETProject *, const ElementsLocation &); void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &); @@ -172,6 +176,8 @@ class QETProject : public QObject { QString project_title_; /// Version de QElectroTech declaree dans le document XML lors de son ouverture qreal project_qet_version_; + /// Whether options were modified + bool modified_; /// booleen indiquant si le projet est en ReadOnly ou non bool read_only_; /// Chemin du fichier pour lequel ce projet est considere comme etant en lecture seule