diff --git a/sources/ElementsCollection/elementscollectionmodel.cpp b/sources/ElementsCollection/elementscollectionmodel.cpp index 2663c008f..a55eb523e 100644 --- a/sources/ElementsCollection/elementscollectionmodel.cpp +++ b/sources/ElementsCollection/elementscollectionmodel.cpp @@ -264,10 +264,12 @@ bool ElementsCollectionModel::dropMimeData(const QMimeData *data, @param projects : list of projects to load */ void ElementsCollectionModel::loadCollections(bool common_collection, - bool company_collection, - bool custom_collection, - QList projects) + bool company_collection, + bool custom_collection, + QList projects) { + clear(); + m_items_list_to_setUp.clear(); if (common_collection) @@ -280,36 +282,64 @@ void ElementsCollectionModel::loadCollections(bool common_collection, if (common_collection || company_collection || custom_collection) m_items_list_to_setUp.append(items()); - for (QETProject *project : projects) { addProject(project, false); m_items_list_to_setUp.append(projectItems(project)); } + auto *watcher = new QFutureWatcher(); connect(watcher, &QFutureWatcher::progressValueChanged, - this, &ElementsCollectionModel::loadingProgressValueChanged); + this, &ElementsCollectionModel::loadingProgressValueChanged); connect(watcher, &QFutureWatcher::progressRangeChanged, - this, &ElementsCollectionModel::loadingProgressRangeChanged); + this, &ElementsCollectionModel::loadingProgressRangeChanged); connect(watcher, &QFutureWatcher::finished, - this, &ElementsCollectionModel::loadingFinished); - connect( - watcher, - &QFutureWatcher::finished, - watcher, - &QFutureWatcher::deleteLater); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove + this, &ElementsCollectionModel::loadingFinished); + connect(watcher, &QFutureWatcher::finished, watcher, &QFutureWatcher::deleteLater); + + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) m_future = QtConcurrent::map(m_items_list_to_setUp, setUpData); -#else -# if TODO_LIST -# pragma message("@TODO remove code for QT 6 or later") -# endif - qDebug() << "Help code for QT 6 or later" - << "QtConcurrent::run its backwards now...function, object, args"; -#endif + #else + qDebug() << "Help code for QT 6 or later"; + #endif watcher->setFuture(m_future); } +/** + * @brief ElementsCollectionModel::loadMacrosCollection + * Load the macros collection synchronously to avoid thread-collisions. + */ +void ElementsCollectionModel::loadMacrosCollection() +{ + m_items_list_to_setUp.clear(); + addMacrosCollection(true); +} + +/** + * @brief ElementsCollectionModel::addMacrosCollection + * Add the user macros collection to this model + * @param set_data + */ +void ElementsCollectionModel::addMacrosCollection(bool set_data) +{ + QString macrosPath = QETApp::userMacrosDir(); + qDebug() << "=== MAKRO PFAD CHECK ===" << macrosPath; + if (macrosPath.endsWith("/")) { + macrosPath.remove(macrosPath.length() - 1, 1); + } + + FileElementCollectionItem *feci = new FileElementCollectionItem(); + if (feci->setRootPath(macrosPath, + set_data, + m_hide_element)) { + invisibleRootItem()->appendRow(feci); + if (set_data) + feci->setUpData(); + } + else + delete feci; +} + /** @brief ElementsCollectionModel::addCommonCollection Add the common elements collection to this model @@ -368,11 +398,11 @@ void ElementsCollectionModel::addCustomCollection(bool set_data) } /** - @brief ElementsCollectionModel::addLocation - Add the element or directory to this model. - If the location is already managed by this model, do nothing. - @param location -*/ + * @brief ElementsCollectionModel::addLocation + * Add the element or directory to this model. + * If the location is already managed by this model, do nothing. + * @param location + */ void ElementsCollectionModel::addLocation(const ElementsLocation& location) { QModelIndex index = indexFromLocation(location); @@ -387,14 +417,15 @@ void ElementsCollectionModel::addLocation(const ElementsLocation& location) if (project) { XmlProjectElementCollectionItem *xpeci = - m_project_hash.value(project); + m_project_hash.value(project); last_item = xpeci->lastItemForPath( - location.collectionPath(false), - collection_name); + location.collectionPath(false), + collection_name); } } - else if (location.isCustomCollection()) { + // ANPASSUNG: Makros und Custom Collection werden hier behandelt! + else if (location.isCustomCollection() || location.isMacrosCollection()) { QList child_list; for (int i=0 ; itype() == FileElementCollectionItem::Type) { FileElementCollectionItem *feci = - static_cast(eci); + static_cast(eci); + + // Wir prüfen explizit, ob es Custom ODER Macros ist, und weisen es richtig zu. + if ((location.isCustomCollection() && feci->isCustomCollection()) || + (location.isMacrosCollection() && feci->isMacrosCollection())) { - if (feci->isCustomCollection()) { last_item = feci->lastItemForPath( - location.collectionPath(false), - collection_name); + location.collectionPath(false), + collection_name); if(last_item) break; - } + } } } } @@ -574,14 +608,14 @@ void ElementsCollectionModel::hideElement() } /** - @brief ElementsCollectionModel::indexFromLocation - Return the index who represent location. - Index can be non valid - @param location - @return -*/ + * @brief ElementsCollectionModel::indexFromLocation + * Return the index who represent location. + * Index can be non valid + * @param location + * @return + */ QModelIndex ElementsCollectionModel::indexFromLocation( - const ElementsLocation &location) + const ElementsLocation &location) { QList child_list; @@ -589,30 +623,34 @@ QModelIndex ElementsCollectionModel::indexFromLocation( child_list.append(static_cast(item(i))); } - foreach(ElementCollectionItem *eci, child_list) { + foreach(ElementCollectionItem *eci, child_list) { - ElementCollectionItem *match_eci = nullptr; + ElementCollectionItem *match_eci = nullptr; - if (eci->type() == FileElementCollectionItem::Type) { - if (FileElementCollectionItem *feci = static_cast(eci)) { - if ( (location.isCommonCollection() && feci->isCommonCollection()) || - (location.isCompanyCollection() && feci->isCompanyCollection()) || - (location.isCustomCollection() && !feci->isCommonCollection()) ) { - match_eci = feci->itemAtPath(location.collectionPath(false)); + if (eci->type() == FileElementCollectionItem::Type) { + if (FileElementCollectionItem *feci = static_cast(eci)) { + + // ANPASSUNG: Makro-Prüfung hinzugefügt, damit das Modell den Pfad im Baum findet! + if ( (location.isCommonCollection() && feci->isCommonCollection()) || + (location.isCompanyCollection() && feci->isCompanyCollection()) || + (location.isMacrosCollection() && feci->isMacrosCollection()) || + (location.isCustomCollection() && feci->isCustomCollection()) ) { + + match_eci = feci->itemAtPath(location.collectionPath(false)); } - } } - else if (eci->type() == XmlProjectElementCollectionItem::Type) { - if (XmlProjectElementCollectionItem *xpeci = static_cast(eci)) { - match_eci = xpeci->itemAtPath(location.collectionPath(false)); - } + } + else if (eci->type() == XmlProjectElementCollectionItem::Type) { + if (XmlProjectElementCollectionItem *xpeci = static_cast(eci)) { + match_eci = xpeci->itemAtPath(location.collectionPath(false)); } - - if (match_eci) - return indexFromItem(match_eci); } - return QModelIndex(); + if (match_eci) + return indexFromItem(match_eci); + } + + return QModelIndex(); } /** diff --git a/sources/ElementsCollection/elementscollectionmodel.h b/sources/ElementsCollection/elementscollectionmodel.h index d6652f9df..1bf12e66e 100644 --- a/sources/ElementsCollection/elementscollectionmodel.h +++ b/sources/ElementsCollection/elementscollectionmodel.h @@ -47,6 +47,8 @@ class ElementsCollectionModel : public QStandardItemModel void addCommonCollection(bool set_data = true); void addCompanyCollection(bool set_data = true); void addCustomCollection(bool set_data = true); + void addMacrosCollection(bool set_data = true); + void loadMacrosCollection(); void addLocation(const ElementsLocation& location); void addProject(QETProject *project, bool set_data = true); diff --git a/sources/ElementsCollection/elementscollectionwidget.cpp b/sources/ElementsCollection/elementscollectionwidget.cpp index 56d793463..a4c61a78b 100644 --- a/sources/ElementsCollection/elementscollectionwidget.cpp +++ b/sources/ElementsCollection/elementscollectionwidget.cpp @@ -176,16 +176,14 @@ void ElementsCollectionWidget::setUpAction() */ void ElementsCollectionWidget::setUpWidget() { - //Setup the main layout m_main_vlayout = new QVBoxLayout(this); - this->setLayout(m_main_vlayout); + m_main_vlayout->setContentsMargins(0, 0, 0, 0); + m_main_vlayout->setSpacing(2); m_search_field = new QLineEdit(this); - m_search_field->setPlaceholderText(tr("Rechercher")); + m_search_field->setPlaceholderText(tr("Rechercher...")); m_search_field->setClearButtonEnabled(true); - m_main_vlayout->addWidget(m_search_field); - //Setup the tree view m_tree_view = new ElementsTreeView(this); m_tree_view->setHeaderHidden(true); m_tree_view->setIconSize(QSize(50, 50)); @@ -195,12 +193,29 @@ void ElementsCollectionWidget::setUpWidget() m_tree_view->setAnimated(true); m_tree_view->setMouseTracking(true); m_tree_view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); - m_main_vlayout->addWidget(m_tree_view); - //Setup the progress bar + //Setup the macros tree view (DEV) + m_macros_tree_view = new ElementsTreeView(this); + m_macros_tree_view->setHeaderHidden(true); + m_macros_tree_view->setIconSize(QSize(50, 50)); + m_macros_tree_view->setDragDropMode(QAbstractItemView::DragDrop); + m_macros_tree_view->setContextMenuPolicy(Qt::CustomContextMenu); + m_macros_tree_view->setAutoExpandDelay(500); + m_macros_tree_view->setAnimated(true); + m_macros_tree_view->setMouseTracking(true); + m_macros_tree_view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); + + m_tab_widget = new QTabWidget(this); + m_tab_widget->setDocumentMode(true); + m_tab_widget->setTabPosition(QTabWidget::North); + m_tab_widget->addTab(m_tree_view, tr("Collections")); + m_tab_widget->addTab(m_macros_tree_view, tr("Modèles (DEV)")); + + m_main_vlayout->addWidget(m_search_field); + m_main_vlayout->addWidget(m_tab_widget); + m_progress_bar = new QProgressBar(this); m_progress_bar->setFormat(QObject::tr("chargement %p% (%v sur %m)")); - m_main_vlayout->addWidget(m_progress_bar); m_progress_bar->hide(); @@ -256,22 +271,43 @@ void ElementsCollectionWidget::setUpConnection() if (qde && eci) qde->statusBar()->showMessage(eci->localName()); }); + + connect(m_macros_tree_view, &QTreeView::customContextMenuRequested, + this, &ElementsCollectionWidget::customContextMenu); + + connect(m_macros_tree_view, &QTreeView::doubleClicked, + [this](const QModelIndex &index) + { + this->m_index_at_context_menu = index ; + this->editElement(); + }); + + connect(m_macros_tree_view, &QTreeView::entered, + [this] (const QModelIndex &index) { + QETDiagramEditor *qde = QETApp::diagramEditorAncestorOf(this); + ElementCollectionItem *eci = elementCollectionItemForIndex(index); + if (qde && eci) + qde->statusBar()->showMessage(eci->localName()); + }); } /** - @brief ElementsCollectionWidget::customContextMenu - Display the context menu of this widget at point - @param point -*/ + * @brief ElementsCollectionWidget::customContextMenu + * Display the context menu of this widget at point + * @param point + */ void ElementsCollectionWidget::customContextMenu(const QPoint &point) { - m_index_at_context_menu = m_tree_view->indexAt(point); + QTreeView *clicked_tree = qobject_cast(sender()); + if (!clicked_tree) clicked_tree = m_tree_view; // Fallback + + m_index_at_context_menu = clicked_tree->indexAt(point); if (!m_index_at_context_menu.isValid()) return; m_context_menu->clear(); ElementCollectionItem *eci = elementCollectionItemForIndex( - m_index_at_context_menu); + m_index_at_context_menu); bool add_open_dir = false; if (eci->isElement()) @@ -281,12 +317,14 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point) { add_open_dir = true; FileElementCollectionItem *feci = - static_cast(eci); + static_cast(eci); if (!feci->isCommonCollection()) { if (feci->isDir()) { - m_context_menu->addAction(m_new_element); + if (!feci->isMacrosCollection()) { + m_context_menu->addAction(m_new_element); + } m_context_menu->addAction(m_new_directory); if (!feci->isCollectionRoot()) { @@ -301,7 +339,7 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point) if (eci->type() == XmlProjectElementCollectionItem::Type) { XmlProjectElementCollectionItem *xpeci = - static_cast(eci); + static_cast(eci); if (xpeci->isCollectionRoot()) add_open_dir = true; } @@ -320,7 +358,7 @@ void ElementsCollectionWidget::customContextMenu(const QPoint &point) m_context_menu->addAction(m_open_dir); m_context_menu->addAction(m_reload); - m_context_menu->popup(mapToGlobal(m_tree_view->mapToParent(point))); + m_context_menu->popup(mapToGlobal(clicked_tree->mapToParent(point))); } /** @@ -400,9 +438,10 @@ void ElementsCollectionWidget::deleteElement() QFile file(loc.fileSystemPath()); if (file.remove()) { - m_model->removeRows(m_index_at_context_menu.row(), - 1, - m_index_at_context_menu.parent()); + QAbstractItemModel *clicked_model = const_cast(m_index_at_context_menu.model()); + if (clicked_model) { + clicked_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent()); + } } else { @@ -445,9 +484,10 @@ void ElementsCollectionWidget::deleteDirectory() QDir dir (loc.fileSystemPath()); if (dir.removeRecursively()) { - m_model->removeRows(m_index_at_context_menu.row(), - 1, - m_index_at_context_menu.parent()); + QAbstractItemModel *clicked_model = const_cast(m_index_at_context_menu.model()); + if (clicked_model) { + clicked_model->removeRows(m_index_at_context_menu.row(), 1, m_index_at_context_menu.parent()); + } } else { @@ -489,19 +529,29 @@ void ElementsCollectionWidget::editDirectory() */ void ElementsCollectionWidget::newDirectory() { - ElementCollectionItem *eci = elementCollectionItemForIndex( - m_index_at_context_menu); + ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu); - if (eci->type() != FileElementCollectionItem::Type) return; + if (!eci || eci->type() != FileElementCollectionItem::Type) return; - FileElementCollectionItem *feci = - static_cast(eci); + FileElementCollectionItem *feci = static_cast(eci); if(feci->isCommonCollection()) return; ElementsLocation location(feci->collectionPath()); ElementsCategoryEditor new_dir_editor(location, false, this); - if (new_dir_editor.exec() == QDialog::Accepted) - m_model->addLocation(new_dir_editor.createdLocation()); + + if (new_dir_editor.exec() == QDialog::Accepted) { + ElementsLocation new_loc = new_dir_editor.createdLocation(); + + if (new_loc.isMacrosCollection()) { + if (m_macros_model) { + m_macros_model->addLocation(new_loc); + } + } else { + if (m_model) { + m_model->addLocation(new_loc); + } + } + } } /** @@ -662,12 +712,19 @@ void ElementsCollectionWidget::reload() &ElementsCollectionWidget::loadingFinished); m_new_model->loadCollections(true, true, true, project_list); + + if (m_macros_model) { + m_macros_model->deleteLater(); + } + m_macros_model = new ElementsCollectionModel(m_macros_tree_view); + m_macros_tree_view->setModel(m_macros_model); + m_macros_model->loadMacrosCollection(); } /** - @brief ElementsCollectionWidget::loadingFinished - Process when collection finished to be loaded -*/ + * @brief ElementsCollectionWidget::loadingFinished + * Process when collection finished to be loaded + */ void ElementsCollectionWidget::loadingFinished() { if (m_new_model) @@ -842,15 +899,21 @@ void ElementsCollectionWidget::showAndExpandItem(const QModelIndex &index, } /** - @brief ElementsCollectionWidget::elementCollectionItemForIndex - @param index - @return The internal pointer of index casted to ElementCollectionItem; -*/ -ElementCollectionItem *ElementsCollectionWidget::elementCollectionItemForIndex( - const QModelIndex &index) { - if (!index.isValid()) - return nullptr; + * @brief ElementsCollectionWidget::elementCollectionItemForIndex + * @param index + * @return The internal pointer of index casted to ElementCollectionItem; + */ +ElementCollectionItem *ElementsCollectionWidget::elementCollectionItemForIndex(const QModelIndex &index) +{ + if (!index.isValid()) return nullptr; - return static_cast( - m_model->itemFromIndex(index)); + if (m_macros_model && index.model() == m_macros_model) { + return static_cast(m_macros_model->itemFromIndex(index)); + } + + if (m_model && index.model() == m_model) { + return static_cast(m_model->itemFromIndex(index)); + } + + return nullptr; } diff --git a/sources/ElementsCollection/elementscollectionwidget.h b/sources/ElementsCollection/elementscollectionwidget.h index 4a5fe4071..a8294ec78 100644 --- a/sources/ElementsCollection/elementscollectionwidget.h +++ b/sources/ElementsCollection/elementscollectionwidget.h @@ -25,6 +25,8 @@ #include #include #include +#include +#include class ElementsCollectionModel; class QVBoxLayout; @@ -90,9 +92,12 @@ class ElementsCollectionWidget : public QWidget private: ElementsCollectionModel *m_model = nullptr; ElementsCollectionModel *m_new_model = nullptr; + ElementsCollectionModel *m_macros_model = nullptr; QLineEdit *m_search_field; QTimer m_search_timer; ElementsTreeView *m_tree_view; + ElementsTreeView *m_macros_tree_view = nullptr; + QTabWidget *m_tab_widget = nullptr; QVBoxLayout *m_main_vlayout; QMenu *m_context_menu; QModelIndex m_index_at_context_menu; diff --git a/sources/ElementsCollection/elementslocation.cpp b/sources/ElementsCollection/elementslocation.cpp index f236d9edb..2f2f810fe 100644 --- a/sources/ElementsCollection/elementslocation.cpp +++ b/sources/ElementsCollection/elementslocation.cpp @@ -181,7 +181,7 @@ QString ElementsLocation::collectionPath(bool protocol) const else { QString path = m_collection_path; - return path.remove(QRegularExpression("common://|company://|custom://|embed://")); + return path.remove(QRegularExpression("common://|company://|custom://|macros://|embed://")); } } @@ -232,54 +232,34 @@ QString ElementsLocation::path() const (start by common://, company://, custom:// or embed://) or not. @param path */ + void ElementsLocation::setPath(const QString &path) { QString tmp_path = path; -#ifdef Q_OS_WIN32 - //On windows, we convert backslash to slash + #ifdef Q_OS_WIN32 tmp_path = QDir::fromNativeSeparators(path); + #endif -#endif + QString macrosPath = QETApp::userMacrosDir(); + if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1); - //There is a project, the path is for an embedded coolection. if (m_project) { m_collection_path = path; - //Add the protocol to the collection path if (!path.startsWith("embed://")) m_collection_path.prepend("embed://"); - } - - //The path start with project, we get the project and the path from the string else if (tmp_path.startsWith("project")) { - QRegularExpression re - ("^project(?[0-9])\\+(?embed://*.*)$"); - if (!re.isValid()) - { - qWarning() <[0-9])\\+(?embed://*.*)$"); + if (!re.isValid()) return; QRegularExpressionMatch match = re.match(tmp_path); - if (!match.hasMatch()) - { - qDebug()<<"no Match => return" - <type() - == FileElementCollectionItem::Type) { + == FileElementCollectionItem::Type) { ElementCollectionItem *eci = - static_cast(parent()); - if (eci->isCollectionRoot()) - return eci->collectionPath() + m_path; + static_cast(parent()); + if (eci->isCollectionRoot()) + return eci->collectionPath() + m_path; else return eci->collectionPath() % "/" % m_path; - } - else - return QString(); + } + else + return QString(); } /** @@ -220,10 +231,14 @@ QString FileElementCollectionItem::collectionPath() const */ bool FileElementCollectionItem::isCollectionRoot() const { + QString macrosPath = QETApp::userMacrosDir(); + if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1); + if (m_path == QETApp::commonElementsDirN() - || m_path == QETApp::companyElementsDirN() - || m_path == QETApp::customElementsDirN()) - return true; + || m_path == QETApp::companyElementsDirN() + || m_path == QETApp::customElementsDirN() + || m_path == macrosPath) // <-- NEU: Makros sind jetzt ein echtes Root-Verzeichnis + return true; else return false; } @@ -318,12 +333,17 @@ void FileElementCollectionItem::setUpIcon() return; if (isCollectionRoot()) { + QString macrosPath = QETApp::userMacrosDir(); + if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1); + if (m_path == QETApp::commonElementsDirN()) setIcon(QIcon(":/ico/16x16/qet.png")); else if (m_path == QETApp::companyElementsDirN()) setIcon(QIcon(":/ico/16x16/go-company.png")); - else - setIcon(QIcon(":/ico/16x16/go-home.png")); + else if (m_path == macrosPath) + setIcon(QIcon(":/ico/16x16/go-home.png")); // <-- NEU: Icon für Makros (z.B. go-home) + else + setIcon(QIcon(":/ico/16x16/go-home.png")); } else { @@ -393,3 +413,15 @@ void FileElementCollectionItem::populate(bool set_data, bool hide_element) feci->setUpData(); } } + +/** + * @brief FileElementCollectionItem::isMacrosCollection + * @return True if this item represent the macros collection + */ +bool FileElementCollectionItem::isMacrosCollection() const +{ + QString macrosPath = QETApp::userMacrosDir(); + if (macrosPath.endsWith("/")) macrosPath.remove(macrosPath.length() - 1, 1); + + return fileSystemPath().startsWith(macrosPath); +} diff --git a/sources/ElementsCollection/fileelementcollectionitem.h b/sources/ElementsCollection/fileelementcollectionitem.h index ae023fb7e..d2c735d72 100644 --- a/sources/ElementsCollection/fileelementcollectionitem.h +++ b/sources/ElementsCollection/fileelementcollectionitem.h @@ -50,6 +50,7 @@ class FileElementCollectionItem : public ElementCollectionItem bool isCommonCollection() const; bool isCompanyCollection() const; bool isCustomCollection() const; + bool isMacrosCollection() const; void addChildAtPath(const QString &collection_name) override; void setUpData() override; diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index f4e14ad57..aaa462fc5 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -91,6 +91,8 @@ QString QETApp::m_user_company_tbt_dir = QString(); QString QETApp::m_user_custom_tbt_dir = QString(); +QString QETApp::m_user_macros_dir = QString(); + QETApp *QETApp::m_qetapp = nullptr; bool lang_is_set = false; @@ -724,6 +726,8 @@ void QETApp::resetCollectionsPath() m_user_company_tbt_dir.clear(); m_user_custom_tbt_dir.clear(); + + m_user_macros_dir.clear(); } /** @@ -822,6 +826,38 @@ QString QETApp::customTitleBlockTemplatesDir() return(dataDir() + "/titleblocks/"); } +/** + * @brief QETApp::userMacrosDir + * @return the path of the directory containing the user macros collection. + */ +QString QETApp::userMacrosDir() +{ + if (m_user_macros_dir.isEmpty()) + { + QSettings settings; + QString path = settings.value( + "elements-collections/macros-path", + "default").toString(); + if (path != "default" && !path.isEmpty()) + { + QDir dir(path); + if (dir.exists()) + { + m_user_macros_dir = path; + return m_user_macros_dir; + } + } + else { + m_user_macros_dir = "default"; + } + } + else if (m_user_macros_dir != "default") { + return m_user_macros_dir; + } + + return(dataDir() + "/macros/"); +} + /** @brief QETApp::configDir Return the QET configuration folder, i.e. the path to the folder in @@ -938,6 +974,8 @@ QString QETApp::realPath(const QString &sym_path) { directory = commonElementsDir(); } else if (sym_path.startsWith("company://")) { directory = companyElementsDir(); + } else if (sym_path.startsWith("macros://")) { + directory = userMacrosDir(); } else if (sym_path.startsWith("company://")) { directory = companyElementsDir(); } else if (sym_path.startsWith("custom://")) { @@ -976,6 +1014,7 @@ QString QETApp::symbolicPath(const QString &real_path) { QString commond = commonElementsDir(); QString companyd = companyElementsDir(); QString customd = customElementsDir(); + QString macrosd = userMacrosDir(); QString chemin; // analyzes the file path passed in parameter // analyse le chemin de fichier passe en parametre @@ -987,6 +1026,10 @@ QString QETApp::symbolicPath(const QString &real_path) { chemin = "company://" + real_path.right( real_path.length() - companyd.length()); + } else if (real_path.startsWith(macrosd)) { + chemin = "macros://" + + real_path.right( + real_path.length() - macrosd.length()); } else if (real_path.startsWith(customd)) { chemin = "custom://" + real_path.right( @@ -2212,6 +2255,10 @@ void QETApp::initConfiguration() if (!custom_tbt_dir.exists()) custom_tbt_dir.mkpath(QETApp::customTitleBlockTemplatesDir()); + QDir macros_dir(QETApp::userMacrosDir()); + if (!macros_dir.exists()) + macros_dir.mkpath(QETApp::userMacrosDir()); + /* recent files * note: * icons must be initialized before these instructions diff --git a/sources/qetapp.h b/sources/qetapp.h index 59d10d3cd..2f4ecc363 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -91,6 +91,7 @@ class QETApp : public QObject static QString commonTitleBlockTemplatesDir(); static QString companyTitleBlockTemplatesDir(); static QString customTitleBlockTemplatesDir(); + static QString userMacrosDir(); static bool registerProject(QETProject *); static bool unregisterProject(QETProject *); static QMap registeredProjects(); @@ -242,7 +243,7 @@ class QETApp : public QObject static QString m_user_company_tbt_dir; static QString m_user_custom_tbt_dir; - + static QString m_user_macros_dir; public slots: void systray(QSystemTrayIcon::ActivationReason); diff --git a/sources/ui/configpage/generalconfigurationpage.cpp b/sources/ui/configpage/generalconfigurationpage.cpp index 00d62f57a..e050c5e45 100644 --- a/sources/ui/configpage/generalconfigurationpage.cpp +++ b/sources/ui/configpage/generalconfigurationpage.cpp @@ -177,6 +177,15 @@ GeneralConfigurationPage::GeneralConfigurationPage(QWidget *parent) : ui->m_custom_tbt_path_cb->blockSignals(false); } + path = settings.value("elements-collections/macros-path", "default").toString(); + if (path != "default") + { + ui->m_user_macros_path_cb->blockSignals(true); + ui->m_user_macros_path_cb->setCurrentIndex(1); + ui->m_user_macros_path_cb->setItemData(1, path, Qt::DisplayRole); + ui->m_user_macros_path_cb->blockSignals(false); + } + fillLang(); } @@ -321,6 +330,21 @@ void GeneralConfigurationPage::applyConf() if (path != settings.value("elements-collections/custom-tbt-path").toString()) { QETApp::resetCollectionsPath(); } + + path = settings.value("elements-collections/macros-path").toString(); + if (ui->m_user_macros_path_cb->currentIndex() == 1) + { + QString path = ui->m_user_macros_path_cb->currentText(); + QDir dir(path); + settings.setValue("elements-collections/macros-path", + dir.exists() ? path : "default"); + } + else { + settings.setValue("elements-collections/macros-path", "default"); + } + if (path != settings.value("elements-collections/macros-path").toString()) { + QETApp::resetCollectionsPath(); + } } /** @@ -512,6 +536,19 @@ void GeneralConfigurationPage::on_m_custom_tbt_path_cb_currentIndexChanged(int i } } +void GeneralConfigurationPage::on_m_user_macros_path_cb_currentIndexChanged(int index) +{ + if (index == 1) + { + QString path = QFileDialog::getExistingDirectory(this, tr("Chemin des macros utilisateur (DEV)"), QETApp::documentDir()); + if (!path.isEmpty()) { + ui->m_user_macros_path_cb->setItemData(1, path, Qt::DisplayRole); + } + else { + ui->m_user_macros_path_cb->setCurrentIndex(0); + } + } +} void GeneralConfigurationPage::on_m_indi_text_font_pb_clicked() { diff --git a/sources/ui/configpage/generalconfigurationpage.h b/sources/ui/configpage/generalconfigurationpage.h index ce85d8f82..ab55fdb79 100644 --- a/sources/ui/configpage/generalconfigurationpage.h +++ b/sources/ui/configpage/generalconfigurationpage.h @@ -46,6 +46,7 @@ class GeneralConfigurationPage : public ConfigPage void on_m_custom_elmt_path_cb_currentIndexChanged(int index); void on_m_company_tbt_path_cb_currentIndexChanged(int index); void on_m_custom_tbt_path_cb_currentIndexChanged(int index); + void on_m_user_macros_path_cb_currentIndexChanged(int index); void on_m_indi_text_font_pb_clicked(); void on_MaxPartsElementEditorList_sb_valueChanged(int value); void on_DiagramEditor_Grid_PointSize_min_sb_valueChanged(int value); diff --git a/sources/ui/configpage/generalconfigurationpage.ui b/sources/ui/configpage/generalconfigurationpage.ui index 38130c8b9..2e645d9c0 100644 --- a/sources/ui/configpage/generalconfigurationpage.ui +++ b/sources/ui/configpage/generalconfigurationpage.ui @@ -349,6 +349,27 @@ + + + + Macros utilisateur (DEV) + + + + + + + + Par defaut + + + + + Parcourir... + + + +