diff --git a/sources/elementscategorydeleter.cpp b/sources/elementscategorydeleter.cpp deleted file mode 100644 index edd29327d..000000000 --- a/sources/elementscategorydeleter.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - Copyright 2006-2016 The QElectroTech Team - This file is part of QElectroTech. - - QElectroTech is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - QElectroTech is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with QElectroTech. If not, see . -*/ -#include "elementscategorydeleter.h" -#include "qetapp.h" -#include "qetmessagebox.h" - -/** - Constructeur - @param category_path Chemin virtuel de la categorie a supprimer - @param parent QWidget parent -*/ -ElementsCategoryDeleter::ElementsCategoryDeleter(const ElementsLocation &category_path, QWidget *parent) : - QWidget(parent), - category(0) -{ - // recupere la categorie a supprimer - ElementsCollectionItem *category_item = QETApp::collectionItem(category_path); - if (!category_item) return; - - // on exige une collection ou une categorie - if (!category_item -> isCollection() && !category_item -> isCategory()) return; - - category = category_item; -} - -/// Destructeur -ElementsCategoryDeleter::~ElementsCategoryDeleter() { -} - -/** - Supprime la categorie et ses elements : verifie l'existence du dossier, - demande deux fois confirmation a l'utilisateur et avertit ce dernier si la - suppression a echoue. - @return true si la suppression a ete effectuee, false sinon -*/ -bool ElementsCategoryDeleter::exec() { - // verifie l'existence de la categorie - if (!category) return(false); - - // gere le cas ou la suppression d'une collection est demandee - if (category -> isCollection()) { - QMessageBox::StandardButton answer_0 = QET::QetMessageBox::question( - this, - tr("Vider la collection ?", "message box title"), - tr("Êtes-vous sûr de vouloir vider cette collection ?", "message box content"), - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel - ); - if (answer_0 != QMessageBox::Yes) return(false); - } - - /** - @todo Regression : rafficher le nom de la categorie supprimee - */ - // QString cat_name(category -> name().replace("<", "<").replace(">", ">")); - - - // avertissement pour la suppression d'une collection - // confirmation #1 - QMessageBox::StandardButton answer_1 = QET::QetMessageBox::question( - this, - tr("Supprimer la catégorie ?", "message box title"), - tr( - "Êtes-vous sûr de vouloir supprimer la catégorie ?\nTous " - "les éléments et les catégories contenus dans cette " - "catégorie seront supprimés.", - "message box content" - ), - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel - ); - if (answer_1 != QMessageBox::Yes) return(false); - - // confirmation #2 - QMessageBox::StandardButton answer_2 = QET::QetMessageBox::question( - this, - tr("Supprimer la catégorie ?", "message box title"), - tr( - "Êtes-vous vraiment sur de vouloir supprimer cette " - "catégorie ?\nLes changements seront définitifs.", - "message box content" - ), - QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel - ); - if (answer_2 != QMessageBox::Yes) return(false); - - // supprime la categorie - if (!category -> remove()) { - QET::QetMessageBox::warning( - this, - tr("Suppression de la catégorie", "message box title"), - tr("La suppression de la catégorie a échoué.", "message box content") - ); - return(false); - } - - return(true); -} diff --git a/sources/elementscategorydeleter.h b/sources/elementscategorydeleter.h deleted file mode 100644 index 14223e5ec..000000000 --- a/sources/elementscategorydeleter.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright 2006-2016 The QElectroTech Team - This file is part of QElectroTech. - - QElectroTech is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - QElectroTech is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with QElectroTech. If not, see . -*/ -#ifndef ELEMENTS_CATEGORY_DELETER_H -#define ELEMENTS_CATEGORY_DELETER_H -#include "fileelementscategory.h" -#include "elementslocation.h" -#include -/** - This class provide an abstract way to delete an elements category along with - its child elements and subcategories. It always requires a double confirmation - from users before actually proceeding to the deletion. - If the deletion of a whole elements collection is required, this class will - require an extra confirmation. -*/ -class ElementsCategoryDeleter : public QWidget { - Q_OBJECT - // constructors, destructor - public: - ElementsCategoryDeleter(const ElementsLocation &, QWidget * = 0); - virtual ~ElementsCategoryDeleter(); - private: - ElementsCategoryDeleter(const ElementsCategory &); - - // methods - public slots: - bool exec(); - - // attributes - private: - ElementsCollectionItem *category; -}; -#endif diff --git a/sources/elementspanel.cpp b/sources/elementspanel.cpp index d9bbf5d72..0a277d35a 100644 --- a/sources/elementspanel.cpp +++ b/sources/elementspanel.cpp @@ -19,14 +19,8 @@ #include "qetapp.h" #include "qetproject.h" #include "diagram.h" -#include "elementscategory.h" -#include "elementscollectioncache.h" -#include "factory/elementfactory.h" -#include "fileelementscollection.h" -#include "fileelementdefinition.h" #include "qeticons.h" #include "templatescollection.h" -#include "element.h" /* Lorsque le flag ENABLE_PANEL_DND_CHECKS est defini, le panel d'elements @@ -38,26 +32,12 @@ */ #define ENABLE_PANEL_DND_CHECKS -/* - Largeur maximale, en pixels, de la pixmap accrochee au pointeur de la - souris -*/ -#define QET_MAX_DND_PIXMAP_WIDTH 500 - -/* - Hauteur maximale, en pixels, de la pixmap accrochee au pointeur de la - souris -*/ -#define QET_MAX_DND_PIXMAP_HEIGHT 375 - /** Constructeur @param parent Le QWidget parent du panel d'appareils */ ElementsPanel::ElementsPanel(QWidget *parent) : GenericPanel(parent), - common_collection_item_(0), - custom_collection_item_(0), first_reload_(true) { // selection unique @@ -89,8 +69,6 @@ ElementsPanel::ElementsPanel(QWidget *parent) : //Emit a signal instead au manage is own context menu setContextMenuPolicy(Qt::CustomContextMenu); - - setElementsCache(QETApp::collectionCache()); } /** @@ -99,41 +77,6 @@ ElementsPanel::ElementsPanel(QWidget *parent) : ElementsPanel::~ElementsPanel() { } -/** - @param qtwi Un QTreeWidgetItem - @return true si qtwi represente un element, false sinon -*/ -bool ElementsPanel::itemIsWritable(QTreeWidgetItem *qtwi) const { - if (ElementsCollectionItem *qtwi_item = collectionItemForItem(qtwi)) { - return(qtwi_item -> isWritable()); - } - return(false); -} - - -/** - @return true si l'item selectionne est accessible en ecriture, false sinon -*/ -bool ElementsPanel::selectedItemIsWritable() const { - if (ElementsCollectionItem *selected_item = selectedItem()) { - return(selected_item -> isWritable()); - } - return(false); -} - -/** - @return la collection, la categorie ou l'element selectionne(e) -*/ -ElementsCollectionItem *ElementsPanel::selectedItem() const { - - - ElementsLocation selected_location(selectedElementLocation()); - if (!selected_location.isNull()) { - return(QETApp::collectionItem(selected_location)); - } - return(0); -} - /** Gere l'entree d'un drag'n drop. L'evenement est accepte si les donnees fournies contiennent un type MIME representant une categorie ou un element @@ -148,71 +91,12 @@ void ElementsPanel::dragEnterEvent(QDragEnterEvent *e) { } } -/** - Gere le mouvement lors d'un drag'n drop -*/ -void ElementsPanel::dragMoveEvent(QDragMoveEvent *e) -{ - // scrolle lorsque le curseur est pres des bords - int limit = 40; - QScrollBar *scroll_bar = verticalScrollBar(); - if (e -> pos().y() < limit) { - scroll_bar -> setValue(scroll_bar -> value() - 1); - } else if (e -> pos().y() > height() - limit) { - scroll_bar -> setValue(scroll_bar -> value() + 1); - } - - QTreeWidget::dragMoveEvent(e); - - // recupere la categorie cible pour le deplacement / la copie - ElementsCategory *target_category = categoryForPos(e -> pos()); - if (!target_category) { - e -> ignore(); - return; - } - - // recupere la source (categorie ou element) pour le deplacement / la copie - ElementsLocation dropped_location = ElementsLocation(e -> mimeData() -> text()); - ElementsCollectionItem *source_item = QETApp::collectionItem(dropped_location, false); - if (!source_item) { - e -> ignore(); - return; - } - -#ifdef ENABLE_PANEL_DND_CHECKS - // ne prend pas en consideration le drop d'un item sur lui-meme ou une categorie imbriquee - if ( - source_item -> location() == target_category -> location() ||\ - target_category -> isChildOf(source_item) - ) { - e -> ignore(); - return; - } - - // s'assure que la categorie cible est accessible en ecriture - if (!target_category -> isWritable()) { - e -> ignore(); - return; - } -#endif - - - e -> accept(); - /// @todo mettre en valeur le lieu de depot -} - /** Gere le debut des drag'n drop @param supportedActions Les actions supportees */ void ElementsPanel::startDrag(Qt::DropActions supportedActions) { Q_UNUSED(supportedActions); - // recupere l'emplacement selectionne - ElementsLocation element_location = selectedElementLocation(); - if (!element_location.isNull()) { - startElementDrag(element_location); - return; - } TitleBlockTemplateLocation tbt_location = selectedTemplateLocation(); if (tbt_location.isValid()) { @@ -221,63 +105,6 @@ void ElementsPanel::startDrag(Qt::DropActions supportedActions) { } } -/** - Handle the dragging of an element. - @param location Location of the dragged element -*/ -void ElementsPanel::startElementDrag(const ElementsLocation &location) { - // recupere la selection - ElementsCollectionItem *selected_item = QETApp::collectionItem(location); - if (!selected_item) return; - - // objet QDrag pour realiser le drag'n drop - QDrag *drag = new QDrag(this); - - // donnees qui seront transmises par le drag'n drop - QString location_string(location.toString()); - QMimeData *mimeData = new QMimeData(); - mimeData -> setText(location_string); - - if (selected_item -> isCategory() || selected_item -> isCollection()) { - mimeData -> setData("application/x-qet-category-uri", location_string.toLatin1()); - drag -> setPixmap(QET::Icons::Folder.pixmap(22, 22)); - } else if (selected_item -> isElement()) { - mimeData -> setData("application/x-qet-element-uri", location_string.toLatin1()); - - // element temporaire pour fournir un apercu - int elmt_creation_state; - Element *temp_elmt = ElementFactory::Instance() -> createElement(location, 0, &elmt_creation_state); - if (elmt_creation_state) { - delete temp_elmt; - return; - } - - // accrochage d'une pixmap representant l'appareil au pointeur - QPixmap elmt_pixmap(temp_elmt -> pixmap()); - QPoint elmt_hotspot(temp_elmt -> hotspot()); - - // ajuste la pixmap si celle-ci est trop grande - QPoint elmt_pixmap_size(elmt_pixmap.width(), elmt_pixmap.height()); - if (elmt_pixmap.width() > QET_MAX_DND_PIXMAP_WIDTH || elmt_pixmap.height() > QET_MAX_DND_PIXMAP_HEIGHT) { - elmt_pixmap = elmt_pixmap.scaled(QET_MAX_DND_PIXMAP_WIDTH, QET_MAX_DND_PIXMAP_HEIGHT, Qt::KeepAspectRatio); - elmt_hotspot = QPoint( - elmt_hotspot.x() * elmt_pixmap.width() / elmt_pixmap_size.x(), - elmt_hotspot.y() * elmt_pixmap.height() / elmt_pixmap_size.y() - ); - } - - drag -> setPixmap(elmt_pixmap); - drag -> setHotSpot(elmt_hotspot); - - // suppression de l'appareil temporaire - delete temp_elmt; - } - - // realisation du drag'n drop - drag -> setMimeData(mimeData); - drag -> start(Qt::MoveAction | Qt::CopyAction); -} - /** Handle the dragging of a title block template @param location Location of the dragged template. @@ -333,21 +160,6 @@ QTreeWidgetItem *ElementsPanel::addProject(QETProject *project) { return(qtwi_project); } -/** - Methode privee permettant d'ajouter une collection d'elements au panel d'elements - @param qtwi_parent QTreeWidgetItem parent sous lequel sera insere la collection d'elements - @param collection Collection a inserer dans le panel d'elements - si - collection vaut 0, cette methode retourne 0. - @param coll_name Nom a utiliser pour la collection - @param icon Icone a utiliser pour l'affichage de la collection - @return Le QTreeWidgetItem insere le plus haut -*/ -QTreeWidgetItem *ElementsPanel::addCollection(ElementsCollection *collection) { - PanelOptions options = GenericPanel::AddAllChild; - options |= GenericPanel::DisplayElementsPreview; - return(addElementsCollection(collection, invisibleRootItem(), options)); -} - QTreeWidgetItem *ElementsPanel::updateTemplatesCollectionItem(QTreeWidgetItem *tbt_collection_qtwi, TitleBlockTemplatesCollection *tbt_collection, PanelOptions options, bool freshly_created) { QTreeWidgetItem *tbtc_qtwi = GenericPanel::updateTemplatesCollectionItem(tbt_collection_qtwi, tbt_collection, options, freshly_created); if (tbt_collection && tbt_collection -> parentProject()) { @@ -369,43 +181,6 @@ QTreeWidgetItem *ElementsPanel::updateTemplateItem(QTreeWidgetItem *tb_template_ return(item); } -QTreeWidgetItem *ElementsPanel::updateElementsCategoryItem(QTreeWidgetItem *category_qtwi, ElementsCategory *category, PanelOptions options, bool freshly_created) { - QTreeWidgetItem *item = GenericPanel::updateElementsCategoryItem(category_qtwi, category, options, freshly_created); - item -> setStatusTip( - 0, - tr( - "Double-cliquez pour réduire ou développer cette catégorie d'éléments", - "Status tip displayed by elements category" - ) - ); - emit(loadingProgressed(++ loading_progress_, -1)); - return(item); -} - -QTreeWidgetItem *ElementsPanel::updateElementsCollectionItem(QTreeWidgetItem *collection_qtwi, ElementsCollection *collection, PanelOptions options, bool freshly_created) { - QTreeWidgetItem *c_qtwi = GenericPanel::updateElementsCollectionItem(collection_qtwi, collection, options, freshly_created); - if (collection && collection -> project()) { - c_qtwi -> setText(0, tr("Collection embarquée")); - c_qtwi -> setStatusTip(0, tr("Double-cliquez pour réduire ou développer cette collection d'éléments embarquée", "Status tip")); - } - return(c_qtwi); -} - -QTreeWidgetItem *ElementsPanel::updateElementItem(QTreeWidgetItem *element_qtwi, ElementDefinition *element, PanelOptions options, bool freshly_created) { - QTreeWidgetItem *item = GenericPanel::updateElementItem(element_qtwi, element, options, freshly_created); - - QString status_tip = tr( - "Glissez-déposez cet élément « %1 » sur un folio pour l'y insérer, double-cliquez dessus pour l'éditer", - "Status tip displayed in the status bar when selecting an element" - ); - item -> setStatusTip(0, status_tip.arg(item -> text(0))); - - item -> setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled); - - emit(loadingProgressed(++ loading_progress_, -1)); - return(item); -} - /** @return true if \a item matches the current filter, false otherwise */ @@ -434,50 +209,18 @@ bool ElementsPanel::matchesFilter(const QTreeWidgetItem *item, QString filter) c return(item_matches); } -/** - Reloads the following collections: - * common collection - * custom collection - * collection of every project displayed in this panel -*/ -void ElementsPanel::reloadCollections() { - QETApp::commonElementsCollection() -> reload(); - QETApp::customElementsCollection() -> reload(); -} - -/** - @return the count of categories and elements within the following collections: - * common collection - * custom collection - * collection of every project displayed in this panel -*/ -int ElementsPanel::elementsCollectionItemsCount() { - int items_count = 0; - items_count += QETApp::commonElementsCollection() -> count(); - items_count += QETApp::customElementsCollection() -> count(); - - return(items_count); -} - /** * @brief ElementsPanel::reload * Reload the elements tree * @param reload_collections true for read all collections since their sources (files, projects ...) */ void ElementsPanel::reload(bool reload_collections) { - if (reload_collections) { - emit(readingAboutToBegin()); - reloadCollections(); - emit(readingFinished()); - } + + Q_UNUSED(reload_collections); QIcon system_icon(":/ico/16x16/qet.png"); QIcon user_icon(":/ico/16x16/go-home.png"); - // estimates the number of categories and elements to load - int items_count = elementsCollectionItemsCount(); - emit(loadingProgressed(loading_progress_ = 0, items_count)); - // load the common title block templates collection TitleBlockTemplatesCollection *common_tbt_collection = QETApp::commonTitleBlockTemplatesCollection(); common_tbt_collection_item_ = addTemplatesCollection(common_tbt_collection, invisibleRootItem()); @@ -486,16 +229,6 @@ void ElementsPanel::reload(bool reload_collections) { common_tbt_collection_item_ -> setWhatsThis(0, tr("Ceci est la collection de cartouches fournie avec QElectroTech. Installée en tant que composant système, vous ne pouvez normalement pas la personnaliser.", "\"What's this\" tip")); if (first_reload_) common_tbt_collection_item_ -> setExpanded(true); - // load the common elements collection - if (QETApp::commonElementsCollection() -> rootCategory()) { - // first check local - QETApp::commonElementsCollection()->cache()->setLocale(QETApp::langFromSetting()); - common_collection_item_ = addCollection(QETApp::commonElementsCollection()); - common_collection_item_ -> setStatusTip(0, tr("Double-cliquez pour réduire ou développer la collection d'éléments QElectroTech", "Status tip")); - common_collection_item_ -> setWhatsThis(0, tr("Ceci est la collection d'éléments fournie avec QElectroTech. Installée en tant que composant système, vous ne pouvez normalement pas la personnaliser.", "\"What's this\" tip")); - if (first_reload_) common_collection_item_ -> setExpanded(true); - } - // load the custom title block templates collection TitleBlockTemplatesCollection *custom_tbt_collection = QETApp::customTitleBlockTemplatesCollection(); custom_tbt_collection_item_ = addTemplatesCollection(custom_tbt_collection, invisibleRootItem()); @@ -504,16 +237,6 @@ void ElementsPanel::reload(bool reload_collections) { custom_tbt_collection_item_ -> setWhatsThis(0, tr("Ceci est votre collection personnelle de cartouches -- utilisez-la pour créer, stocker et éditer vos propres cartouches.", "\"What's this\" tip")); if (first_reload_) custom_tbt_collection_item_ -> setExpanded(true); - // load the custom elements collection - if (QETApp::customElementsCollection() -> rootCategory()) { - // first check local - QETApp::customElementsCollection()->cache()->setLocale(QETApp::langFromSetting()); - custom_collection_item_ = addCollection(QETApp::customElementsCollection()); - custom_collection_item_ -> setStatusTip(0, tr("Double-cliquez pour réduire ou développer votre collection personnelle d'éléments", "Status tip")); - custom_collection_item_ -> setWhatsThis(0, tr("Ceci est votre collection personnelle d'éléments -- utilisez-la pour créer, stocker et éditer vos propres éléments.", "\"What's this\" tip")); - if (first_reload_) custom_collection_item_ -> setExpanded(true); - } - // add projects foreach(QETProject *project, projects_to_display_.values()) { addProject(project); @@ -521,8 +244,6 @@ void ElementsPanel::reload(bool reload_collections) { // the first time, expand the first level of collections if (first_reload_) first_reload_ = false; - - emit(loadingFinished()); } /** @@ -531,8 +252,6 @@ void ElementsPanel::reload(bool reload_collections) { est emis. Si un double-clic sur un schema est effectue, le signal requestForDiagram est emis. - Si un double-clic sur une collection, une categorie ou un element est - effectue, le signal requestForCollectionItem est emis. @param qtwi */ void ElementsPanel::slot_doubleClick(QTreeWidgetItem *qtwi, int) { @@ -543,64 +262,12 @@ void ElementsPanel::slot_doubleClick(QTreeWidgetItem *qtwi, int) { } else if (qtwi_type == QET::Diagram) { Diagram *diagram = valueForItem(qtwi); emit(requestForDiagram(diagram)); - } else if (qtwi_type & QET::ElementsCollectionItem) { - ElementsLocation element = valueForItem(qtwi); - emit(requestForCollectionItem(element)); } else if (qtwi_type == QET::TitleBlockTemplate) { TitleBlockTemplateLocation tbt = valueForItem(qtwi); emit(requestForTitleBlockTemplate(tbt)); } } -/** - @param qtwi Un QTreeWidgetItem - @return L'ElementsCollectionItem represente par qtwi, ou 0 si qtwi ne - represente pas un ElementsCollectionItem -*/ -ElementsCollectionItem *ElementsPanel::collectionItemForItem(QTreeWidgetItem *qtwi) const { - if (qtwi && qtwi -> type() & QET::ElementsCollectionItem) { - ElementsLocation item_location = elementLocationForItem(qtwi); - return(QETApp::collectionItem(item_location)); - } - return(0); -} - -/** - Cette methode permet d'acceder a la categorie correspondant a un item donne. - Si cet item represente une collection, c'est sa categorie racine qui est renvoyee. - Si cet item represente une categorie, c'est cette categorie qui est renvoyee. - Si cet item represente un element, c'est sa categorie parente qui est renvoyee. - @param qtwi un QTreeWidgetItem - @return la categorie correspondant au QTreeWidgetItem qtwi, ou 0 s'il n'y a - aucune categorie correspondante. -*/ -ElementsCategory *ElementsPanel::categoryForItem(QTreeWidgetItem *qtwi) { - if (!qtwi) return(0); - - // Recupere le CollectionItem associe a cet item - ElementsCollectionItem *collection_item = collectionItemForItem(qtwi); - if (!collection_item) return(0); - - // recupere la categorie cible pour le deplacement - return(collection_item -> toCategory()); -} - -/** - @param pos Position dans l'arborescence - @return La categorie situee sous la position pos, ou 0 s'il n'y a aucune - categorie correspondante. - @see categoryForItem -*/ -ElementsCategory *ElementsPanel::categoryForPos(const QPoint &pos) { - // Accede a l'item sous la position - QTreeWidgetItem *pos_qtwi = itemAt(pos); - if (!pos_qtwi) { - return(0); - } - - return(categoryForItem(pos_qtwi)); -} - /** @param qtwi a QTreeWidgetItem @return the directory path of the object represented by \a qtwi @@ -626,23 +293,15 @@ QString ElementsPanel::dirPathForItem(QTreeWidgetItem *item) { QString ElementsPanel::filePathForItem(QTreeWidgetItem *item) { if (!item) return(QString()); - ElementsCollectionItem *collection_item = collectionItemForItem(item); - if (collection_item) { - if (collection_item -> hasFilePath()) { - return(collection_item -> filePath()); - } + TitleBlockTemplateLocation tbt_location = templateLocationForItem(item); + TitleBlockTemplatesCollection *tbt_collection = tbt_location.parentCollection(); + if (tbt_collection && tbt_collection -> hasFilePath()) { + return(tbt_collection -> filePath()); } else { - TitleBlockTemplateLocation tbt_location = templateLocationForItem(item); - TitleBlockTemplatesCollection *tbt_collection = tbt_location.parentCollection(); - if (tbt_collection && tbt_collection -> hasFilePath()) { - return(tbt_collection -> filePath()); - } - else { - QETProject *project = projectForItem(item); - if (project) { - return(project -> filePath()); - } + QETProject *project = projectForItem(item); + if (project) { + return(project -> filePath()); } } return(QString()); @@ -710,23 +369,6 @@ void ElementsPanel::projectWasClosed(QETProject *project) { emit(panelContentChanged()); } -/** - Affiche un element etant donne son emplacement - @param location Emplacement de l'element a afficher -*/ -bool ElementsPanel::scrollToElement(const ElementsLocation &location) { - // recherche l'element dans le panel - QTreeWidgetItem *item = itemForElementsLocation(location); - if (!item) return(false); - - // s'assure que l'item ne soit pas filtre - item -> setHidden(false); - setCurrentItem(item); - ensureHierarchyIsVisible(QList() << item); - scrollToItem(item); - return(true); -} - /** Build filter list for multiple filter */ @@ -788,13 +430,3 @@ void ElementsPanel::ensureHierarchyIsVisible(const QList &ite if (parent_qtwi -> isHidden()) parent_qtwi -> setHidden(false); } } - -/** - Scroll to the currently selected item. -*/ -void ElementsPanel::scrollToSelectedItem() { - QList selected_items = selectedItems(); - if (selected_items.count()) { - scrollToItem(selected_items.first(), QAbstractItemView::PositionAtCenter); - } -} diff --git a/sources/elementspanel.h b/sources/elementspanel.h index 848c9a87d..1b0bcf1c4 100644 --- a/sources/elementspanel.h +++ b/sources/elementspanel.h @@ -17,17 +17,12 @@ */ #ifndef PANELAPPAREILS_H #define PANELAPPAREILS_H -#include + #include "genericpanel.h" -#include "elementslocation.h" #include "templatelocation.h" + class QETProject; class Diagram; -class ElementsCollection; -class ElementsCollectionItem; -class ElementsCategory; -class ElementDefinition; -class ElementsCollectionCache; class TitleBlockTemplatesFilesCollection; /** @@ -50,29 +45,15 @@ class ElementsPanel : public GenericPanel { // methods public: // methods used to determine what is represented by a particular visual item - bool itemIsWritable(QTreeWidgetItem *) const; - bool selectedItemIsWritable() const; // methods used to get what is represented by a particular visual item - ElementsCollectionItem *collectionItemForItem(QTreeWidgetItem *) const; - ElementsCollectionItem *selectedItem() const; - ElementsCategory *categoryForItem(QTreeWidgetItem *); - ElementsCategory *categoryForPos(const QPoint &); QString dirPathForItem(QTreeWidgetItem *); QString filePathForItem(QTreeWidgetItem *); - void reloadCollections(); - int elementsCollectionItemsCount(); - signals: void requestForProject(QETProject *); void requestForDiagram(Diagram *); - void requestForCollectionItem(const ElementsLocation &); void requestForTitleBlockTemplate(const TitleBlockTemplateLocation &); - void readingAboutToBegin(); - void readingFinished(); - void loadingProgressed(int, int); - void loadingFinished(); public slots: void slot_doubleClick(QTreeWidgetItem *, int); @@ -80,17 +61,13 @@ class ElementsPanel : public GenericPanel { void filter(const QString &, QET::Filtering = QET::RegularFilter); void projectWasOpened(QETProject *); void projectWasClosed(QETProject *); - bool scrollToElement(const ElementsLocation &); void buildFilterList(); void applyCurrentFilter(const QList &); void ensureHierarchyIsVisible(const QList &); - void scrollToSelectedItem(); protected: void dragEnterEvent(QDragEnterEvent *); - void dragMoveEvent(QDragMoveEvent *); void startDrag(Qt::DropActions); - void startElementDrag(const ElementsLocation &); void startTitleBlockTemplateDrag(const TitleBlockTemplateLocation &); bool matchesCurrentFilter(const QTreeWidgetItem *) const; bool matchesFilter(const QTreeWidgetItem *, QString) const; @@ -100,24 +77,17 @@ class ElementsPanel : public GenericPanel { private: virtual QTreeWidgetItem *addProject (QETProject *); - virtual QTreeWidgetItem *addCollection(ElementsCollection *); virtual QTreeWidgetItem *updateTemplatesCollectionItem(QTreeWidgetItem *, TitleBlockTemplatesCollection *, PanelOptions = AddAllChild, bool = false); virtual QTreeWidgetItem *updateTemplateItem (QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions, bool = false); - virtual QTreeWidgetItem *updateElementsCategoryItem(QTreeWidgetItem *, ElementsCategory *, PanelOptions, bool = false); - virtual QTreeWidgetItem *updateElementsCollectionItem(QTreeWidgetItem *, ElementsCollection *, PanelOptions, bool = false); - virtual QTreeWidgetItem *updateElementItem (QTreeWidgetItem *, ElementDefinition *, PanelOptions, bool = false); // attributes private: QSet projects_to_display_; ///< list of projects that have been added to this panel - QTreeWidgetItem *common_collection_item_; ///< pointer to the item representing the common elements collection QTreeWidgetItem *common_tbt_collection_item_; ///< pointer to the item representing the common templates collection - QTreeWidgetItem *custom_collection_item_; ///< pointer to the item representing the user elements collection QTreeWidgetItem *custom_tbt_collection_item_; ///< pointer to the item representing the user templates collection int loading_progress_; ///< used to track the loading progress of elements collections bool first_reload_; ///< used to distinguish the first time this panel is reloaded QString filter_; ///< Currently applied filter QStringList filter_list_; ///< Currently applied list of filter - QTreeWidgetItem *it_prev_, *it_; }; #endif diff --git a/sources/elementspanelwidget.cpp b/sources/elementspanelwidget.cpp index c29fc28c6..6e437765e 100644 --- a/sources/elementspanelwidget.cpp +++ b/sources/elementspanelwidget.cpp @@ -40,10 +40,6 @@ @param parent Le QWidget parent de ce widget */ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) { - // initialize the progress bar (hidden by default) - progress_bar_ = new QProgressBar(this); - progress_bar_ -> setVisible(false); - progress_bar_ -> setTextVisible(true); // initalise le panel d'elements elements_panel = new ElementsPanel(this); @@ -107,17 +103,12 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) { connect(elements_panel, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(updateButtons())); connect(elements_panel, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(handleContextMenu(const QPoint &))); connect(elements_panel, SIGNAL(requestForDiagram(Diagram*)), this, SIGNAL(requestForDiagram(Diagram*))); - connect(elements_panel, SIGNAL(requestForCollectionItem(const ElementsLocation &)), this, SLOT(handleCollectionRequest(const ElementsLocation &))); connect( elements_panel, SIGNAL(requestForTitleBlockTemplate(const TitleBlockTemplateLocation &)), QETApp::instance(), SLOT(openTitleBlockTemplate(const TitleBlockTemplateLocation &)) ); - connect(elements_panel, SIGNAL(loadingProgressed(int, int)), this, SLOT(updateProgressBar(int, int))); - connect(elements_panel, SIGNAL(readingAboutToBegin()), this, SLOT(collectionsRead())); - connect(elements_panel, SIGNAL(readingFinished()), this, SLOT(collectionsReadFinished())); - connect(elements_panel, SIGNAL(loadingFinished()), this, SLOT(loadingFinished())); // disposition verticale QVBoxLayout *vlayout = new QVBoxLayout(this); @@ -125,12 +116,8 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) { vlayout -> setSpacing(0); vlayout -> addWidget(filter_textfield); vlayout -> addWidget(elements_panel); - vlayout -> addWidget(progress_bar_); vlayout -> setStretchFactor(elements_panel, 75000); setLayout(vlayout); - - // by default, the reload button is disabled - reload -> setEnabled(false); } /** @@ -173,9 +160,6 @@ void ElementsPanelWidget::reloadAndFilter() { // recharge tous les elements reload -> setEnabled(false); elements_panel -> reload(true); - - // the reload button was enabled again through loadingFinished() - reload -> setEnabled(false); // reapplique le filtre if (!filter_textfield -> text().isEmpty()) { elements_panel -> filter(filter_textfield -> text()); @@ -414,69 +398,6 @@ void ElementsPanelWidget::handleContextMenu(const QPoint &pos) { } } -/** - Gere les demandes d'edition de categories ou d'elements - @param item Item de la collection a editer -*/ -void ElementsPanelWidget::handleCollectionRequest(const ElementsLocation &item_location) { - if (item_location.isNull()) return; - ElementsCollectionItem *item = QETApp::collectionItem(item_location); - if (!item) return; - if (item -> isElement()) { - // il s'agit d'un element - launchElementEditor(item -> location()); - } - // we could edit it categories, but instead people prefer the double-clic to - // expand/collapse them -} - -/** - Reflects the fact that collections are being read (i.e from filesystem) in - the progress bar. -*/ -void ElementsPanelWidget::collectionsRead() { - progress_bar_ -> setMinimum(0); - progress_bar_ -> setMaximum(1); - progress_bar_ -> setValue(0); - progress_bar_ -> setFormat(tr("Lecture...", "Reading of elements/categories files")); - progress_bar_ -> setVisible(true); -} - -/** - Reflects the fact that collections have been read (i.e from filesystem) in - the progress bar. -*/ -void ElementsPanelWidget::collectionsReadFinished() { - // we do not hide the progress bar because it will be used by updateProgressBar -} - -/** - Updates the progress bar - @param current value that should be displayed - @param maximum maximum expected value; -1 means "use the previously known one" -*/ -void ElementsPanelWidget::updateProgressBar(int current, int maximum) { - int provided_maximum = maximum == -1 ? progress_bar_ -> maximum() : maximum; - if (provided_maximum != progress_bar_ -> maximum()) { - progress_bar_ -> setMaximum(maximum); - } - if (!current) { - progress_bar_ -> setFormat(tr("Chargement : %p%", "Visual rendering of elements/categories files - %p is the progress percentage")); - progress_bar_ -> setVisible(true); - } - progress_bar_ -> setValue(current); -} - -/** - Reflects the fact the whole panel content was loaded by hiding the progress - bar and enabling again the reload button. -*/ -void ElementsPanelWidget::loadingFinished() { - QTimer::singleShot(500, progress_bar_, SLOT(hide())); - reload -> setEnabled(true); - -} - void ElementsPanelWidget::filterEdited(const QString &next_text) { if (previous_filter_.isEmpty() && next_text.length() == 1) { // the field is not empty anymore: begin filtering @@ -503,22 +424,3 @@ void ElementsPanelWidget::keyPressEvent (QKeyEvent *e) { } return; } - -/** - Lance l'editeur d'element pour l'element filename - @param location Emplacement de l'element a editer -*/ -void ElementsPanelWidget::launchElementEditor(const ElementsLocation &location) { - QETApp::instance() -> openElementLocations(QList() << location); -} - -/** - Lance l'editeur de categorie pour la categorie path - @param location Emplacement de la categorie a editer -*/ -void ElementsPanelWidget::launchCategoryEditor(const ElementsLocation &location) { - ElementsCategoryEditor ece(location, true); - if (ece.exec() == QDialog::Accepted) { - elements_panel -> reload(); - } -} diff --git a/sources/elementspanelwidget.h b/sources/elementspanelwidget.h index 5dc2dd22f..5dcd0a67b 100644 --- a/sources/elementspanelwidget.h +++ b/sources/elementspanelwidget.h @@ -45,7 +45,6 @@ class ElementsPanelWidget : public QWidget { QAction *tbt_add, *tbt_edit, *tbt_remove; QMenu *context_menu; QLineEdit *filter_textfield; - QProgressBar *progress_bar_; // methods public: @@ -85,19 +84,12 @@ class ElementsPanelWidget : public QWidget { void removeTitleBlockTemplate(); void updateButtons(); void handleContextMenu(const QPoint &); - void handleCollectionRequest(const ElementsLocation &); - void collectionsRead(); - void collectionsReadFinished(); - void updateProgressBar(int, int); - void loadingFinished(); void filterEdited(const QString &); protected: virtual void keyPressEvent (QKeyEvent *e); private: - void launchElementEditor(const ElementsLocation &); - void launchCategoryEditor(const ElementsLocation &); QString previous_filter_; }; diff --git a/sources/genericpanel.cpp b/sources/genericpanel.cpp index cceea84e6..be6c19bfe 100644 --- a/sources/genericpanel.cpp +++ b/sources/genericpanel.cpp @@ -19,14 +19,9 @@ #include #include "qetproject.h" #include "diagram.h" -#include "elementscollection.h" -#include "elementscategory.h" -#include "elementdefinition.h" #include "titleblock/templatescollection.h" #include "titleblock/templatelocation.h" -#include "elementslocation.h" #include "qeticons.h" -#include "elementscollectioncache.h" #include "qetapp.h" /** @@ -35,7 +30,6 @@ */ GenericPanel::GenericPanel(QWidget *parent) : QTreeWidget(parent), - cache_(0), first_activation_(true) { header() -> hide(); @@ -48,28 +42,6 @@ GenericPanel::GenericPanel(QWidget *parent) : GenericPanel::~GenericPanel() { } -/** - @return the elements cache currently used, or 0 if none has been set. -*/ -ElementsCollectionCache *GenericPanel::elementsCache() { - return(cache_); -} - -/** - @return the elements cache to be used to render elements collection. If no - cache has been explicitly set using setElementsCache(), this method builds - a basic cache named "genericpanel.sqlite" in the current working directory. -*/ -ElementsCollectionCache *GenericPanel::getElementsCache() { - if (!cache_) { - // build a default cache - QString cache_path = "./genericpanel.sqlite"; - cache_ = new ElementsCollectionCache(cache_path, this); - cache_->setLocale(QETApp::langFromSetting()); - } - return(cache_); -} - /** @return the type of the current item */ @@ -109,16 +81,6 @@ TitleBlockTemplateLocation GenericPanel::templateLocationForItem(QTreeWidgetItem /** -*/ -ElementsLocation GenericPanel::elementLocationForItem(QTreeWidgetItem *item) const { - if (item && item -> type() & QET::ElementsCollectionItem) { - return(valueForItem(item)); - } - return(ElementsLocation()); -} - -/** - */ QETProject *GenericPanel::selectedProject() const { return(projectForItem(currentItem())); @@ -140,28 +102,6 @@ TitleBlockTemplateLocation GenericPanel::selectedTemplateLocation() const { /** -*/ -ElementsLocation GenericPanel::selectedElementLocation() const { - return(elementLocationForItem(currentItem())); -} - -/** - @param cache New cache to be used to render elements. - @param previous if non-zero, this pointer will be set to the previously used cache - @return true if the cache was changed, false otherwise (it may happen if the - provided cache is already the one being used). -*/ -bool GenericPanel::setElementsCache(ElementsCollectionCache *cache, ElementsCollectionCache **previous) { - if (cache == cache_) return(false); - if (previous) { - *previous = cache_; - } - cache_ = cache; - return(true); -} - -/** - */ QTreeWidgetItem *GenericPanel::addProject(QETProject *project, QTreeWidgetItem *parent_item, PanelOptions options) { if (!project) return(0); @@ -556,301 +496,6 @@ QTreeWidgetItem *GenericPanel::fillTemplateItem(QTreeWidgetItem *tb_template_qtw return(fillItem(tb_template_qtwi, options, freshly_created)); } -/** - Add an elements category to the panel. - @param parent_item Parent for the created QTreeWidgetItem - @param collection Collection to be added to the panel - @param options Control the creation of child items - @return the created QTreeWidgetItem -*/ -QTreeWidgetItem *GenericPanel::addElementsCollection(ElementsCollection *collection, QTreeWidgetItem *parent_item, PanelOptions options) { - if (!collection) return(0); - bool creation_required; - - QTreeWidgetItem *collection_qtwi = getItemForElementsCollection(collection, &creation_required); - updateElementsCollectionItem(collection_qtwi, collection, options, creation_required); - reparent(collection_qtwi, parent_item); - fillElementsCollectionItem(collection_qtwi, collection, options, creation_required); - - return(collection_qtwi); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::getItemForElementsCollection(ElementsCollection *collection, bool *created) { - if (!collection) return(0); - - QTreeWidgetItem *collection_item = elements_.value(collection -> rootCategory() -> location(), 0); - if (collection_item) { - if (created) *created = false; - return(collection_item); - } - - collection_item = makeItem(QET::ElementsCollection); - if (created) *created = true; - return(collection_item); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::updateElementsCollectionItem(QTreeWidgetItem *collection_qtwi, ElementsCollection *collection, PanelOptions options, bool freshly_created) { - Q_UNUSED(options) - if (!collection) return(0); - - QString collection_title = collection -> title(); - QIcon collection_icon = collection -> icon(); - - if (!collection_title.isEmpty()) collection_qtwi -> setText(0, collection_title); - if (!collection_icon.isNull()) collection_qtwi -> setIcon(0, collection_icon); - - if (freshly_created) { - collection_qtwi -> setData(0, GenericPanel::Item, qVariantFromValue(collection -> rootCategory() -> location())); - elements_.insert(collection -> rootCategory() -> location(), collection_qtwi); - - connect( - collection, SIGNAL(elementsCollectionChanged(ElementsCollection*)), - this, SLOT(elementsCollectionChanged(ElementsCollection*)) - ); - } - - return(updateItem(collection_qtwi, options, freshly_created)); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::fillElementsCollectionItem(QTreeWidgetItem *collection_qtwi, ElementsCollection *collection, PanelOptions options, bool freshly_created) { - // use the cache from the provided collection, if any - bool restore_previous_cache = false; - ElementsCollectionCache *previous_cache = 0; - ElementsCollectionCache *collection_cache = collection -> cache(); - if (collection_cache) { - restore_previous_cache = setElementsCache(collection_cache, &previous_cache); - } - - ElementsCollectionCache *cache = getElementsCache(); - cache -> beginCollection(collection); - fillElementsCategoryItem(collection_qtwi, collection -> rootCategory(), options, freshly_created); - cache -> endCollection(collection); - - // restore the former cache - if (restore_previous_cache) { - setElementsCache(previous_cache); - } - return(fillItem(collection_qtwi, options, freshly_created)); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::itemForElementsLocation(const ElementsLocation &location) { - return(elements_.value(location, 0)); -} - -/** - Add an elements category to the panel. - @param category Category to be added to the panel - @param parent_item Parent for the created QTreeWidgetItem - @param options Control the creation of child items - @return the created QTreeWidgetItem -*/ -QTreeWidgetItem *GenericPanel::addElementsCategory(ElementsCategory *category, QTreeWidgetItem *parent_item, PanelOptions options) { - if (!category) return(0); - bool creation_required; - - QTreeWidgetItem *category_qtwi = getItemForElementsCategory(category, &creation_required); - updateElementsCategoryItem(category_qtwi, category, options, creation_required); - reparent(category_qtwi, parent_item); - fillElementsCategoryItem(category_qtwi, category, options, creation_required); - - return(category_qtwi); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::itemForElementsCategory(ElementsCategory *category) { - if (!category) return(0); - return(elements_.value(category -> location())); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::getItemForElementsCategory(ElementsCategory *category, bool *created) { - if (!category) return(0); - - QTreeWidgetItem *category_item = elements_.value(category -> location(), 0); - if (category_item) { - if (created) *created = false; - return(category_item); - } - - category_item = makeItem(QET::ElementsCategory); - if (created) *created = true; - return(category_item); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::updateElementsCategoryItem(QTreeWidgetItem *category_qtwi, ElementsCategory *category, PanelOptions options, bool freshly_created) { - Q_UNUSED(options) - if (!category || !category_qtwi) return(0); - QString category_whatsthis = tr( - "Ceci est une catégorie d'éléments, un simple container permettant d'organiser les collections d'éléments", - "\"What's this\" tip" - ); - category_qtwi -> setWhatsThis(0, category_whatsthis); - QString category_tooltip = category -> location().toString(); - category_qtwi -> setToolTip(0, category_tooltip); - category_qtwi -> setText(0, category -> name()); - markItemAsContainer(category_qtwi); - - if (freshly_created) { - category_qtwi -> setData(0, GenericPanel::Item, qVariantFromValue(category -> location())); - elements_.insert(category -> location(), category_qtwi); - } - return(updateItem(category_qtwi, options, freshly_created)); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::fillElementsCategoryItem(QTreeWidgetItem *category_qtwi, ElementsCategory *category, PanelOptions options, bool freshly_created) { - if (!category || !category_qtwi) return(0); - - int index = 0; - - category_qtwi -> setData(0, GenericPanel::PanelFlags, (int)options); - - if (options & AddChildElementsCategories) { - if (!freshly_created) { - QList sub_categories; - foreach(ElementsCategory *sub_category, category -> categories()) { - sub_categories << sub_category -> location(); - } - removeObsoleteItems(sub_categories, category_qtwi, QET::ElementsCategory, false); - } - - foreach (ElementsCategory *sub_category, category -> categories()) { - QTreeWidgetItem *sub_category_qtwi = addElementsCategory(sub_category, 0, options); - category_qtwi -> insertChild(index ++, sub_category_qtwi); - } - } - - if (options & AddChildElements) { - if (!freshly_created) { - QList sub_elements; - foreach(ElementDefinition *sub_element, category -> elements()) { - sub_elements << sub_element -> location(); - } - removeObsoleteItems(sub_elements, category_qtwi, QET::Element, false); - } - foreach (ElementDefinition *sub_element, category -> elements()) { - QTreeWidgetItem *sub_element_qtwi = addElement(sub_element, 0, options); - category_qtwi -> insertChild(index ++, sub_element_qtwi); - } - } - - return(fillItem(category_qtwi, options, freshly_created)); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::addElement(ElementDefinition *element, QTreeWidgetItem *parent_item, PanelOptions options) { - if (!element) return(0); - bool creation_required; - - QTreeWidgetItem *element_qtwi = getItemForElement(element, &creation_required); - updateElementItem(element_qtwi, element, options, creation_required); - reparent(element_qtwi, parent_item); - fillElementItem(element_qtwi, element, options, creation_required); - - return(element_qtwi); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::itemForElement(ElementDefinition *element) { - if (!element) return(0); - return(elements_.value(element -> location(), 0)); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::getItemForElement(ElementDefinition *element, bool *created) { - if (!element) return(0); - - QTreeWidgetItem *element_qtwi = elements_.value(element -> location(), 0); - if (element_qtwi) { - if (created) *created = false; - return(element_qtwi); - } - - element_qtwi = makeItem(QET::Element); - if (created) *created = true; - return(element_qtwi); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::updateElementItem(QTreeWidgetItem *element_qtwi, ElementDefinition *element, PanelOptions options, bool freshly_created) { - Q_UNUSED(options) - Q_UNUSED(freshly_created) - if (!element_qtwi || !element) { - return(updateItem(element_qtwi, options, freshly_created)); - } - - ElementsCollectionCache *cache = getElementsCache(); - if (!cache -> fetchElement(element)) { - return(updateItem(element_qtwi, options, freshly_created)); - } - - ElementsLocation element_location = element -> location(); - element_qtwi -> setText(0, cache -> name()); - QString element_whatsthis = tr("Ceci est un élément que vous pouvez insérer dans un schéma.", "\"What's this\" tip"); - element_qtwi -> setWhatsThis(0, element_whatsthis); - if (options & DisplayElementsPreview) { - element_qtwi -> setIcon(0, QIcon(cache -> pixmap())); - } - - // note the following lines are technically marking the element as used - element_qtwi -> setToolTip(0, element_location.toString()); - element_qtwi -> setBackground(0, QBrush()); - // actions speciales pour les elements appartenant a un projet - if (QETProject *element_project = element_location.project()) { - // affiche en rouge les elements inutilises dans un projet - if (!element_project -> usesElement(element -> location())) { - markItemAsUnused(element_qtwi); - } - } - - if (freshly_created) { - element_qtwi -> setData(0, GenericPanel::Item, qVariantFromValue(element_location)); - elements_.insert(element_location, element_qtwi); - } - - return(updateItem(element_qtwi, options, freshly_created)); -} - -/** - -*/ -QTreeWidgetItem *GenericPanel::fillElementItem (QTreeWidgetItem *element_qtwi, ElementDefinition *element, PanelOptions options, bool freshly_created) { - Q_UNUSED(element_qtwi) - Q_UNUSED(element) - Q_UNUSED(options) - Q_UNUSED(freshly_created) - return(fillItem(element_qtwi, options, freshly_created)); -} - /** This generic method is called at the end of each update*Item method. Its only purpose is being reimplemented in a subclass. The default @@ -971,14 +616,6 @@ void GenericPanel::diagramUsedTemplate(TitleBlockTemplatesCollection *collection /** -*/ -void GenericPanel::elementsCollectionChanged(ElementsCollection *collection) { - addElementsCollection(collection, 0, 0); - emit(panelContentChanged()); -} - -/** - */ QString GenericPanel::defaultText(QET::ItemType type) { switch(type) { @@ -1143,9 +780,7 @@ void GenericPanel::unregisterItem(QTreeWidgetItem *item) { if (!item) return; int type = item ->type(); - if (type & QET::ElementsCollectionItem) { - elements_.remove(valueForItem(item)); - } else if (type & QET::TitleBlockTemplatesCollectionItem) { + if (type & QET::TitleBlockTemplatesCollectionItem) { tb_templates_.remove(valueForItem(item)); } else if (type == QET::Diagram) { diagrams_.remove(valueForItem(item)); @@ -1162,7 +797,6 @@ void GenericPanel::clearPanel() { projects_.clear(); diagrams_.clear(); tb_templates_.clear(); - elements_.clear(); } /** diff --git a/sources/genericpanel.h b/sources/genericpanel.h index 67785c718..1f46ecb02 100644 --- a/sources/genericpanel.h +++ b/sources/genericpanel.h @@ -19,16 +19,12 @@ #define GENERIC_PANEL_H #include "qet.h" #include -#include "elementslocation.h" + class QTreeWidgetItem; class QETProject; class Diagram; -class ElementsCollection; -class ElementsCategory; -class ElementDefinition; class TitleBlockTemplatesCollection; class TitleBlockTemplateLocation; -class ElementsCollectionCache; /** The generic panel is a QTreeWidget subclass providing extra methods @@ -45,13 +41,7 @@ class GenericPanel : public QTreeWidget { AddChildTemplatesCollection = 2, AddChildTemplates = 4, AddAllChildTemplates = 6, - AddChildElementsCollections = 8, - AddChildElementsCategories = 16, - AddChildElementsContainers = 24, - AddChildElements = 32, - AddAllChildElements = 56, AddAllChild = 63, - DisplayElementsPreview = 64, All = 127 }; Q_DECLARE_FLAGS(PanelOptions, PanelOption) @@ -68,27 +58,17 @@ class GenericPanel : public QTreeWidget { GenericPanel(QWidget * = 0); virtual ~GenericPanel(); - // cache-related methods - public: - virtual ElementsCollectionCache *elementsCache(); - virtual bool setElementsCache(ElementsCollectionCache *, ElementsCollectionCache ** = 0); - - protected: - virtual ElementsCollectionCache *getElementsCache(); - public: // convenience methods to obtain what an item represents virtual int currentItemType(); virtual QETProject *projectForItem(QTreeWidgetItem *) const; virtual Diagram *diagramForItem(QTreeWidgetItem *) const; virtual TitleBlockTemplateLocation templateLocationForItem(QTreeWidgetItem *) const; - virtual ElementsLocation elementLocationForItem(QTreeWidgetItem *) const; // convenience methods to obtain what the selected item represents virtual QETProject *selectedProject() const; virtual Diagram *selectedDiagram() const; virtual TitleBlockTemplateLocation selectedTemplateLocation() const; - virtual ElementsLocation selectedElementLocation() const; // project-related methods public: @@ -126,33 +106,6 @@ class GenericPanel : public QTreeWidget { virtual QTreeWidgetItem *updateTemplateItem(QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions = AddAllChild, bool = false); virtual QTreeWidgetItem *fillTemplateItem (QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions = AddAllChild, bool = false); - // elements collections methods - public: - virtual QTreeWidgetItem *itemForElementsLocation(const ElementsLocation &); - virtual QTreeWidgetItem *addElementsCollection(ElementsCollection *, QTreeWidgetItem *, PanelOptions = AddAllChild); - protected: - virtual QTreeWidgetItem *getItemForElementsCollection(ElementsCollection *, bool * = 0); - virtual QTreeWidgetItem *updateElementsCollectionItem(QTreeWidgetItem *, ElementsCollection *, PanelOptions = AddAllChild, bool = false); - virtual QTreeWidgetItem *fillElementsCollectionItem (QTreeWidgetItem *, ElementsCollection *, PanelOptions = AddAllChild, bool = false); - - // elements categories methods - public: - virtual QTreeWidgetItem *addElementsCategory(ElementsCategory *, QTreeWidgetItem * = 0, PanelOptions = AddAllChild); - virtual QTreeWidgetItem *itemForElementsCategory(ElementsCategory *); - protected: - virtual QTreeWidgetItem *getItemForElementsCategory(ElementsCategory *, bool * = 0); - virtual QTreeWidgetItem *updateElementsCategoryItem(QTreeWidgetItem *, ElementsCategory *, PanelOptions = AddAllChild, bool = false); - virtual QTreeWidgetItem *fillElementsCategoryItem (QTreeWidgetItem *, ElementsCategory *, PanelOptions = AddAllChild, bool = false); - - // elements methods - public: - virtual QTreeWidgetItem *addElement(ElementDefinition *, QTreeWidgetItem * = 0, PanelOptions = AddAllChild); - virtual QTreeWidgetItem *itemForElement(ElementDefinition *); - protected: - virtual QTreeWidgetItem *getItemForElement(ElementDefinition *, bool * = 0); - virtual QTreeWidgetItem *updateElementItem(QTreeWidgetItem *, ElementDefinition *, PanelOptions = AddAllChild, bool = false); - virtual QTreeWidgetItem *fillElementItem (QTreeWidgetItem *, ElementDefinition *, PanelOptions = AddAllChild, bool = false); - // generic methods protected: virtual QTreeWidgetItem *updateItem(QTreeWidgetItem *, PanelOptions = AddAllChild, bool = false); @@ -167,7 +120,6 @@ class GenericPanel : public QTreeWidget { virtual void diagramTitleChanged(Diagram *, const QString &); virtual void templatesCollectionChanged(TitleBlockTemplatesCollection*, const QString &); virtual void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &); - virtual void elementsCollectionChanged(ElementsCollection *); // various other methods protected: @@ -193,14 +145,10 @@ class GenericPanel : public QTreeWidget { private slots: void emitFirstActivated(); - protected: - ElementsCollectionCache *cache_; ///< Cache used to render elements - private: bool first_activation_; ///< boolean used to track the first time this widget is activated/shown QHash projects_; ///< Allow quick retrieval of the item representing a given project QHash diagrams_; ///< Allow quick retrieval of the item representing a given diagram QHash tb_templates_; ///< Allow quick retrieval of the item representing a title block template - QHash elements_; ///< Allow quick retrieval of the item representing an element }; #endif diff --git a/sources/qetapp.cpp b/sources/qetapp.cpp index 340610eda..d28eb8496 100644 --- a/sources/qetapp.cpp +++ b/sources/qetapp.cpp @@ -21,9 +21,7 @@ #include "configpages.h" #include "qetdiagrameditor.h" #include "qetelementeditor.h" -#include "elementscollectionitem.h" #include "elementscollectioncache.h" -#include "fileelementscollection.h" #include "titleblocktemplate.h" #include "qettemplateeditor.h" #include "qetproject.h" @@ -48,8 +46,6 @@ QString QETApp::common_tbt_dir_ = QString(); QString QETApp::config_dir = QString(); #endif QString QETApp::lang_dir = QString(); -FileElementsCollection *QETApp::common_collection = 0; -FileElementsCollection *QETApp::custom_collection = 0; TitleBlockTemplatesFilesCollection *QETApp::common_tbt_collection_; TitleBlockTemplatesFilesCollection *QETApp::custom_tbt_collection_; ElementsCollectionCache *QETApp::collections_cache_ = 0; @@ -110,12 +106,6 @@ QETApp::QETApp(int &argc, char **argv) : collections_cache_->setLocale(langFromSetting()); } - // loads known collections into memory (this does not include items rendering made in elements panels) - setSplashScreenStep(tr("Chargement... Lecture des collections d'éléments", "splash screen caption")); - foreach(ElementsCollection *collection, availableCollections()) { - collection -> reload(); - } - // on ouvre soit les fichiers passes en parametre soit un nouvel editeur de projet if (qet_arguments_.files().isEmpty()) { setSplashScreenStep(tr("Chargement... Éditeur de schéma", "splash screen caption")); @@ -139,8 +129,6 @@ QETApp::~QETApp() { delete about_dialog_; } delete qsti; - delete custom_collection; - delete common_collection; if (custom_tbt_collection_) delete custom_tbt_collection_; if (common_tbt_collection_) delete common_tbt_collection_; ElementFactory::dropInstance(); @@ -283,51 +271,6 @@ void QETApp::newElementEditor() { new QETElementEditor(); } -/** - @return la collection commune -*/ -ElementsCollection *QETApp::commonElementsCollection() { - if (!common_collection) { - common_collection = new FileElementsCollection(QETApp::commonElementsDir()); - common_collection -> setTitle(tr("Collection QET")); - common_collection -> setIcon(QIcon(":/ico/16x16/qet.png")); - common_collection -> setProtocol("common"); - common_collection -> setCache(collections_cache_); - } - return(common_collection); -} - -/** - @return la collection utilisateur -*/ -ElementsCollection *QETApp::customElementsCollection() { - if (!custom_collection) { - custom_collection = new FileElementsCollection(QETApp::customElementsDir()); - custom_collection -> setTitle(tr("Collection utilisateur")); - custom_collection -> setIcon(QIcon(":/ico/16x16/go-home.png")); - custom_collection -> setProtocol("custom"); - custom_collection -> setCache(collections_cache_); - } - return(custom_collection); -} - -/** - @return la liste des collections disponibles - Cela inclut typiquement la collection commune, la collection perso - ainsi que les collections embarquees dans les projets. -*/ -QList QETApp::availableCollections() { - QList coll_list; - - // collection commune - coll_list << commonElementsCollection(); - - // collection perso - coll_list << customElementsCollection(); - - return(coll_list); -} - /** @return the collection cache provided by the application itself. */ @@ -1666,102 +1609,6 @@ void QETApp::printLicense() { std::cout << qPrintable(QET::license()) << std::endl; } -//@TODO remove code below -///// Constructeur -//QETStyle::QETStyle() : QPlastiqueStyle() { -//} - -///// Destructeur -//QETStyle::~QETStyle() { -//} - -///// Gere les parametres de style -//int QETStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returndata) const { -// if (hint == QStyle::SH_DialogButtonBox_ButtonsHaveIcons) { -// return(int(true)); -// } else { -// return(QPlastiqueStyle::styleHint(hint, option, widget, returndata)); -// } -//} - -///// Gere les icones standard -//QIcon QETStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget* widget) const { -// switch(standardIcon) { -// case QStyle::SP_DialogSaveButton: -// return(QET::Icons::DocumentSave); -// case QStyle::SP_DialogOpenButton: -// return(QET::Icons::DocumentOpen); -// case QStyle::SP_DialogCancelButton: -// return(QET::Icons::DialogCancel); -// case QStyle::SP_DialogOkButton: -// case QStyle::SP_DialogApplyButton: -// return(QET::Icons::DialogOk); -// case QStyle::SP_DialogCloseButton: -// return(QET::Icons::DocumentClose); -// case QStyle::SP_DialogYesButton: -// return(QET::Icons::Allowed); -// case QStyle::SP_DialogNoButton: -// return(QET::Icons::Forbidden); -// case QStyle::SP_DialogResetButton: -// return(QET::Icons::EditUndo); -// case QStyle::SP_DialogHelpButton: -// case QStyle::SP_DialogDiscardButton: -// return(QIcon()); -// default: -// return(QPlastiqueStyle::standardIconImplementation(standardIcon, option, widget)); -// } -//} - -/** - @param location adresse virtuelle d'un item (collection, categorie, element, ...) - @param prefer_collections true pour renvoyer la collection lorsque le - chemin correspond aussi bien a une collection qu'a sa categorie racine - @return l'item correspondant a l'adresse virtuelle path, ou 0 si celui-ci n'a pas ete trouve -*/ -ElementsCollectionItem *QETApp::collectionItem(const ElementsLocation &location, bool prefer_collections) -{ - QString path(location.path()); - if (path.startsWith("common://")) { - return(common_collection -> item(path, prefer_collections)); - } else if (path.startsWith("custom://")) { - return(custom_collection -> item(path, prefer_collections)); - } - - return(0); -} - -/** - @param location adresse virtuelle de la categorie a creer - @return la categorie creee, ou 0 en cas d'echec -*/ -ElementsCategory *QETApp::createCategory(const ElementsLocation &location) -{ - QString path(location.path()); - if (path.startsWith("common://")) { - return(common_collection -> createCategory(path)); - } else if (path.startsWith("custom://")) { - return(custom_collection -> createCategory(path)); - } - - return(0); -} - -/** - @param location adresse virtuelle de l'element a creer - @return l'element cree, ou 0 en cas d'echec -*/ -ElementDefinition *QETApp::createElement(const ElementsLocation &location) -{ - QString path(location.path()); - if (path.startsWith("common://")) { - return(common_collection -> createElement(path)); - } else if (path.startsWith("custom://")) { - return(custom_collection -> createElement(path)); - } - - return(0); -} - /** @return la liste des projets avec leurs ids associes */ diff --git a/sources/qetapp.h b/sources/qetapp.h index cafdfac7a..4f1e283c2 100644 --- a/sources/qetapp.h +++ b/sources/qetapp.h @@ -30,12 +30,7 @@ class AboutQET; class QETDiagramEditor; class QETElementEditor; -class ElementsCollection; class ElementsCollectionCache; -class ElementsCollectionItem; -class FileElementsCollection; -class ElementsCategory; -class ElementDefinition; class TitleBlockTemplate; class TitleBlockTemplatesCollection; class TitleBlockTemplatesFilesCollection; @@ -67,12 +62,6 @@ class QETApp : public QETSingleApplication { static void printVersion(); static void printLicense(); - static ElementsCollectionItem *collectionItem(const ElementsLocation &, bool = true); - static ElementsCategory *createCategory(const ElementsLocation &); - static ElementDefinition *createElement(const ElementsLocation &); - static ElementsCollection *commonElementsCollection(); - static ElementsCollection *customElementsCollection(); - static QList availableCollections(); static ElementsCollectionCache *collectionCache(); static QStringList elementInfoKeys(); static QString elementTranslatedInfoKey(QString &); @@ -170,8 +159,6 @@ class QETApp : public QETSingleApplication { bool non_interactive_execution_; ///< Whether the application will end without any user interaction QPalette initial_palette_; ///< System color palette - static FileElementsCollection *common_collection; - static FileElementsCollection *custom_collection; static TitleBlockTemplatesFilesCollection *common_tbt_collection_; static TitleBlockTemplatesFilesCollection *custom_tbt_collection_; static ElementsCollectionCache *collections_cache_; @@ -236,19 +223,4 @@ class QETApp : public QETSingleApplication { static QETProject *projectFromString(const QString &); }; -//TODO remove code below -///** -// This class represents the custom QElectroTech style. -// It implements simple modification such as extra standard icons. -//*/ -//class QETStyle : public QPlastiqueStyle { -// Q_OBJECT -// public: -// QETStyle(); -// virtual ~QETStyle(); -// virtual int styleHint(StyleHint hint, const QStyleOption * = 0, const QWidget * = 0, QStyleHintReturn * = 0) const; - -// protected slots: -// virtual QIcon standardIconImplementation(StandardPixmap, const QStyleOption * = 0, const QWidget * = 0) const; -//}; #endif diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index b0ec2bf02..f6f8eea1e 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -2008,39 +2008,8 @@ void QETDiagramEditor::diagramWasAdded(DiagramView *dv) d'elements. */ void QETDiagramEditor::findElementInPanel(const ElementsLocation &location) { - bool element_found = pa -> elementsPanel().scrollToElement(location); - if (!element_found) { - // l'element n'a pas ete trouve - - ElementsCollectionItem *element = QETApp::collectionItem(location); - if (element) { - // mais il semble exister tout de meme - - // peut-etre vient-il d'un projet ouvert dans un autre editeur ? - if (location.project() && !findProject(location.project())) { - statusBar() -> showMessage( - tr("Impossible de retrouver cet élément dans le panel car il semble édité dans une autre fenêtre"), - 10000 - ); - } else { - // il devrait etre affiche : on tente de recharger le panel - statusBar() -> showMessage( - tr("Impossible de retrouver cet élément dans le panel... rechargement du panel..."), - 10000 - ); - pa -> reloadAndFilter(); - statusBar() -> clearMessage(); - element_found = pa -> elementsPanel().scrollToElement(location); - } - } - } - - if (!element_found) { - statusBar() -> showMessage( - tr("Impossible de retrouver cet élément dans le panel"), - 10000 - ); - } + //@TODO implement this method for the new element panel + Q_UNUSED (location); } /**