QElectroTech is now able to open .titleblock files passed as arguments to the program.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1646 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-04-09 15:27:15 +00:00
parent b8ae554310
commit 8ba02ef932
6 changed files with 81 additions and 3 deletions

View File

@@ -922,6 +922,7 @@ void QETApp::messageReceived(const QString &message) {
void QETApp::openFiles(const QETArguments &args) { void QETApp::openFiles(const QETArguments &args) {
openProjectFiles(args.projectFiles()); openProjectFiles(args.projectFiles());
openElementFiles(args.elementFiles()); openElementFiles(args.elementFiles());
openTitleBlockTemplateFiles(args.titleBlockTemplateFiles());
} }
/** /**
@@ -966,7 +967,7 @@ void QETApp::openProjectFiles(const QStringList &files_list) {
/** /**
Ouvre les fichiers elements passes en parametre. Si un element est deja 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 @param files_list Fichiers a ouvrir
*/ */
void QETApp::openElementFiles(const QStringList &files_list) { void QETApp::openElementFiles(const QStringList &files_list) {
@@ -1062,6 +1063,45 @@ void QETApp::openTitleBlockTemplate(const QString &filepath) {
qet_template_editor -> showMaximized(); qet_template_editor -> showMaximized();
} }
/**
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. Permet a l'utilisateur de configurer QET en lancant un dialogue approprie.
@see ConfigDialog @see ConfigDialog

View File

@@ -203,6 +203,7 @@ class QETApp : public QETSingleApplication {
void openElementLocations(const QList<ElementsLocation> &); void openElementLocations(const QList<ElementsLocation> &);
void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool = false); void openTitleBlockTemplate(const TitleBlockTemplateLocation &, bool = false);
void openTitleBlockTemplate(const QString &); void openTitleBlockTemplate(const QString &);
void openTitleBlockTemplateFiles(const QStringList &);
void configureQET(); void configureQET();
void aboutQET(); void aboutQET();

View File

@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>. along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "qetarguments.h" #include "qetarguments.h"
#include "titleblock/templatescollection.h"
/** /**
Constructeur par defaut Constructeur par defaut
@@ -51,6 +52,7 @@ QETArguments::QETArguments(const QETArguments &qet_arguments) :
QObject(qet_arguments.parent()), QObject(qet_arguments.parent()),
project_files_(qet_arguments.project_files_), project_files_(qet_arguments.project_files_),
element_files_(qet_arguments.element_files_), element_files_(qet_arguments.element_files_),
tbt_files_(qet_arguments.tbt_files_),
options_(qet_arguments.options_), options_(qet_arguments.options_),
unknown_options_(qet_arguments.unknown_options_), unknown_options_(qet_arguments.unknown_options_),
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION #ifdef QET_ALLOW_OVERRIDE_CED_OPTION
@@ -76,6 +78,7 @@ common_tbt_dir_(qet_arguments.common_tbt_dir_),
QETArguments &QETArguments::operator=(const QETArguments &qet_arguments) { QETArguments &QETArguments::operator=(const QETArguments &qet_arguments) {
project_files_ = qet_arguments.project_files_; project_files_ = qet_arguments.project_files_;
element_files_ = qet_arguments.element_files_; element_files_ = qet_arguments.element_files_;
tbt_files_ = qet_arguments.tbt_files_;
options_ = qet_arguments.options_; options_ = qet_arguments.options_;
unknown_options_ = qet_arguments.unknown_options_; unknown_options_ = qet_arguments.unknown_options_;
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION #ifdef QET_ALLOW_OVERRIDE_CED_OPTION
@@ -115,7 +118,7 @@ void QETArguments::setArguments(const QList<QString> &args) {
projet puis element. projet puis element.
*/ */
QList<QString> QETArguments::arguments() const { 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 @@ QList<QString> QETArguments::arguments() const {
Les fichiers de type projet viennent avant les fichiers de type element. Les fichiers de type projet viennent avant les fichiers de type element.
*/ */
QList<QString> QETArguments::files() const { QList<QString> QETArguments::files() const {
return(project_files_ + element_files_); return(project_files_ + element_files_ + tbt_files_);
} }
/** /**
@@ -140,6 +143,13 @@ QList<QString> QETArguments::elementFiles() const {
return(element_files_); return(element_files_);
} }
/**
@return title block template files
*/
QList<QString> QETArguments::titleBlockTemplateFiles() const {
return(tbt_files_);
}
/** /**
@return les options reconnues @return les options reconnues
*/ */
@@ -203,6 +213,10 @@ void QETArguments::handleFileArgument(const QString &file) {
if (!element_files_.contains(file)) { if (!element_files_.contains(file)) {
element_files_ << file; element_files_ << file;
} }
} else if (file.endsWith(TITLEBLOCKS_FILE_EXTENSION)) {
if (!tbt_files_.contains(file)) {
tbt_files_ << file;
}
} else { } else {
if (!project_files_.contains(file)) { if (!project_files_.contains(file)) {
project_files_ << file; project_files_ << file;

View File

@@ -42,6 +42,7 @@ class QETArguments : public QObject {
virtual QList<QString> files() const; virtual QList<QString> files() const;
virtual QList<QString> projectFiles() const; virtual QList<QString> projectFiles() const;
virtual QList<QString> elementFiles() const; virtual QList<QString> elementFiles() const;
virtual QList<QString> titleBlockTemplateFiles() const;
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION #ifdef QET_ALLOW_OVERRIDE_CED_OPTION
virtual bool commonElementsDirSpecified() const; virtual bool commonElementsDirSpecified() const;
virtual QString commonElementsDir() const; virtual QString commonElementsDir() const;
@@ -72,6 +73,7 @@ class QETArguments : public QObject {
private: private:
QList<QString> project_files_; QList<QString> project_files_;
QList<QString> element_files_; QList<QString> element_files_;
QList<QString> tbt_files_;
QList<QString> options_; QList<QString> options_;
QList<QString> unknown_options_; QList<QString> unknown_options_;
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION #ifdef QET_ALLOW_OVERRIDE_CED_OPTION

View File

@@ -60,6 +60,26 @@ TitleBlockTemplateLocation QETTitleBlockTemplateEditor::location() const {
return(location_); return(location_);
} }
/**
@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 @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. soon as the window appears in order to duplicate the edited one.

View File

@@ -84,6 +84,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow {
// methods // methods
public: public:
TitleBlockTemplateLocation location() const; TitleBlockTemplateLocation location() const;
bool isEditing(const QString &ilepath);
void setOpenForDuplication(bool); void setOpenForDuplication(bool);
bool openForDuplication() const; bool openForDuplication() const;