I have 2 doubts ,
1. Do I need to derive my all classes system,SytemDatabase and CoresData from QAbstractItemModel .
2. Or Do i need to write like here in the example https://doc.qt.io/qt-5/qtwidgets-ite...l-example.html. please find the below code as per the example
class CoresData {
public:
CoresData();
~CoresData();
void appendChild(CoresData *child);
CoresData *child(int row);
int childCount() const;
int columnCount() const;
int row() const;
CoresData *parentItem();
int m_iCoreSpeed;
bool m_bCoreAvailable;
int m_iCoreNumber;
private:
CoresData *m_parentItem;
};
class SytemDatabase {
public:
SytemDatabase();
~SytemDatabase();
void appendChild(SytemDatabase *child);
SytemDatabase *child(int row);
int childCount() const;
int columnCount() const;
int row() const;
SytemDatabase *parentItem();
bool m_bDatabaseVisible;
int m_iDatabaseNumber;
private:
QVector<SytemDatabase*> m_childItems;
SytemDatabase *m_parentItem;
QList<CoresData> m_listCoresData;
};
class Sytem {
public:
Sytem();
~Sytem();
void appendChild(Sytem *child);
Sytem *child(int row);
int childCount() const;
int columnCount() const;
int row() const;
Sytem *parentItem();
bool m_bSystemAvailable;
int m_iSystemNumber;
private:
QVector<Sytem*> m_childItems;
Sytem *m_parentItem;
QList<SytemDatabase> m_listSytemDatabase;
};
Q_OBJECT
public:
explicit SytemTree
( QObject *parent
= nullptr
);
~SytemTree();
Qt
::ItemFlags flags
(const QModelIndex &index
) const override;
QVariant headerData
(int section, Qt
::Orientation orientation,
int role
= Qt
::DisplayRole) const override;
private:
void addSytemDatabase(Sytem &data);
QList<Sytem> m_listSystem;
};
class CoresData {
public:
CoresData();
~CoresData();
void appendChild(CoresData *child);
CoresData *child(int row);
int childCount() const;
int columnCount() const;
QVariant data(int column) const;
int row() const;
CoresData *parentItem();
int m_iCoreSpeed;
bool m_bCoreAvailable;
int m_iCoreNumber;
private:
CoresData *m_parentItem;
};
class SytemDatabase {
public:
SytemDatabase();
~SytemDatabase();
void appendChild(SytemDatabase *child);
SytemDatabase *child(int row);
int childCount() const;
int columnCount() const;
QVariant data(int column) const;
int row() const;
SytemDatabase *parentItem();
bool m_bDatabaseVisible;
int m_iDatabaseNumber;
private:
QVector<SytemDatabase*> m_childItems;
SytemDatabase *m_parentItem;
QList<CoresData> m_listCoresData;
};
class Sytem {
public:
Sytem();
~Sytem();
void appendChild(Sytem *child);
Sytem *child(int row);
int childCount() const;
int columnCount() const;
QVariant data(int column) const;
int row() const;
Sytem *parentItem();
bool m_bSystemAvailable;
int m_iSystemNumber;
private:
QVector<Sytem*> m_childItems;
Sytem *m_parentItem;
QList<SytemDatabase> m_listSytemDatabase;
};
class SytemTree : public QAbstractItemModel {
Q_OBJECT
public:
explicit SytemTree( QObject *parent = nullptr);
~SytemTree();
QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
private:
void addSytemDatabase(Sytem &data);
QList<Sytem> m_listSystem;
};
To copy to clipboard, switch view to plain text mode
because i need to consider this model usage in qml i.e
--
model: System
-----
model: SytemTree.get(index).SytemDatabase
-----
model: SytemTree.get(index).SytemDatabase.get(index).CoresData
----
--
model: System
-----
model: SytemTree.get(index).SytemDatabase
-----
model: SytemTree.get(index).SytemDatabase.get(index).CoresData
----
To copy to clipboard, switch view to plain text mode
and also in the 2nd doubt, how to handle this pointer m_parentItem?? Since different level of tree is having different structure
Bookmarks