Commit 9fe97068 authored by hjk's avatar hjk

ProjectExplorer: Clean up remaining SessionManager uses

Change-Id: I170edc81cc2bcb4de4168c5ec38d3897c2e7c7e8
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 01266723
......@@ -46,34 +46,28 @@
namespace ProjectExplorer {
namespace Internal {
DependenciesModel::DependenciesModel(SessionManager *session,
Project *project,
QObject *parent)
DependenciesModel::DependenciesModel(Project *project, QObject *parent)
: QAbstractListModel(parent)
, m_session(session)
, m_project(project)
, m_projects(session->projects())
, m_projects(SessionManager::projects())
{
// We can't select ourselves as a dependency
m_projects.removeAll(m_project);
connect(session, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
QObject *sessionManager = SessionManager::instance();
connect(sessionManager, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(resetModel()));
connect(session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
this, SLOT(resetModel()));
connect(session, SIGNAL(sessionLoaded(QString)),
connect(sessionManager, SIGNAL(sessionLoaded(QString)),
this, SLOT(resetModel()));
// qDebug()<<"Dependencies Model"<<this<<"for project"<<project<<"("<<project->file()->fileName()<<")";
}
DependenciesModel::~DependenciesModel()
{
// qDebug()<<"~DependenciesModel"<<this;
}
void DependenciesModel::resetModel()
{
beginResetModel();
m_projects = m_session->projects();
m_projects = SessionManager::projects();
m_projects.removeAll(m_project);
endResetModel();
}
......@@ -101,7 +95,7 @@ QVariant DependenciesModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
return p->displayName();
case Qt::CheckStateRole:
return m_session->hasDependency(m_project, p) ? Qt::Checked : Qt::Unchecked;
return SessionManager::hasDependency(m_project, p) ? Qt::Checked : Qt::Unchecked;
case Qt::DecorationRole:
return Core::FileIconProvider::instance()->icon(QFileInfo(p->projectFilePath()));
default:
......@@ -116,7 +110,7 @@ bool DependenciesModel::setData(const QModelIndex &index, const QVariant &value,
const Qt::CheckState c = static_cast<Qt::CheckState>(value.toInt());
if (c == Qt::Checked) {
if (m_session->addDependency(m_project, p)) {
if (SessionManager::addDependency(m_project, p)) {
emit dataChanged(index, index);
return true;
} else {
......@@ -124,8 +118,8 @@ bool DependenciesModel::setData(const QModelIndex &index, const QVariant &value,
QCoreApplication::translate("DependenciesModel", "This would create a circular dependency."));
}
} else if (c == Qt::Unchecked) {
if (m_session->hasDependency(m_project, p)) {
m_session->removeDependency(m_project, p);
if (SessionManager::hasDependency(m_project, p)) {
SessionManager::removeDependency(m_project, p);
emit dataChanged(index, index);
return true;
}
......@@ -157,11 +151,6 @@ DependenciesView::DependenciesView(QWidget *parent)
setRootIsDecorated(false);
}
DependenciesView::~DependenciesView()
{
}
QSize DependenciesView::sizeHint() const
{
return m_sizeHint;
......@@ -219,13 +208,10 @@ void DependenciesView::updateSizeHint()
// DependenciesWidget
//
DependenciesWidget::DependenciesWidget(SessionManager *session,
Project *project,
QWidget *parent)
DependenciesWidget::DependenciesWidget(Project *project, QWidget *parent)
: QWidget(parent)
, m_session(session)
, m_project(project)
, m_model(new DependenciesModel(session, project, this))
, m_model(new DependenciesModel(project, this))
{
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setContentsMargins(0, 0, 0, 0);
......@@ -248,14 +234,9 @@ DependenciesWidget::DependenciesWidget(SessionManager *session,
// DependenciesPanelFactory
//
DependenciesPanelFactory::DependenciesPanelFactory(SessionManager *session)
: m_session(session)
{
}
QString DependenciesPanelFactory::id() const
{
return QLatin1String(DEPENDENCIES_PANEL_ID);
return QLatin1String("ProjectExplorer.DependenciesPanel");
}
QString DependenciesPanelFactory::displayName() const
......@@ -277,7 +258,7 @@ bool DependenciesPanelFactory::supports(Project *project)
PropertiesPanel *DependenciesPanelFactory::createPanel(Project *project)
{
PropertiesPanel *panel = new PropertiesPanel;
panel->setWidget(new DependenciesWidget(m_session, project));
panel->setWidget(new DependenciesWidget(project));
panel->setIcon(QIcon(QLatin1String(":/projectexplorer/images/ProjectDependencies.png")));
panel->setDisplayName(QCoreApplication::translate("DependenciesPanel", "Dependencies"));
return panel;
......
......@@ -36,33 +36,24 @@
#include <QTreeView>
namespace Utils {
class DetailsWidget;
}
namespace Utils { class DetailsWidget; }
namespace ProjectExplorer {
class Project;
class SessionManager;
namespace Internal {
const char DEPENDENCIES_PANEL_ID[] = "ProjectExplorer.DependenciesPanel";
class DependenciesWidget;
class DependenciesPanelFactory : public IProjectPanelFactory
{
public:
DependenciesPanelFactory(SessionManager *session);
DependenciesPanelFactory() {}
QString id() const;
QString displayName() const;
int priority() const;
bool supports(Project *project);
PropertiesPanel *createPanel(Project *project);
private:
SessionManager *m_session;
};
......@@ -73,9 +64,9 @@ private:
class DependenciesModel : public QAbstractListModel
{
Q_OBJECT
public:
DependenciesModel(SessionManager *session, Project *project, QObject *parent = 0);
~DependenciesModel();
explicit DependenciesModel(Project *project, QObject *parent = 0);
int rowCount(const QModelIndex &index) const;
int columnCount(const QModelIndex &index) const;
......@@ -87,7 +78,6 @@ public slots:
void resetModel();
private:
SessionManager *m_session;
Project *m_project;
QList<Project *> m_projects;
};
......@@ -95,13 +85,16 @@ private:
class DependenciesView : public QTreeView
{
Q_OBJECT
public:
DependenciesView(QWidget *parent);
~DependenciesView();
virtual QSize sizeHint() const;
virtual void setModel(QAbstractItemModel *model);
QSize sizeHint() const;
void setModel(QAbstractItemModel *model);
private slots:
void updateSizeHint();
private:
QSize m_sizeHint;
};
......@@ -109,11 +102,11 @@ private:
class DependenciesWidget : public QWidget
{
Q_OBJECT
public:
DependenciesWidget(SessionManager *session, Project *project,
QWidget *parent = 0);
explicit DependenciesWidget(Project *project, QWidget *parent = 0);
private:
SessionManager *m_session;
Project *m_project;
DependenciesModel *m_model;
Utils::DetailsWidget *m_detailsContainer;
......
......@@ -209,16 +209,17 @@ int ListWidget::padding()
////////
// ProjectListWidget
////////
ProjectListWidget::ProjectListWidget(SessionManager *sessionManager, QWidget *parent)
: ListWidget(parent), m_sessionManager(sessionManager), m_ignoreIndexChange(false)
ProjectListWidget::ProjectListWidget(QWidget *parent)
: ListWidget(parent), m_ignoreIndexChange(false)
{
connect(m_sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
QObject *sessionManager = SessionManager::instance();
connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
this, SLOT(addProject(ProjectExplorer::Project*)));
connect(m_sessionManager, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
connect(sessionManager, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
this, SLOT(removeProject(ProjectExplorer::Project*)));
connect(m_sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
connect(sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
this, SLOT(changeStartupProject(ProjectExplorer::Project*)));
connect(m_sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
connect(sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
this, SLOT(projectDisplayNameChanged(ProjectExplorer::Project*)));
connect(this, SIGNAL(currentRowChanged(int)),
this, SLOT(setProject(int)));
......@@ -363,7 +364,7 @@ void ProjectListWidget::setProject(int index)
if (index < 0)
return;
Project *p = item(index)->data(Qt::UserRole).value<Project *>();
m_sessionManager->setStartupProject(p);
SessionManager::setStartupProject(p);
}
void ProjectListWidget::changeStartupProject(Project *project)
......@@ -539,8 +540,8 @@ QWidget *MiniProjectTargetSelector::createTitleLabel(const QString &text)
return bar;
}
MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorAction, SessionManager *sessionManager, QWidget *parent) :
QWidget(parent), m_projectAction(targetSelectorAction), m_sessionManager(sessionManager),
MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorAction, QWidget *parent) :
QWidget(parent), m_projectAction(targetSelectorAction),
m_project(0),
m_target(0),
m_buildConfiguration(0),
......@@ -570,7 +571,7 @@ MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorActi
m_listWidgets[PROJECT] = 0; //project is not a generic list widget
m_titleWidgets[PROJECT] = createTitleLabel(tr("Project"));
m_projectListWidget = new ProjectListWidget(m_sessionManager, this);
m_projectListWidget = new ProjectListWidget(this);
QStringList titles;
titles << tr("Kit") << tr("Build")
......@@ -581,21 +582,23 @@ MiniProjectTargetSelector::MiniProjectTargetSelector(QAction *targetSelectorActi
m_listWidgets[i] = new GenericListWidget(this);
}
changeStartupProject(m_sessionManager->startupProject());
if (m_sessionManager->startupProject())
activeTargetChanged(m_sessionManager->startupProject()->activeTarget());
Project *startup = SessionManager::startupProject();
changeStartupProject(startup);
if (startup)
activeTargetChanged(startup->activeTarget());
connect(m_summaryLabel, SIGNAL(linkActivated(QString)),
this, SLOT(switchToProjectsMode()));
connect(m_sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
QObject *sessionManager = SessionManager::instance();
connect(sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
this, SLOT(changeStartupProject(ProjectExplorer::Project*)));
connect(m_sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
this, SLOT(projectAdded(ProjectExplorer::Project*)));
connect(m_sessionManager, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
connect(sessionManager, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
this, SLOT(projectRemoved(ProjectExplorer::Project*)));
connect(m_sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
connect(sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
this, SLOT(updateActionAndSummary()));
// for icon changes:
......@@ -760,7 +763,7 @@ void MiniProjectTargetSelector::doLayout(bool keepSize)
onlySummary = true;
} else {
if (visibleLineCount < 3) {
foreach (Project *p, m_sessionManager->projects()) {
foreach (Project *p, SessionManager::projects()) {
if (p->needsConfiguration()) {
visibleLineCount = 3;
break;
......@@ -1063,10 +1066,11 @@ void MiniProjectTargetSelector::slotRemovedRunConfiguration(ProjectExplorer::Run
void MiniProjectTargetSelector::updateProjectListVisible()
{
bool visible = m_sessionManager->projects().size() > 1;
int count = SessionManager::projects().size();
bool visible = count > 1;
m_projectListWidget->setVisible(visible);
m_projectListWidget->setMaxCount(m_sessionManager->projects().size());
m_projectListWidget->setMaxCount(count);
m_titleWidgets[PROJECT]->setVisible(visible);
updateSummary();
......@@ -1075,7 +1079,7 @@ void MiniProjectTargetSelector::updateProjectListVisible()
void MiniProjectTargetSelector::updateTargetListVisible()
{
int maxCount = 0;
foreach (Project *p, m_sessionManager->projects())
foreach (Project *p, SessionManager::projects())
maxCount = qMax(p->targets().size(), maxCount);
bool visible = maxCount > 1;
......@@ -1088,7 +1092,7 @@ void MiniProjectTargetSelector::updateTargetListVisible()
void MiniProjectTargetSelector::updateBuildListVisible()
{
int maxCount = 0;
foreach (Project *p, m_sessionManager->projects())
foreach (Project *p, SessionManager::projects())
foreach (Target *t, p->targets())
maxCount = qMax(t->buildConfigurations().size(), maxCount);
......@@ -1102,7 +1106,7 @@ void MiniProjectTargetSelector::updateBuildListVisible()
void MiniProjectTargetSelector::updateDeployListVisible()
{
int maxCount = 0;
foreach (Project *p, m_sessionManager->projects())
foreach (Project *p, SessionManager::projects())
foreach (Target *t, p->targets())
maxCount = qMax(t->deployConfigurations().size(), maxCount);
......@@ -1116,7 +1120,7 @@ void MiniProjectTargetSelector::updateDeployListVisible()
void MiniProjectTargetSelector::updateRunListVisible()
{
int maxCount = 0;
foreach (Project *p, m_sessionManager->projects())
foreach (Project *p, SessionManager::projects())
foreach (Target *t, p->targets())
maxCount = qMax(t->runConfigurations().size(), maxCount);
......@@ -1444,10 +1448,10 @@ void MiniProjectTargetSelector::updateActionAndSummary()
void MiniProjectTargetSelector::updateSummary()
{
QString summary;
if (Project *startupProject = m_sessionManager->startupProject()) {
if (Project *startupProject = SessionManager::startupProject()) {
if (!m_projectListWidget->isVisibleTo(this))
summary.append(tr("Project: <b>%1</b><br/>").arg(startupProject->displayName()));
if (Target *activeTarget = m_sessionManager->startupProject()->activeTarget()) {
if (Target *activeTarget = startupProject->activeTarget()) {
if (!m_listWidgets[TARGET]->isVisibleTo(this))
summary.append(tr("Kit: <b>%1</b><br/>").arg( activeTarget->displayName()));
if (!m_listWidgets[BUILD]->isVisibleTo(this) && activeTarget->activeBuildConfiguration())
......
......@@ -47,7 +47,6 @@ class BuildConfiguration;
class DeployConfiguration;
class ProjectConfiguration;
class RunConfiguration;
class SessionManager;
namespace Internal {
......@@ -75,7 +74,7 @@ class ProjectListWidget : public ListWidget
{
Q_OBJECT
public:
explicit ProjectListWidget(SessionManager *sessionManager, QWidget *parent = 0);
explicit ProjectListWidget(QWidget *parent = 0);
private slots:
void addProject(ProjectExplorer::Project *project);
void removeProject(ProjectExplorer::Project *project);
......@@ -85,7 +84,6 @@ private slots:
private:
QListWidgetItem *itemForProject(Project *project);
QString fullName(ProjectExplorer::Project *project);
SessionManager *m_sessionManager;
bool m_ignoreIndexChange;
};
......@@ -114,7 +112,7 @@ class MiniProjectTargetSelector : public QWidget
{
Q_OBJECT
public:
explicit MiniProjectTargetSelector(QAction *projectAction, SessionManager *sessionManager, QWidget *parent = 0);
explicit MiniProjectTargetSelector(QAction *projectAction, QWidget *parent = 0);
void setVisible(bool visible);
void keyPressEvent(QKeyEvent *ke);
......@@ -175,7 +173,6 @@ private:
QWidget *createTitleLabel(const QString &text);
QAction *m_projectAction;
SessionManager *m_sessionManager;
enum TYPES { PROJECT = 0, TARGET = 1, BUILD = 2, DEPLOY = 3, RUN = 4, LAST = 5 };
ProjectListWidget *m_projectListWidget;
......
......@@ -48,7 +48,6 @@ QT_END_NAMESPACE
namespace Core {
class IMode;
class IEditor;
class IDocument;
}
namespace ProjectExplorer {
......@@ -56,7 +55,6 @@ namespace ProjectExplorer {
class Project;
class Node;
class SessionNode;
class SessionManager;
class PROJECTEXPLORER_EXPORT SessionManager : public QObject
{
......
......@@ -122,8 +122,8 @@ bool SessionNameInputDialog::isSwitchToRequested() const
}
SessionDialog::SessionDialog(SessionManager *sessionManager, QWidget *parent)
: QDialog(parent), m_sessionManager(sessionManager)
SessionDialog::SessionDialog(QWidget *parent)
: QDialog(parent)
{
m_ui.setupUi(this);
......@@ -161,10 +161,10 @@ bool SessionDialog::autoLoadSession() const
void SessionDialog::addItems(bool setDefaultSession)
{
QStringList sessions = m_sessionManager->sessions();
QStringList sessions = SessionManager::sessions();
foreach (const QString &session, sessions) {
m_ui.sessionList->addItem(session);
if (setDefaultSession && session == m_sessionManager->activeSession())
if (setDefaultSession && session == SessionManager::activeSession())
m_ui.sessionList->setCurrentRow(m_ui.sessionList->count() - 1);
}
}
......@@ -174,11 +174,11 @@ void SessionDialog::markItems()
QListWidgetItem *item = m_ui.sessionList->item(i);
QFont f = item->font();
QString session = item->data(Qt::DisplayRole).toString();
if (m_sessionManager->isDefaultSession(session))
if (SessionManager::isDefaultSession(session))
f.setItalic(true);
else
f.setItalic(false);
if (m_sessionManager->activeSession() == session && !m_sessionManager->isDefaultVirgin())
if (SessionManager::activeSession() == session && !SessionManager::isDefaultVirgin())
f.setBold(true);
else
f.setBold(false);
......@@ -190,7 +190,7 @@ void SessionDialog::updateActions()
{
if (m_ui.sessionList->currentItem()) {
bool isDefault = (m_ui.sessionList->currentItem()->text() == QLatin1String("default"));
bool isActive = (m_ui.sessionList->currentItem()->text() == m_sessionManager->activeSession());
bool isActive = (m_ui.sessionList->currentItem()->text() == SessionManager::activeSession());
m_ui.btDelete->setEnabled(!isActive && !isDefault);
m_ui.btRename->setEnabled(!isDefault);
m_ui.btClone->setEnabled(true);
......@@ -205,17 +205,17 @@ void SessionDialog::updateActions()
void SessionDialog::createNew()
{
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), this);
SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), this);
newSessionInputDialog.setWindowTitle(tr("New session name"));
if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value();
if (newSession.isEmpty() || m_sessionManager->sessions().contains(newSession))
if (newSession.isEmpty() || SessionManager::sessions().contains(newSession))
return;
m_sessionManager->createSession(newSession);
SessionManager::createSession(newSession);
m_ui.sessionList->clear();
QStringList sessions = m_sessionManager->sessions();
QStringList sessions = SessionManager::sessions();
m_ui.sessionList->addItems(sessions);
m_ui.sessionList->setCurrentRow(sessions.indexOf(newSession));
markItems();
......@@ -226,15 +226,15 @@ void SessionDialog::createNew()
void SessionDialog::clone()
{
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), this);
SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), this);
newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
newSessionInputDialog.setWindowTitle(tr("New session name"));
if (newSessionInputDialog.exec() == QDialog::Accepted) {
QString newSession = newSessionInputDialog.value();
if (m_sessionManager->cloneSession(m_ui.sessionList->currentItem()->text(), newSession)) {
if (SessionManager::cloneSession(m_ui.sessionList->currentItem()->text(), newSession)) {
m_ui.sessionList->clear();
QStringList sessions = m_sessionManager->sessions();
QStringList sessions = SessionManager::sessions();
m_ui.sessionList->addItems(sessions);
m_ui.sessionList->setCurrentRow(sessions.indexOf(newSession));
markItems();
......@@ -246,9 +246,9 @@ void SessionDialog::remove()
{
const QString name = m_ui.sessionList->currentItem()->text();
if (!m_sessionManager->confirmSessionDelete(name))
if (!SessionManager::confirmSessionDelete(name))
return;
m_sessionManager->deleteSession(name);
SessionManager::deleteSession(name);
m_ui.sessionList->clear();
addItems(false);
markItems();
......@@ -256,12 +256,12 @@ void SessionDialog::remove()
void SessionDialog::rename()
{
SessionNameInputDialog newSessionInputDialog(m_sessionManager->sessions(), this);
SessionNameInputDialog newSessionInputDialog(SessionManager::sessions(), this);
newSessionInputDialog.setValue(m_ui.sessionList->currentItem()->text());
newSessionInputDialog.setWindowTitle(tr("Rename session"));
if (newSessionInputDialog.exec() == QDialog::Accepted) {
m_sessionManager->renameSession(m_ui.sessionList->currentItem()->text(), newSessionInputDialog.value());
SessionManager::renameSession(m_ui.sessionList->currentItem()->text(), newSessionInputDialog.value());
m_ui.sessionList->clear();
addItems(false);
markItems();
......@@ -271,7 +271,7 @@ void SessionDialog::rename()
void SessionDialog::switchToSession()
{
QString session = m_ui.sessionList->currentItem()->text();
m_sessionManager->loadSession(session);
SessionManager::loadSession(session);
markItems();
updateActions();
reject();
......
......@@ -30,27 +30,25 @@
#ifndef SESSIONDIALOG_H
#define SESSIONDIALOG_H
#include "ui_sessiondialog.h"
#include <QString>
#include <QDialog>
#include "ui_sessiondialog.h"
QT_BEGIN_NAMESPACE
class QLineEdit;
class QPushButton;
QT_END_NAMESPACE
namespace ProjectExplorer {
class SessionManager;
namespace Internal {
class SessionDialog : public QDialog
{
Q_OBJECT
public:
SessionDialog(SessionManager *sessionManager, QWidget *parent = 0);
explicit SessionDialog(QWidget *parent = 0);
void setAutoLoadSession(bool);
bool autoLoadSession() const;
......@@ -68,7 +66,6 @@ private:
void addItems(bool setDefaultSession);
void markItems();
Ui::SessionDialog m_ui;
SessionManager *m_sessionManager;
};
class SessionNameInputDialog : public QDialog
......
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