Commit c1be554f authored by Ahmad Samir's avatar Ahmad Samir Committed by Christoph Cullmann
Browse files

KateFileTree: general code clean-up

- Store pointers to the proxy and source models, less casting
- Add some convenience methods, less code duplication
- Remove QVariant::isValid() checks, QVariant::value() will return a
  default contructed/empty QList if the conversion/cast fails anyway
- Initialize a member
parent 3f603590
This diff is collapsed.
......@@ -18,6 +18,9 @@ class Document;
class QActionGroup;
class KateFileTreeModel;
class KateFileTreeProxyModel;
class KateFileTree : public QTreeView
{
Q_OBJECT
......@@ -85,6 +88,8 @@ private:
const Func &slot,
Qt::CheckState checked = Qt::Unchecked);
void addChildrenTolist(const QModelIndex &index, QList<QPersistentModelIndex> *worklist);
QAction *m_filelistCloseDocument;
QAction *m_filelistExpandRecursive;
QAction *m_filelistCollapseRecursive;
......@@ -105,10 +110,12 @@ private:
QAction *m_sortByOpeningOrder;
QAction *m_resetHistory;
KateFileTreeProxyModel *m_proxyModel = nullptr;
KateFileTreeModel *m_sourceModel = nullptr;
QPersistentModelIndex m_previouslySelected;
QPersistentModelIndex m_indexContextMenu;
bool m_hasCloseButton;
bool m_hasCloseButton = false;
};
#endif // KATE_FILETREE_H
......@@ -22,6 +22,16 @@ void KateFileTreeProxyModel::setSourceModel(QAbstractItemModel *model)
QSortFilterProxyModel::setSourceModel(model);
}
KTextEditor::Document *KateFileTreeProxyModel::docFromIndex(const QModelIndex &index)
{
return data(index, KateFileTreeModel::DocumentRole).value<KTextEditor::Document *>();
}
QList<KTextEditor::Document *> KateFileTreeProxyModel::docTreeFromIndex(const QModelIndex &index)
{
return data(index, KateFileTreeModel::DocumentTreeRole).value<QList<KTextEditor::Document *>>();
}
bool KateFileTreeProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
const KateFileTreeModel *model = static_cast<KateFileTreeModel *>(sourceModel());
......
......@@ -23,6 +23,8 @@ public:
QModelIndex docIndex(const KTextEditor::Document *) const;
bool isDir(const QModelIndex &i) const;
void setSourceModel(QAbstractItemModel *model) override;
KTextEditor::Document *docFromIndex(const QModelIndex &index);
QList<KTextEditor::Document *> docTreeFromIndex(const QModelIndex &index);
protected:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment