So, here's my item:
class treeNodeClient
{
public:
treeNodeClient
(treeNodeClient
*parentnode
= 0,
int pid
= 0,
const QString &pname
= "",
const QString &pphone
= "",
const bool &phaschildren = false);
~treeNodeClient();
int id;
bool haschildren; // true if node can have children. but we don't know how many yet
int row() const;
treeNodeClient *parent;
QList<treeNodeClient*> children;
};
class treeNodeClient
{
public:
treeNodeClient(treeNodeClient *parentnode = 0, int pid = 0, const QString &pname = "", const QString &pphone = "",
const QString &pemail = "", const QString &preferal = "",
const bool &phaschildren = false);
~treeNodeClient();
int id;
QString name;
QString phone;
QString email;
QString referal;
bool haschildren; // true if node can have children. but we don't know how many yet
int row() const;
treeNodeClient *parent;
QList<treeNodeClient*> children;
};
To copy to clipboard, switch view to plain text mode
Model:
{
public:
~modelClients();
int columnCount
(const QModelIndex & /* parent */) const;
QVariant headerData
(int section, Qt
::Orientation orientation,
int role
) const;
bool canFetchMore
( const QModelIndex & parent
) const ;
treeNodeClient *rootNode; // root node is created in constructor, is newer shown in treeview
};
class modelClients: public QAbstractItemModel
{
public:
modelClients(QObject *parent = 0);
~modelClients();
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex & /* parent */) const;
QVariant data(const QModelIndex &index, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QModelIndex index(int row, int column, const QModelIndex &parent) const;
QModelIndex parent(const QModelIndex &index) const;
bool hasChildren ( const QModelIndex & parent = QModelIndex() ) const;
bool canFetchMore ( const QModelIndex & parent ) const ;
treeNodeClient *rootNode; // root node is created in constructor, is newer shown in treeview
};
To copy to clipboard, switch view to plain text mode
Functions:
int modelClients
::rowCount(const QModelIndex &parent
) const {
treeNodeClient *parentNode;
if (!parent.isValid()) parentNode = rootNode;
else parentNode = static_cast<treeNodeClient*>(parent.internalPointer());
return parentNode->children.count();
}
bool modelClients
::hasChildren ( const QModelIndex & parent
) const {
if (!parent.isValid()) return false;
treeNodeClient *node = static_cast<treeNodeClient*>(parent.internalPointer());
return node->haschildren;
}
int modelClients::rowCount(const QModelIndex &parent) const
{
treeNodeClient *parentNode;
if (!parent.isValid()) parentNode = rootNode;
else parentNode = static_cast<treeNodeClient*>(parent.internalPointer());
return parentNode->children.count();
}
bool modelClients::hasChildren ( const QModelIndex & parent ) const
{
if (!parent.isValid()) return false;
treeNodeClient *node = static_cast<treeNodeClient*>(parent.internalPointer());
return node->haschildren;
}
To copy to clipboard, switch view to plain text mode
I can't imagine what to write in canFetchMore and fetchMore
Bookmarks