Commit aabdc242 authored by hjk's avatar hjk
Browse files

ProjectTree: Use signals to communicate change from FlatModel to view



Better encapsulation and potentially more than one view on the model.

Change-Id: I45657484a68eba61b3987d324cf1542704ffd61c
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
parent f7a77869
......@@ -89,14 +89,6 @@ FlatModel::FlatModel(QObject *parent)
update();
}
void FlatModel::setView(QTreeView *view)
{
QTC_CHECK(!m_view);
m_view = view;
connect(m_view, &QTreeView::expanded, this, &FlatModel::onExpanded);
connect(m_view, &QTreeView::collapsed, this, &FlatModel::onCollapsed);
}
QVariant FlatModel::data(const QModelIndex &index, int role) const
{
QVariant result;
......@@ -221,7 +213,7 @@ void FlatModel::rebuildModel()
const QString displayName = node->m_node->displayName();
ExpandData ed(path, displayName);
if (m_toExpand.contains(ed))
m_view->expand(node->index());
emit requestExpansion(node->index());
});
}
......
......@@ -59,8 +59,6 @@ class FlatModel : public Utils::TreeModel<WrapperNode, WrapperNode>
public:
FlatModel(QObject *parent);
void setView(QTreeView *view);
// QAbstractItemModel
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
......@@ -79,8 +77,12 @@ public:
void setProjectFilterEnabled(bool filter);
void setGeneratedFilesFilterEnabled(bool filter);
void onExpanded(const QModelIndex &idx);
void onCollapsed(const QModelIndex &idx);
signals:
void renamed(const Utils::FileName &oldName, const Utils::FileName &newName);
void requestExpansion(const QModelIndex &index);
private:
void nodeUpdated(ProjectExplorer::Node *node);
......@@ -99,14 +101,11 @@ private:
void addFolderNode(WrapperNode *parent, FolderNode *folderNode, QSet<Node *> *seen);
ExpandData expandDataForNode(const Node *node) const;
void onExpanded(const QModelIndex &idx);
void onCollapsed(const QModelIndex &idx);
void loadExpandData();
void saveExpandData();
void handleProjectAdded(Project *project);
QTimer m_timer;
QTreeView *m_view = nullptr;
QSet<ExpandData> m_toExpand;
};
......
......@@ -175,7 +175,6 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent) : QWidget(parent)
m_view->setItemDelegate(new ProjectTreeItemDelegate(this));
setFocusProxy(m_view);
m_view->installEventFilter(this);
m_model->setView(m_view);
auto layout = new QVBoxLayout();
layout->addWidget(ItemViewFind::createSearchableWrapper(
......@@ -198,12 +197,18 @@ ProjectTreeWidget::ProjectTreeWidget(QWidget *parent) : QWidget(parent)
// connections
connect(m_model, &FlatModel::renamed,
this, &ProjectTreeWidget::renamed);
connect(m_model, &FlatModel::requestExpansion,
m_view, &QTreeView::expand);
connect(m_view, &QAbstractItemView::activated,
this, &ProjectTreeWidget::openItem);
connect(m_view->selectionModel(), &QItemSelectionModel::currentChanged,
this, &ProjectTreeWidget::handleCurrentItemChange);
connect(m_view, &QWidget::customContextMenuRequested,
this, &ProjectTreeWidget::showContextMenu);
connect(m_view, &QTreeView::expanded,
m_model, &FlatModel::onExpanded);
connect(m_view, &QTreeView::collapsed,
m_model, &FlatModel::onCollapsed);
m_toggleSync = new QToolButton;
m_toggleSync->setIcon(Utils::Icons::LINK.icon());
......
Markdown is supported
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