DependencyModel: Modernize connections

Change-Id: Ie1eb9802907da2bf82c40dcbf5ce86855540cbbd
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
hjk
2016-01-20 09:56:02 +01:00
parent fe944e47e7
commit ee87ff4a87
2 changed files with 25 additions and 27 deletions

View File

@@ -52,13 +52,13 @@ DependenciesModel::DependenciesModel(Project *project, QObject *parent)
// We can't select ourselves as a dependency
m_projects.removeAll(m_project);
QObject *sessionManager = SessionManager::instance();
connect(sessionManager, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(resetModel()));
connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
this, SLOT(resetModel()));
connect(sessionManager, SIGNAL(sessionLoaded(QString)),
this, SLOT(resetModel()));
SessionManager *sessionManager = SessionManager::instance();
connect(sessionManager, &SessionManager::projectRemoved,
this, &DependenciesModel::resetModel);
connect(sessionManager, &SessionManager::projectAdded,
this, &DependenciesModel::resetModel);
connect(sessionManager, &SessionManager::sessionLoaded,
this, &DependenciesModel::resetModel);
// qDebug()<<"Dependencies Model"<<this<<"for project"<<project<<"("<<project->file()->fileName()<<")";
}
@@ -157,27 +157,27 @@ QSize DependenciesView::sizeHint() const
void DependenciesView::setModel(QAbstractItemModel *newModel)
{
if (QAbstractItemModel *oldModel = model()) {
disconnect(oldModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(updateSizeHint()));
disconnect(oldModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(updateSizeHint()));
disconnect(oldModel, SIGNAL(modelReset()),
this, SLOT(updateSizeHint()));
disconnect(oldModel, SIGNAL(layoutChanged()),
this, SLOT(updateSizeHint()));
disconnect(oldModel, &QAbstractItemModel::rowsInserted,
this, &DependenciesView::updateSizeHint);
disconnect(oldModel, &QAbstractItemModel::rowsRemoved,
this, &DependenciesView::updateSizeHint);
disconnect(oldModel, &QAbstractItemModel::modelReset,
this, &DependenciesView::updateSizeHint);
disconnect(oldModel, &QAbstractItemModel::layoutChanged,
this, &DependenciesView::updateSizeHint);
}
QTreeView::setModel(newModel);
if (newModel) {
connect(newModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
this, SLOT(updateSizeHint()));
connect(newModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
this, SLOT(updateSizeHint()));
connect(newModel, SIGNAL(modelReset()),
this, SLOT(updateSizeHint()));
connect(newModel, SIGNAL(layoutChanged()),
this, SLOT(updateSizeHint()));
connect(newModel, &QAbstractItemModel::rowsInserted,
this, &DependenciesView::updateSizeHint);
connect(newModel, &QAbstractItemModel::rowsRemoved,
this, &DependenciesView::updateSizeHint);
connect(newModel, &QAbstractItemModel::modelReset,
this, &DependenciesView::updateSizeHint);
connect(newModel, &QAbstractItemModel::layoutChanged,
this, &DependenciesView::updateSizeHint);
}
updateSizeHint();
}

View File

@@ -59,10 +59,9 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
Qt::ItemFlags flags(const QModelIndex &index) const;
public slots:
private:
void resetModel();
private:
Project *m_project;
QList<Project *> m_projects;
};
@@ -77,10 +76,9 @@ public:
QSize sizeHint() const;
void setModel(QAbstractItemModel *model);
private slots:
private:
void updateSizeHint();
private:
QSize m_sizeHint;
};