29 QList<QVariant> rootData;
51 const QModelIndex& parent)
const
53 if (!hasIndex(row, column,
parent))
72 return createIndex(row, column, childItem);
88 auto* childItem =
static_cast<TreeItem*
>(
index.internalPointer());
96 return createIndex(parentItem->
row(), 0, parentItem);
144 if (!
index.isValid())
149 if (role == Qt::EditRole || role == Qt::DisplayRole)
151 auto* item =
static_cast<TreeItem*
>(
index.internalPointer());
162 if (!
index.isValid())
167 if (role == Qt::EditRole)
169 auto* item =
static_cast<TreeItem*
>(
index.internalPointer());
177 if (!
index.isValid())
179 return Qt::NoItemFlags;
182 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
192 auto* item =
static_cast<TreeItem*
>(
index.internalPointer());
204 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
220 beginRemoveRows(
parent, position, position + count - 1);
232 QList<TreeItem*> parents;
233 QList<int> indentations;
239 while (number < lines.count())
242 while (position < lines[number].length())
244 if (lines[number].mid(position, 1) !=
" ")
251 QString lineData = lines[number].mid(position).trimmed();
253 if (!lineData.isEmpty())
256 QStringList columnStrings =
257 lineData.split(
"\t", Qt::SkipEmptyParts);
258 QList<QVariant> columnData;
259 for (
int column = 0; column < columnStrings.count(); ++column)
261 columnData << columnStrings[column];
264 if (position > indentations.last())
269 if (parents.last()->childCount() > 0)
271 parents << parents.last()->child(
272 parents.last()->childCount() - 1);
273 indentations << position;
278 while (position < indentations.last() && parents.count() > 0)
281 indentations.pop_back();
286 parents.last()->appendChild(
287 new TreeItem(columnData, parents.last()));
Definition of the TreeItem class.
Definition of the TreeModel class.
Objects nodes for the TreeModel.
virtual int childCount() const
virtual int columnCount() const
TreeItem * parentItem() const
TreeItem * child(int row) const
bool removeChildren(int position, int count)
virtual bool setData(int column, const QVariant &value)
virtual QVariant data(int column) const
void setupModelData(const QStringList &lines, TreeItem *parent)
bool removeRows(int position, int count, const QModelIndex &parent) override
TreeItem * getItem(const QModelIndex &index) const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
QModelIndex parent(const QModelIndex &index) const override
TreeItem * rootItem() const
TreeModel(QObject *parent=nullptr)
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Qt::ItemFlags flags(const QModelIndex &index) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override