[qet] [1492] GenericPanel and its subclasses now use the title and icon provided by collections .

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1492
Author:   xavier
Date:     2012-02-06 23:34:52 +0100 (Mon, 06 Feb 2012)
Log Message:
-----------
GenericPanel and its subclasses now use the title and icon provided by collections.

Modified Paths:
--------------
    branches/0.3/sources/elementscategorieslist.cpp
    branches/0.3/sources/elementspanel.cpp
    branches/0.3/sources/elementspanel.h
    branches/0.3/sources/genericpanel.cpp
    branches/0.3/sources/genericpanel.h

Modified: branches/0.3/sources/elementscategorieslist.cpp
===================================================================
--- branches/0.3/sources/elementscategorieslist.cpp	2012-02-06 22:13:39 UTC (rev 1491)
+++ branches/0.3/sources/elementscategorieslist.cpp	2012-02-06 22:34:52 UTC (rev 1492)
@@ -66,7 +66,7 @@
 	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 @@
 		addElementsCollection(
 			QETApp::commonElementsCollection(),
 			invisibleRootItem(),
-			options,
-			tr("Collection QET"),
-			QIcon(":/ico/16x16/qet.png")
+			options
 		) -> setExpanded(true);
 	}
 	
@@ -84,9 +82,7 @@
 	addElementsCollection(
 		QETApp::customElementsCollection(),
 		invisibleRootItem(),
-		options,
-		tr("Collection utilisateur"),
-		QIcon(":/ico/16x16/go-home.png")
+		options
 	) -> setExpanded(true);
 	
 	if (first_load) first_load = false;

Modified: branches/0.3/sources/elementspanel.cpp
===================================================================
--- branches/0.3/sources/elementspanel.cpp	2012-02-06 22:13:39 UTC (rev 1491)
+++ branches/0.3/sources/elementspanel.cpp	2012-02-06 22:34:52 UTC (rev 1492)
@@ -399,10 +399,10 @@
 	@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 @@
 	
 	// 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 @@
 	
 	// 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);
 	}
 	

Modified: branches/0.3/sources/elementspanel.h
===================================================================
--- branches/0.3/sources/elementspanel.h	2012-02-06 22:13:39 UTC (rev 1491)
+++ branches/0.3/sources/elementspanel.h	2012-02-06 22:34:52 UTC (rev 1492)
@@ -92,7 +92,7 @@
 	
 	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);

Modified: branches/0.3/sources/genericpanel.cpp
===================================================================
--- branches/0.3/sources/genericpanel.cpp	2012-02-06 22:13:39 UTC (rev 1491)
+++ branches/0.3/sources/genericpanel.cpp	2012-02-06 22:34:52 UTC (rev 1492)
@@ -276,8 +276,7 @@
 		addElementsCollection(
 			project -> embeddedCollection(),
 			project_qtwi,
-			options,
-			tr("Collection projet")
+			options
 		);
 	}
 	return(project_qtwi);
@@ -544,14 +543,76 @@
 	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 @@
 	
 	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 @@
 		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,13 +909,19 @@
 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) {
 		case QET::ElementsCollectionItem:

Modified: branches/0.3/sources/genericpanel.h
===================================================================
--- branches/0.3/sources/genericpanel.h	2012-02-06 22:13:39 UTC (rev 1491)
+++ branches/0.3/sources/genericpanel.h	2012-02-06 22:34:52 UTC (rev 1492)
@@ -127,8 +127,13 @@
 	
 	// 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 @@
 	void diagramTitleChanged(Diagram *, const QString &);
 	void templatesCollectionChanged(TitleBlockTemplatesCollection*, const QString &);
 	void diagramUsedTemplate(TitleBlockTemplatesCollection *, const QString &);
+	void elementsCollectionChanged(ElementsCollection *);
 	
 	// various other methods
 	protected:


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/