[qet] [1901] Projects are now displayed with a [Modified] tag after their properties were edited.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1901
Author:   xavier
Date:     2012-07-07 21:45:32 +0200 (Sat, 07 Jul 2012)
Log Message:
-----------
Projects are now displayed with a [Modified] tag after their properties were edited.

Modified Paths:
--------------
    trunk/sources/projectconfigpages.cpp
    trunk/sources/projectview.cpp
    trunk/sources/qetproject.cpp
    trunk/sources/qetproject.h

Modified: trunk/sources/projectconfigpages.cpp
===================================================================
--- trunk/sources/projectconfigpages.cpp	2012-07-07 19:45:30 UTC (rev 1900)
+++ trunk/sources/projectconfigpages.cpp	2012-07-07 19:45:32 UTC (rev 1901)
@@ -105,8 +105,23 @@
 	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 @@
 	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);
+	}
 }
 
 /**

Modified: trunk/sources/projectview.cpp
===================================================================
--- trunk/sources/projectview.cpp	2012-07-07 19:45:30 UTC (rev 1900)
+++ trunk/sources/projectview.cpp	2012-07-07 19:45:32 UTC (rev 1901)
@@ -106,6 +106,7 @@
 	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 @@
 	@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 @@
 		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);
 }
 
 /**

Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp	2012-07-07 19:45:30 UTC (rev 1900)
+++ trunk/sources/qetproject.cpp	2012-07-07 19:45:32 UTC (rev 1901)
@@ -40,6 +40,7 @@
 	QObject(parent),
 	collection_(0),
 	project_qet_version_(-1),
+	modified_(false),
 	read_only_(false),
 	titleblocks_(this)
 {
@@ -69,6 +70,7 @@
 	QObject(parent),
 	collection_(0),
 	project_qet_version_(-1),
+	modified_(false),
 	read_only_(false),
 	titleblocks_(this)
 {
@@ -107,6 +109,7 @@
 	QObject(parent),
 	collection_(0),
 	project_qet_version_(-1),
+	modified_(false),
 	read_only_(false),
 	titleblocks_(this)
 {
@@ -264,6 +267,14 @@
 			)
 		).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 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);
 }
@@ -835,6 +848,17 @@
 }
 
 /**
+	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.
 */
@@ -1122,6 +1146,16 @@
 }
 
 /**
+	@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.
 	@return true si la collection d'elements embarquee a ete modifiee.
@@ -1150,6 +1184,16 @@
 }
 
 /**
+	@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.
 	@return true si les schemas de ce projet ont ete modifies
@@ -1189,12 +1233,10 @@
 	@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);
 }

Modified: trunk/sources/qetproject.h
===================================================================
--- trunk/sources/qetproject.h	2012-07-07 19:45:30 UTC (rev 1900)
+++ trunk/sources/qetproject.h	2012-07-07 19:45:32 UTC (rev 1901)
@@ -113,7 +113,9 @@
 	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 @@
 	Diagram *addNewDiagram();
 	void removeDiagram(Diagram *);
 	void diagramOrderChanged(int, int);
+	void setModified(bool);
 	
 	signals:
 	void projectFilePathChanged(QETProject *, const QString &);
@@ -130,6 +133,7 @@
 	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 @@
 	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


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/