mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Added count() method to ElementsCollectionItem class and its subclasses.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1216 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -102,6 +102,8 @@ class ElementDefinition : public ElementsCollectionItem {
|
||||
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 *);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user