diff --git a/sources/elementdefinition.cpp b/sources/elementdefinition.cpp index 79566b93b..d0ddcd139 100644 --- a/sources/elementdefinition.cpp +++ b/sources/elementdefinition.cpp @@ -175,6 +175,20 @@ ElementDefinition *ElementDefinition::createElement(const QString &) { return(0); } +/** + @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 */ diff --git a/sources/elementdefinition.h b/sources/elementdefinition.h index 757d2c613..6d542439f 100644 --- a/sources/elementdefinition.h +++ b/sources/elementdefinition.h @@ -102,6 +102,8 @@ class ElementDefinition : public ElementsCollectionItem { virtual QList 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 *); diff --git a/sources/elementscategory.cpp b/sources/elementscategory.cpp index 1cb310bbd..ba610352d 100644 --- a/sources/elementscategory.cpp +++ b/sources/elementscategory.cpp @@ -615,6 +615,17 @@ bool ElementsCategory::isEmpty() { return(categories().count() || elements().count()); } +/** + @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 diff --git a/sources/elementscategory.h b/sources/elementscategory.h index 19f57b91b..b714008e2 100644 --- a/sources/elementscategory.h +++ b/sources/elementscategory.h @@ -65,6 +65,7 @@ class ElementsCategory : public ElementsCollectionItem { virtual void deleteUnusedElements(MoveElementsHandler *handler); virtual void deleteEmptyCategories(MoveElementsHandler *handler); virtual bool isEmpty(); + virtual int count(); // Methodes propres a la classe ElementsCategory public: diff --git a/sources/elementscollection.cpp b/sources/elementscollection.cpp index a0eb12de3..f6860bbda 100644 --- a/sources/elementscollection.cpp +++ b/sources/elementscollection.cpp @@ -378,6 +378,15 @@ bool ElementsCollection::isEmpty() { return(root_category -> isEmpty()); } +/** + @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 @@ -404,3 +413,4 @@ ElementsCollectionItem *ElementsCollection::item(const QString &item_path, bool return(result); } + diff --git a/sources/elementscollection.h b/sources/elementscollection.h index 9e61b9923..98b9ae851 100644 --- a/sources/elementscollection.h +++ b/sources/elementscollection.h @@ -73,6 +73,7 @@ class ElementsCollection : public ElementsCollectionItem { virtual ElementDefinition *element(const QString &); virtual ElementDefinition *createElement(const QString &); virtual bool isEmpty(); + virtual int count(); // Methodes propres a la classe ElementsCollection public: diff --git a/sources/elementscollectionitem.h b/sources/elementscollectionitem.h index 258e9833e..eb5ebbc80 100644 --- a/sources/elementscollectionitem.h +++ b/sources/elementscollectionitem.h @@ -202,5 +202,13 @@ class ElementsCollectionItem : public QObject { @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