mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Added API to get a valid TitleBlockTemplateLocation from a string.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1468 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
9c658d84b1
commit
aa0a83e0d6
@ -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<TitleBlockTemplatesCollection *> 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 <class T> void QETApp::addWindowsListToMenu(QMenu *menu, const QList<T
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@param url The location of a collection item (title block template,
|
||||
element, category, ...).
|
||||
@return the id of the project mentionned in the URL, or -1 if none could be
|
||||
found.
|
||||
*/
|
||||
int QETApp::projectIdFromString(const QString &url) {
|
||||
QRegExp embedded("^project([0-9]+)\\+embed.*$", Qt::CaseInsensitive);
|
||||
if (embedded.exactMatch(url)) {
|
||||
bool conv_ok = false;
|
||||
int project_id = embedded.capturedTexts().at(1).toInt(&conv_ok);
|
||||
if (conv_ok) {
|
||||
return(project_id);
|
||||
}
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
@param url The location of a collection item (title block template,
|
||||
element, category, ...).
|
||||
@return the project mentionned in the URL, or 0 if none could be
|
||||
found.
|
||||
*/
|
||||
QETProject *QETApp::projectFromString(const QString &url) {
|
||||
int project_id = projectIdFromString(url);
|
||||
if (project_id == -1) return(0);
|
||||
return(project(project_id));
|
||||
}
|
||||
|
||||
/// construit le menu de l'icone dans le systray
|
||||
void QETApp::buildSystemTrayMenu() {
|
||||
menu_systray -> clear();
|
||||
|
@ -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<TitleBlockTemplatesCollection *> availableTitleBlockTemplatesCollections();
|
||||
static TitleBlockTemplatesCollection *titleBlockTemplatesCollection(const QString &);
|
||||
|
||||
static QString userName();
|
||||
static QString commonElementsDir();
|
||||
@ -220,6 +226,8 @@ class QETApp : public QETSingleApplication {
|
||||
const QList<QETTitleBlockTemplateEditor *> &
|
||||
);
|
||||
template <class T> void addWindowsListToMenu(QMenu *, const QList<T *> &);
|
||||
static int projectIdFromString(const QString &);
|
||||
static QETProject *projectFromString(const QString &);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user