mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 23:20:52 +01:00
Gestion des categories sous forme de dossiers, deuxieme partie
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@20 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
46
qetapp.cpp
46
qetapp.cpp
@@ -840,7 +840,7 @@ void QETApp::slot_updateMenuFenetres() {
|
||||
@return Le chemin du dossier des elements communs
|
||||
*/
|
||||
QString QETApp::commonElementsDir() {
|
||||
return(QDir::current().path() + "/elements/");
|
||||
return(QDir::current().path() + QDir::separator() + "elements" + QDir::separator());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -850,11 +850,7 @@ QString QETApp::commonElementsDir() {
|
||||
@return Le chemin du dossier des elements persos
|
||||
*/
|
||||
QString QETApp::customElementsDir() {
|
||||
#ifdef Q_OS_WIN32
|
||||
return(QETApp::configDir() + "elements\\");
|
||||
#else
|
||||
return(QETApp::configDir() + "elements/");
|
||||
#endif
|
||||
return(QETApp::configDir() + "elements" + QDir::separator());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -872,3 +868,41 @@ QString QETApp::configDir() {
|
||||
return(QDir::homePath() + "/.qet/");
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de connaitre le chemin absolu du fichier *.elmt correspondant a un
|
||||
chemin symbolique (du type custom://outils_pervers/sado_maso/contact_bizarre)
|
||||
@param sym_path Chaine de caracteres representant le chemin absolu du fichier
|
||||
@return Une chaine de caracteres vide en cas d'erreur ou le chemin absolu du
|
||||
fichier *.elmt.
|
||||
*/
|
||||
QString QETApp::realPath(QString &sym_path) {
|
||||
QString directory;
|
||||
if (sym_path.startsWith("common://")) {
|
||||
directory = commonElementsDir();
|
||||
} else if (sym_path.startsWith("custom://")) {
|
||||
directory = customElementsDir();
|
||||
} else return(QString());
|
||||
return(directory + QDir::toNativeSeparators(sym_path.right(sym_path.length() - 9)));
|
||||
}
|
||||
|
||||
/**
|
||||
Construit le chemin symbolique (du type custom://outils_pervers/sado_maso/
|
||||
contact_bizarre) correspondant a un fichier.
|
||||
@param real_pathChaine de caracteres representant le chemin symbolique du fichier
|
||||
@return Une chaine de caracteres vide en cas d'erreur ou le chemin
|
||||
symbolique designant l'element.
|
||||
*/
|
||||
QString QETApp::symbolicPath(QString &real_path) {
|
||||
// recupere les dossier common et custom
|
||||
QString commond = commonElementsDir();
|
||||
QString customd = customElementsDir();
|
||||
QString chemin;
|
||||
// analyse le chemin de fichier passe en parametre
|
||||
if (real_path.startsWith(commond)) {
|
||||
chemin = "common://" + real_path.right(real_path.length() - commond.length());
|
||||
} else if (real_path.startsWith(customd)) {
|
||||
chemin = "custom://" + real_path.right(real_path.length() - customd.length());
|
||||
} else chemin = QString();
|
||||
return(chemin);
|
||||
}
|
||||
|
||||
2
qetapp.h
2
qetapp.h
@@ -19,6 +19,8 @@
|
||||
static QString commonElementsDir();
|
||||
static QString customElementsDir();
|
||||
static QString configDir();
|
||||
static QString realPath(QString &);
|
||||
static QString symbolicPath(QString &);
|
||||
public slots:
|
||||
void systray(QSystemTrayIcon::ActivationReason raison);
|
||||
void systrayReduire();
|
||||
|
||||
@@ -145,9 +145,8 @@ QDomDocument Schema::toXml(bool schema) {
|
||||
|
||||
// type
|
||||
QString chemin_elmt = elmt -> typeId();
|
||||
QString type_elmt = QString("");
|
||||
if (QFileInfo(chemin_elmt).dir() == dossier_elmts_persos) type_elmt = "perso://";
|
||||
element.setAttribute("type", type_elmt + QFileInfo(chemin_elmt).fileName());
|
||||
QString type_elmt = QETApp::symbolicPath(chemin_elmt);
|
||||
element.setAttribute("type", type_elmt);
|
||||
|
||||
// position, selection et orientation
|
||||
element.setAttribute("x", elmt -> pos().x());
|
||||
@@ -300,9 +299,7 @@ bool Schema::fromXml(QDomDocument &document, QPointF position) {
|
||||
Element *Schema::elementFromXml(QDomElement &e, QHash<int, Borne *> &table_id_adr) {
|
||||
// cree un element dont le type correspond à l'id type
|
||||
QString type = e.attribute("type");
|
||||
QString chemin_fichier;
|
||||
if (type.startsWith("perso://")) chemin_fichier = QETApp::customElementsDir() + type.right(type.size()-8);
|
||||
else chemin_fichier = QETApp::commonElementsDir() + type;
|
||||
QString chemin_fichier = QETApp::realPath(type);
|
||||
int etat;
|
||||
Element *nvel_elmt = new ElementPerso(chemin_fichier, 0, 0, &etat);
|
||||
if (etat != 0) return(false);
|
||||
|
||||
Reference in New Issue
Block a user