[qet] [1216] Added count() method to ElementsCollectionItem class and its subclasses. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 1216
Author: xavier
Date: 2011-03-15 19:32:52 +0100 (Tue, 15 Mar 2011)
Log Message:
-----------
Added count() method to ElementsCollectionItem class and its subclasses.
Modified Paths:
--------------
branches/0.3/sources/elementdefinition.cpp
branches/0.3/sources/elementdefinition.h
branches/0.3/sources/elementscategory.cpp
branches/0.3/sources/elementscategory.h
branches/0.3/sources/elementscollection.cpp
branches/0.3/sources/elementscollection.h
branches/0.3/sources/elementscollectionitem.h
Modified: branches/0.3/sources/elementdefinition.cpp
===================================================================
--- branches/0.3/sources/elementdefinition.cpp 2011-03-13 17:29:14 UTC (rev 1215)
+++ branches/0.3/sources/elementdefinition.cpp 2011-03-15 18:32:52 UTC (rev 1216)
@@ -176,6 +176,20 @@
}
/**
+ @return always true - an element contains nothing but itself
+*/
+bool ElementDefinition::isEmpty() {
+ return(false);
+}
+
+/**
+ @return always 1
+*/
+int ElementDefinition::count() {
+ return(1);
+}
+
+/**
@return toujours 0 - un element n'est pas une collection
*/
ElementsCollection *ElementDefinition::toCollection() {
Modified: branches/0.3/sources/elementdefinition.h
===================================================================
--- branches/0.3/sources/elementdefinition.h 2011-03-13 17:29:14 UTC (rev 1215)
+++ branches/0.3/sources/elementdefinition.h 2011-03-15 18:32:52 UTC (rev 1216)
@@ -102,6 +102,8 @@
virtual QList<ElementDefinition *> elements();
virtual ElementDefinition *element(const QString &);
virtual ElementDefinition *createElement(const QString &);
+ virtual bool isEmpty();
+ virtual int count();
virtual ElementsCollectionItem *copy(ElementsCategory *, MoveElementsHandler *, bool = true);
virtual ElementsCollectionItem *move(ElementsCategory *, MoveElementsHandler *);
Modified: branches/0.3/sources/elementscategory.cpp
===================================================================
--- branches/0.3/sources/elementscategory.cpp 2011-03-13 17:29:14 UTC (rev 1215)
+++ branches/0.3/sources/elementscategory.cpp 2011-03-15 18:32:52 UTC (rev 1216)
@@ -616,6 +616,17 @@
}
/**
+ @return the count of categories and elements within this collection
+*/
+int ElementsCategory::count() {
+ int items_count = elements().count();
+ foreach(ElementsCategory *category, categories()) {
+ items_count += category -> count();
+ }
+ return(items_count);
+}
+
+/**
Methode permettant d'obtenir le nom affichable de cette categorie.
@return Le nom affichable de la categorie
*/
Modified: branches/0.3/sources/elementscategory.h
===================================================================
--- branches/0.3/sources/elementscategory.h 2011-03-13 17:29:14 UTC (rev 1215)
+++ branches/0.3/sources/elementscategory.h 2011-03-15 18:32:52 UTC (rev 1216)
@@ -65,6 +65,7 @@
virtual void deleteUnusedElements(MoveElementsHandler *handler);
virtual void deleteEmptyCategories(MoveElementsHandler *handler);
virtual bool isEmpty();
+ virtual int count();
// Methodes propres a la classe ElementsCategory
public:
Modified: branches/0.3/sources/elementscollection.cpp
===================================================================
--- branches/0.3/sources/elementscollection.cpp 2011-03-13 17:29:14 UTC (rev 1215)
+++ branches/0.3/sources/elementscollection.cpp 2011-03-15 18:32:52 UTC (rev 1216)
@@ -379,6 +379,15 @@
}
/**
+ @return the count of categories and elements within this collection
+*/
+int ElementsCollection::count() {
+ ElementsCategory *root_category = rootCategory();
+ if (!root_category) return(0);
+ return(root_category -> count());
+}
+
+/**
@param item_path chemin d'un item sous la forme d'une adresse
virtuelle comme common://cat1/cat2/cat3
@param prefer_collections true pour renvoyer la collection lorsque le
@@ -404,3 +413,4 @@
return(result);
}
+
Modified: branches/0.3/sources/elementscollection.h
===================================================================
--- branches/0.3/sources/elementscollection.h 2011-03-13 17:29:14 UTC (rev 1215)
+++ branches/0.3/sources/elementscollection.h 2011-03-15 18:32:52 UTC (rev 1216)
@@ -73,6 +73,7 @@
virtual ElementDefinition *element(const QString &);
virtual ElementDefinition *createElement(const QString &);
virtual bool isEmpty();
+ virtual int count();
// Methodes propres a la classe ElementsCollection
public:
Modified: branches/0.3/sources/elementscollectionitem.h
===================================================================
--- branches/0.3/sources/elementscollectionitem.h 2011-03-13 17:29:14 UTC (rev 1215)
+++ branches/0.3/sources/elementscollectionitem.h 2011-03-15 18:32:52 UTC (rev 1216)
@@ -202,5 +202,13 @@
@return un nouvel element cree a partir d'un chemin virtuel
*/
virtual ElementDefinition *createElement(const QString &) = 0;
+ /**
+ @return true if the item is empty, false otherwise
+ */
+ virtual bool isEmpty() = 0;
+ /**
+ @return the count of categories and elements within this item
+ */
+ virtual int count() = 0;
};
#endif