diff --git a/sources/elementscategorieslist.cpp b/sources/elementscategorieslist.cpp index f673d9b9c..5de4e01f0 100644 --- a/sources/elementscategorieslist.cpp +++ b/sources/elementscategorieslist.cpp @@ -66,7 +66,7 @@ void ElementsCategoriesList::reload() { foreach(ElementsCollection *collection, QETApp::availableCollections()) { if (collection == QETApp::commonElementsCollection()) continue; if (collection == QETApp::customElementsCollection()) continue; - addElementsCollection(collection, invisibleRootItem(), options, tr("Collection projet")) -> setExpanded(true); + addElementsCollection(collection, invisibleRootItem(), options) -> setExpanded(true); } // chargement des elements de la collection commune si droits d'ecriture @@ -74,9 +74,7 @@ void ElementsCategoriesList::reload() { addElementsCollection( QETApp::commonElementsCollection(), invisibleRootItem(), - options, - tr("Collection QET"), - QIcon(":/ico/16x16/qet.png") + options ) -> setExpanded(true); } @@ -84,9 +82,7 @@ void ElementsCategoriesList::reload() { addElementsCollection( QETApp::customElementsCollection(), invisibleRootItem(), - options, - tr("Collection utilisateur"), - QIcon(":/ico/16x16/go-home.png") + options ) -> setExpanded(true); if (first_load) first_load = false; diff --git a/sources/elementspanel.cpp b/sources/elementspanel.cpp index 6c508e3f8..ae9acaa62 100644 --- a/sources/elementspanel.cpp +++ b/sources/elementspanel.cpp @@ -399,10 +399,10 @@ QTreeWidgetItem *ElementsPanel::addProject(QETProject *project) { @param icon Icone a utiliser pour l'affichage de la collection @return Le QTreeWidgetItem insere le plus haut */ -QTreeWidgetItem *ElementsPanel::addCollection(ElementsCollection *collection, const QString &coll_name, const QIcon &icon) { +QTreeWidgetItem *ElementsPanel::addCollection(ElementsCollection *collection) { PanelOptions options = GenericPanel::AddAllChild; options |= GenericPanel::DisplayElementsPreview; - return(addElementsCollection(collection, invisibleRootItem(), options, coll_name, icon)); + return(addElementsCollection(collection, invisibleRootItem(), options)); } QTreeWidgetItem *ElementsPanel::updateTemplateItem(QTreeWidgetItem *tb_template_qtwi, const TitleBlockTemplateLocation &tb_template, PanelOptions options, bool freshly_created) { @@ -507,7 +507,7 @@ void ElementsPanel::reload(bool reload_collections) { // load the common elements collection if (QETApp::commonElementsCollection()->rootCategory()) { - common_collection_item_ = addCollection(QETApp::commonElementsCollection(), tr("Collection QET"), system_icon); + common_collection_item_ = addCollection(QETApp::commonElementsCollection()); if (first_reload_) common_collection_item_ -> setExpanded(true); } @@ -519,7 +519,7 @@ void ElementsPanel::reload(bool reload_collections) { // load the custom elements collection if (QETApp::customElementsCollection()->rootCategory()) { - custom_collection_item_ = addCollection(QETApp::customElementsCollection(), tr("Collection utilisateur"), user_icon); + custom_collection_item_ = addCollection(QETApp::customElementsCollection()); if (first_reload_) custom_collection_item_ -> setExpanded(true); } diff --git a/sources/elementspanel.h b/sources/elementspanel.h index 963b168a9..bd2c3b17b 100644 --- a/sources/elementspanel.h +++ b/sources/elementspanel.h @@ -92,7 +92,7 @@ class ElementsPanel : public GenericPanel { private: QTreeWidgetItem *addProject (QETProject *); - QTreeWidgetItem *addCollection(ElementsCollection *, const QString & = QString(), const QIcon & = QIcon()); + QTreeWidgetItem *addCollection(ElementsCollection *); QTreeWidgetItem *updateTemplateItem (QTreeWidgetItem *, const TitleBlockTemplateLocation &, PanelOptions, bool = false); QTreeWidgetItem *updateElementsCategoryItem(QTreeWidgetItem *, ElementsCategory *, PanelOptions, bool = false); QTreeWidgetItem *updateElementItem (QTreeWidgetItem *, ElementDefinition *, PanelOptions, bool = false); diff --git a/sources/genericpanel.cpp b/sources/genericpanel.cpp index dae104b76..6a6cf3388 100644 --- a/sources/genericpanel.cpp +++ b/sources/genericpanel.cpp @@ -276,8 +276,7 @@ QTreeWidgetItem *GenericPanel::fillProjectItem(QTreeWidgetItem *project_qtwi, QE addElementsCollection( project -> embeddedCollection(), project_qtwi, - options, - tr("Collection projet") + options ); } return(project_qtwi); @@ -544,14 +543,76 @@ QTreeWidgetItem *GenericPanel::fillTemplateItem(QTreeWidgetItem *tb_template_qtw 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 label Name displayed by the created QTreeWidgetItem - @param icon Icon displayed by the created QTreeWidgetItem @param options Control the creation of child items @return the created QTreeWidgetItem */ -QTreeWidgetItem *GenericPanel::addElementsCollection(ElementsCollection *collection, QTreeWidgetItem *parent_item, PanelOptions options, const QString &label, const QIcon &icon) { +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::itemForElementsCollection(ElementsCollection *collection) { + if (!collection) return(0); + return(elements_.value(collection -> rootCategory() -> location(), 0)); +} + +/** + +*/ +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(collection_qtwi); +} + +/** + +*/ +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; @@ -562,16 +623,13 @@ QTreeWidgetItem *GenericPanel::addElementsCollection(ElementsCollection *collect ElementsCollectionCache *cache = getElementsCache(); cache -> beginCollection(collection); - QTreeWidgetItem *collection_qtwi = addElementsCategory(collection -> rootCategory(), parent_item, options); + fillElementsCategoryItem(collection_qtwi, collection -> rootCategory(), options, freshly_created); cache -> endCollection(collection); - if (!label.isEmpty()) collection_qtwi -> setText(0, label); - if (!icon.isNull()) collection_qtwi -> setIcon(0, icon); // restore the former cache if (restore_previous_cache) { setElementsCache(previous_cache); } - return(collection_qtwi); } @@ -621,8 +679,7 @@ QTreeWidgetItem *GenericPanel::getItemForElementsCategory(ElementsCategory *cate return(category_item); } - QET::ItemType type = category -> isRootCategory() ? QET::ElementsCollection : QET::ElementsCategory; - category_item = makeItem(type); + category_item = makeItem(QET::ElementsCategory); if (created) *created = true; return(category_item); } @@ -852,12 +909,18 @@ void GenericPanel::templatesCollectionChanged(TitleBlockTemplatesCollection*coll void GenericPanel::diagramUsedTemplate(TitleBlockTemplatesCollection *collection, const QString &name) { Q_UNUSED(collection) Q_UNUSED(name) - qDebug() << Q_FUNC_INFO << name; addTemplatesCollection(collection); } /** +*/ +void GenericPanel::elementsCollectionChanged(ElementsCollection *collection) { + addElementsCollection(collection, 0, 0); +} + +/** + */ QString GenericPanel::defaultText(QET::ItemType type) { switch(type) { diff --git a/sources/genericpanel.h b/sources/genericpanel.h index 95e18c82e..9e4d5c674 100644 --- a/sources/genericpanel.h +++ b/sources/genericpanel.h @@ -127,8 +127,13 @@ class GenericPanel : public QTreeWidget { // elements collections methods public: - virtual QTreeWidgetItem *addElementsCollection(ElementsCollection *, QTreeWidgetItem *, PanelOptions = AddAllChild, const QString & = QString(), const QIcon & = QIcon()); virtual QTreeWidgetItem *itemForElementsLocation(const ElementsLocation &); + virtual QTreeWidgetItem *addElementsCollection(ElementsCollection *, QTreeWidgetItem *, PanelOptions = AddAllChild); + virtual QTreeWidgetItem *itemForElementsCollection(ElementsCollection *); + 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: @@ -157,6 +162,7 @@ class GenericPanel : public QTreeWidget { void diagramTitleChanged(Diagram *, const QString &); void templatesCollectionChanged(TitleBlockTemplatesCollection*, const QString &); void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &); + void elementsCollectionChanged(ElementsCollection *); // various other methods protected: