Slightly faster version of hasChildren

master
Jos van den Oever 2017-08-14 21:57:59 +02:00
parent 796f5a87b6
commit ae4d9fc89d
5 changed files with 29 additions and 0 deletions

View File

@ -164,6 +164,11 @@ int Directory::columnCount(const QModelIndex &parent) const
return (parent.isValid()) ? 0 : 3;
}
bool Directory::hasChildren(const QModelIndex &parent) const
{
return rowCount(parent) > 0;
}
int Directory::rowCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : directory_row_count(d);
@ -303,6 +308,11 @@ int TestTree::columnCount(const QModelIndex &) const
return 3;
}
bool TestTree::hasChildren(const QModelIndex &parent) const
{
return rowCount(parent) > 0;
}
int TestTree::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0) {

View File

@ -52,6 +52,7 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
bool canFetchMore(const QModelIndex &parent) const;
void fetchMore(const QModelIndex &parent);
@ -80,6 +81,7 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
bool canFetchMore(const QModelIndex &parent) const;
void fetchMore(const QModelIndex &parent);

View File

@ -109,6 +109,11 @@ int Tree::columnCount(const QModelIndex &) const
return 5;
}
bool Tree::hasChildren(const QModelIndex &parent) const
{
return rowCount(parent) > 0;
}
int Tree::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0) {

View File

@ -21,6 +21,7 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
bool canFetchMore(const QModelIndex &parent) const;
void fetchMore(const QModelIndex &parent);

View File

@ -276,6 +276,7 @@ void writeHeaderItemModel(QTextStream& h, const Object&) {
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
bool canFetchMore(const QModelIndex &parent) const;
void fetchMore(const QModelIndex &parent);
@ -315,6 +316,11 @@ int %1::columnCount(const QModelIndex &parent) const
return (parent.isValid()) ? 0 : %3;
}
bool %1::hasChildren(const QModelIndex &parent) const
{
return rowCount(parent) > 0;
}
int %1::rowCount(const QModelIndex &parent) const
{
return (parent.isValid()) ? 0 : %2_row_count(d);
@ -358,6 +364,11 @@ int %1::columnCount(const QModelIndex &) const
return %3;
}
bool %1::hasChildren(const QModelIndex &parent) const
{
return rowCount(parent) > 0;
}
int %1::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() && parent.column() != 0) {