[qet] [1646] QElectroTech is now able to open . titleblock files passed as arguments to the program.

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


Revision: 1646
Author:   xavier
Date:     2012-04-09 17:27:15 +0200 (Mon, 09 Apr 2012)
Log Message:
-----------
QElectroTech is now able to open .titleblock files passed as arguments to the program.

Modified Paths:
--------------
    branches/0.3/sources/qetapp.cpp
    branches/0.3/sources/qetapp.h
    branches/0.3/sources/qetarguments.cpp
    branches/0.3/sources/qetarguments.h
    branches/0.3/sources/titleblock/qettemplateeditor.cpp
    branches/0.3/sources/titleblock/qettemplateeditor.h

Modified: branches/0.3/sources/qetapp.cpp
===================================================================
--- branches/0.3/sources/qetapp.cpp	2012-04-09 11:55:30 UTC (rev 1645)
+++ branches/0.3/sources/qetapp.cpp	2012-04-09 15:27:15 UTC (rev 1646)
@@ -922,6 +922,7 @@
 void QETApp::openFiles(const QETArguments &args) {
 	openProjectFiles(args.projectFiles());
 	openElementFiles(args.elementFiles());
+	openTitleBlockTemplateFiles(args.titleBlockTemplateFiles());
 }
 
 /**
@@ -966,7 +967,7 @@
 
 /**
 	Ouvre les fichiers elements passes en parametre. Si un element est deja
-	ouvert, la fentre qui l'edite est activee.
+	ouvert, la fenetre qui l'edite est activee.
 	@param files_list Fichiers a ouvrir
 */
 void QETApp::openElementFiles(const QStringList &files_list) {
@@ -1063,6 +1064,45 @@
 }
 
 /**
+	Open provided title block template files. If a title block template is already
+	opened, the adequate window is activated.
+	@param files_list Files to be opened
+*/
+void QETApp::openTitleBlockTemplateFiles(const QStringList &files_list) {
+	if (files_list.isEmpty()) return;
+	
+	// avoid duplicates in the provided files list
+	QSet<QString> files_set;
+	foreach (QString file, files_list) {
+		QString canonical_filepath = QFileInfo(file).canonicalFilePath();
+		if (!canonical_filepath.isEmpty()) files_set << canonical_filepath;
+	}
+	// here, we can assume all files in the set exist and are different
+	if (files_set.isEmpty()) return;
+	
+	// opened title block template editors
+	QList<QETTitleBlockTemplateEditor *> tbt_editors = titleBlockTemplateEditors();
+	
+	foreach(QString tbt_file, files_set) {
+		bool already_opened_in_existing_tbt_editor = false;
+		foreach(QETTitleBlockTemplateEditor *tbt_editor, tbt_editors) {
+			if (tbt_editor -> isEditing(tbt_file)) {
+				// this file is already opened
+				already_opened_in_existing_tbt_editor = true;
+				tbt_editor -> setVisible(true);
+				tbt_editor -> raise();
+				tbt_editor -> activateWindow();
+				break;
+			}
+		}
+		if (!already_opened_in_existing_tbt_editor) {
+			// this file is not opened yet
+			openTitleBlockTemplate(tbt_file);
+		}
+	}
+}
+
+/**
 	Permet a l'utilisateur de configurer QET en lancant un dialogue approprie.
 	@see ConfigDialog
 */

Modified: branches/0.3/sources/qetapp.h
===================================================================
--- branches/0.3/sources/qetapp.h	2012-04-09 11:55:30 UTC (rev 1645)
+++ branches/0.3/sources/qetapp.h	2012-04-09 15:27:15 UTC (rev 1646)
@@ -203,6 +203,7 @@
 	void openElementLocations(const QList<ElementsLocation> &);
 	void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool = false);
 	void openTitleBlockTemplate(const QString &);
+	void openTitleBlockTemplateFiles(const QStringList &);
 	void configureQET();
 	void aboutQET();
 	

Modified: branches/0.3/sources/qetarguments.cpp
===================================================================
--- branches/0.3/sources/qetarguments.cpp	2012-04-09 11:55:30 UTC (rev 1645)
+++ branches/0.3/sources/qetarguments.cpp	2012-04-09 15:27:15 UTC (rev 1646)
@@ -16,6 +16,7 @@
 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "qetarguments.h"
