diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index f459b9157..b6e13fd60 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -304,7 +304,7 @@ TitleBlockTemplatesFilesCollection *QETApp::commonTitleBlockTemplatesCollection( if (!common_tbt_collection_) { common_tbt_collection_ = new TitleBlockTemplatesFilesCollection(QETApp::commonTitleBlockTemplatesDir()); common_tbt_collection_ -> setTitle(tr("Cartouches QET", "title of the title block templates collection provided by QElectroTech")); - common_tbt_collection_ -> setProtocol("commontbt"); + common_tbt_collection_ -> setProtocol(QETAPP_COMMON_TBT_PROTOCOL); } return(common_tbt_collection_); } @@ -317,7 +317,7 @@ TitleBlockTemplatesFilesCollection *QETApp::customTitleBlockTemplatesCollection( if (!custom_tbt_collection_) { custom_tbt_collection_ = new TitleBlockTemplatesFilesCollection(QETApp::customTitleBlockTemplatesDir()); custom_tbt_collection_ -> setTitle(tr("Cartouches utilisateur", "title of the user's title block templates collection")); - custom_tbt_collection_ -> setProtocol("customtbt"); + custom_tbt_collection_ -> setProtocol(QETAPP_CUSTOM_TBT_PROTOCOL); } return(custom_tbt_collection_); } @@ -339,6 +339,24 @@ QList QETApp::availableTitleBlockTemplatesColle return(collections_list); } +/** + @param protocol Protocol string + @return the templates collection matching the provided protocol, or 0 if none could be found +*/ +TitleBlockTemplatesCollection *QETApp::titleBlockTemplatesCollection(const QString &protocol) { + if (protocol == QETAPP_COMMON_TBT_PROTOCOL) { + return(common_tbt_collection_); + } else if (protocol == QETAPP_CUSTOM_TBT_PROTOCOL) { + return(custom_tbt_collection_); + } else { + QETProject *project = QETApp::projectFromString(protocol); + if (project) { + return(project -> embeddedTitleBlockTemplatesCollection()); + } + } + return(0); +} + /** @return le nom de l'utilisateur courant */ @@ -452,9 +470,9 @@ QString QETApp::realPath(const QString &sym_path) { directory = commonElementsDir(); } else if (sym_path.startsWith("custom://")) { directory = customElementsDir(); - } else if (sym_path.startsWith("commontbt://")) { + } else if (sym_path.startsWith(QETAPP_COMMON_TBT_PROTOCOL "://")) { directory = commonTitleBlockTemplatesDir(); - } else if (sym_path.startsWith("customtbt://")) { + } else if (sym_path.startsWith(QETAPP_CUSTOM_TBT_PROTOCOL "://")) { directory = customTitleBlockTemplatesDir(); } else return(QString()); return(directory + QDir::toNativeSeparators(sym_path.right(sym_path.length() - 9))); @@ -1276,6 +1294,36 @@ template void QETApp::addWindowsListToMenu(QMenu *menu, const QList clear(); diff --git a/sources/qetapp.h b/sources/qetapp.h index 7a6c73fdb..e4101e5d5 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -23,6 +23,10 @@ #include "elementslocation.h" #include "templatelocation.h" #include "qetarguments.h" + +#define QETAPP_COMMON_TBT_PROTOCOL "commontbt" +#define QETAPP_CUSTOM_TBT_PROTOCOL "customtbt" + class AboutQET; class QETDiagramEditor; class QETElementEditor; @@ -39,6 +43,7 @@ class QETProject; class QETTitleBlockTemplateEditor; class QTextOrientationSpinBoxWidget; class RecentFiles; + /** Cette classe represente l'application QElectroTech. @@ -71,6 +76,7 @@ class QETApp : public QETSingleApplication { static TitleBlockTemplatesFilesCollection *commonTitleBlockTemplatesCollection(); static TitleBlockTemplatesFilesCollection *customTitleBlockTemplatesCollection(); static QList availableTitleBlockTemplatesCollections(); + static TitleBlockTemplatesCollection *titleBlockTemplatesCollection(const QString &); static QString userName(); static QString commonElementsDir(); @@ -220,6 +226,8 @@ class QETApp : public QETSingleApplication { const QList & ); template void addWindowsListToMenu(QMenu *, const QList &); + static int projectIdFromString(const QString &); + static QETProject *projectFromString(const QString &); }; /** diff --git a/sources/titleblock/templatelocation.cpp b/sources/titleblock/templatelocation.cpp index b4fa6f5d6..0ba42e192 100644 --- a/sources/titleblock/templatelocation.cpp +++ b/sources/titleblock/templatelocation.cpp @@ -36,6 +36,15 @@ TitleBlockTemplateLocation::TitleBlockTemplateLocation(const QString &name, Titl TitleBlockTemplateLocation::~TitleBlockTemplateLocation() { } +/** + @param loc_str String describing the location of a title block template. +*/ +TitleBlockTemplateLocation TitleBlockTemplateLocation::locationFromString(const QString &loc_str) { + TitleBlockTemplateLocation loc; + loc.fromString(loc_str); + return(loc); +} + /** @return the parent collection of the template, or 0 if none was defined */ @@ -72,6 +81,20 @@ bool TitleBlockTemplateLocation::isValid() const { return(!name_.isEmpty()); } +/** + @param loc_str String describing the location of a title block template. +*/ +void TitleBlockTemplateLocation::fromString(const QString &loc_str) { + collection_ = QETApp::titleBlockTemplatesCollection(QUrl(loc_str).scheme()); + + QRegExp name_from_url("^[^:]*:\\/\\/(.*)$"); + if (name_from_url.exactMatch(loc_str)) { + name_ = name_from_url.capturedTexts().at(1); + } else { + name_ = QString(); + } +} + /** @return A string representation of the location */ diff --git a/sources/titleblock/templatelocation.h b/sources/titleblock/templatelocation.h index 7a24612d9..d878b7bbd 100644 --- a/sources/titleblock/templatelocation.h +++ b/sources/titleblock/templatelocation.h @@ -31,6 +31,10 @@ class TitleBlockTemplateLocation { TitleBlockTemplateLocation(const QString & = QString(), TitleBlockTemplatesCollection * = 0); virtual ~TitleBlockTemplateLocation(); + // static methods + public: + TitleBlockTemplateLocation locationFromString(const QString &); + // methods public: TitleBlockTemplatesCollection *parentCollection() const; @@ -38,6 +42,7 @@ class TitleBlockTemplateLocation { QString name() const; void setName(const QString &); bool isValid() const; + void fromString(const QString &); QString toString() const; QETProject *parentProject() const; QString protocol() const;