+#include "titleblock/templatescollection.h"
 
 /**
 	Constructeur par defaut
@@ -51,6 +52,7 @@
 	QObject(qet_arguments.parent()),
 	project_files_(qet_arguments.project_files_),
 	element_files_(qet_arguments.element_files_),
+	tbt_files_(qet_arguments.tbt_files_),
 	options_(qet_arguments.options_),
 	unknown_options_(qet_arguments.unknown_options_),
 #ifdef QET_ALLOW_OVERRIDE_CED_OPTION
@@ -76,6 +78,7 @@
 QETArguments &QETArguments::operator=(const QETArguments &qet_arguments) {
 	project_files_   = qet_arguments.project_files_;
 	element_files_   = qet_arguments.element_files_;
+	tbt_files_       = qet_arguments.tbt_files_;
 	options_         = qet_arguments.options_;
 	unknown_options_ = qet_arguments.unknown_options_;
 #ifdef QET_ALLOW_OVERRIDE_CED_OPTION
@@ -115,7 +118,7 @@
 	projet puis element.
 */
 QList<QString> QETArguments::arguments() const {
-	return(options_ + unknown_options_ + project_files_ + element_files_);
+	return(options_ + unknown_options_ + project_files_ + element_files_ + tbt_files_);
 }
 
 /**
@@ -123,7 +126,7 @@
 	Les fichiers de type projet viennent avant les fichiers de type element.
 */
 QList<QString> QETArguments::files() const {
-	return(project_files_ + element_files_);
+	return(project_files_ + element_files_ + tbt_files_);
 }
 
 /**
@@ -141,6 +144,13 @@
 }
 
 /**
+	@return title block template files
+*/
+QList<QString> QETArguments::titleBlockTemplateFiles() const {
+	return(tbt_files_);
+}
+
+/**
 	@return les options reconnues
 */
 QList<QString> QETArguments::options() const {
@@ -203,6 +213,10 @@
 		if (!element_files_.contains(file)) {
 			element_files_ << file;
 		}
+	} else if (file.endsWith(TITLEBLOCKS_FILE_EXTENSION)) {
+		if (!tbt_files_.contains(file)) {
+			tbt_files_ << file;
+		}
 	} else {
 		if (!project_files_.contains(file)) {
 			project_files_ << file;

Modified: branches/0.3/sources/qetarguments.h
===================================================================
--- branches/0.3/sources/qetarguments.h	2012-04-09 11:55:30 UTC (rev 1645)
+++ branches/0.3/sources/qetarguments.h	2012-04-09 15:27:15 UTC (rev 1646)
@@ -42,6 +42,7 @@
 	virtual QList<QString> files() const;
 	virtual QList<QString> projectFiles() const;
 	virtual QList<QString> elementFiles() const;
+	virtual QList<QString> titleBlockTemplateFiles() const;
 #ifdef QET_ALLOW_OVERRIDE_CED_OPTION
 	virtual bool commonElementsDirSpecified() const;
 	virtual QString commonElementsDir() const;
@@ -72,6 +73,7 @@
 	private:
 	QList<QString> project_files_;
 	QList<QString> element_files_;
+	QList<QString> tbt_files_;
 	QList<QString> options_;
 	QList<QString> unknown_options_;
 #ifdef QET_ALLOW_OVERRIDE_CED_OPTION

Modified: branches/0.3/sources/titleblock/qettemplateeditor.cpp
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-04-09 11:55:30 UTC (rev 1645)
+++ branches/0.3/sources/titleblock/qettemplateeditor.cpp	2012-04-09 15:27:15 UTC (rev 1646)
@@ -61,6 +61,26 @@
 }
 
 /**
+	@return true if the provided filepath matches the currently edited template.
+	@param filepath path of a title block template on the filesystem
+*/
+bool QETTitleBlockTemplateEditor::isEditing(const QString &filepath) {
+	QString current_filepath;
+	if (opened_from_file_) {
+		current_filepath = filepath_;
+	} else {
+		current_filepath = QETApp::realPath(location_.toString());
+	}
+	
+	return(
+		QET::compareCanonicalFilePaths(
+			current_filepath,
+			filepath
+		)
+	);
+}
+
+/**
 	@param true for this editor to prompt the user for a new template name as
 	soon as the window appears in order to duplicate the edited one.
 */

Modified: branches/0.3/sources/titleblock/qettemplateeditor.h
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.h	2012-04-09 11:55:30 UTC (rev 1645)
+++ branches/0.3/sources/titleblock/qettemplateeditor.h	2012-04-09 15:27:15 UTC (rev 1646)
@@ -84,6 +84,7 @@
 	// methods
 	public:
 	TitleBlockTemplateLocation location() const;
+	bool isEditing(const QString &ilepath);
 	void setOpenForDuplication(bool);
 	bool openForDuplication() const;
 	


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