forked from qt-creator/qt-creator
Sessions: introduce SessionView
This will replace the simple session list in SessionManager UI. Change-Id: Idec2fa2e4629b9986a5d274d6da5129e779e2100 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -77,6 +77,7 @@ HEADERS += projectexplorer.h \
|
||||
buildprogress.h \
|
||||
projectnodes.h \
|
||||
sessiondialog.h \
|
||||
sessionview.h \
|
||||
projectwizardpage.h \
|
||||
buildstepspage.h \
|
||||
nodesvisitor.h \
|
||||
@@ -224,6 +225,7 @@ SOURCES += projectexplorer.cpp \
|
||||
buildprogress.cpp \
|
||||
projectnodes.cpp \
|
||||
sessiondialog.cpp \
|
||||
sessionview.cpp \
|
||||
projectwizardpage.cpp \
|
||||
buildstepspage.cpp \
|
||||
nodesvisitor.cpp \
|
||||
|
@@ -137,6 +137,7 @@ Project {
|
||||
"selectablefilesmodel.cpp", "selectablefilesmodel.h",
|
||||
"session.cpp", "session.h",
|
||||
"sessionmodel.cpp", "sessionmodel.h",
|
||||
"sessionview.cpp", "sessionview.h",
|
||||
"sessiondialog.cpp", "sessiondialog.h", "sessiondialog.ui",
|
||||
"settingsaccessor.cpp", "settingsaccessor.h",
|
||||
"showineditortaskhandler.cpp", "showineditortaskhandler.h",
|
||||
|
@@ -45,6 +45,16 @@ SessionModel::SessionModel(QObject *parent)
|
||||
this, &SessionModel::resetSessions);
|
||||
}
|
||||
|
||||
int SessionModel::indexOfSession(const QString &session)
|
||||
{
|
||||
return SessionManager::sessions().indexOf(session);
|
||||
}
|
||||
|
||||
QString SessionModel::sessionAt(int row)
|
||||
{
|
||||
return SessionManager::sessions().value(row, QString());
|
||||
}
|
||||
|
||||
int SessionModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return SessionManager::sessions().count();
|
||||
|
@@ -41,7 +41,10 @@ public:
|
||||
|
||||
explicit SessionModel(QObject *parent = nullptr);
|
||||
|
||||
int rowCount(const QModelIndex &parent) const override;
|
||||
int indexOfSession(const QString &session);
|
||||
QString sessionAt(int row);
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
|
134
src/plugins/projectexplorer/sessionview.cpp
Normal file
134
src/plugins/projectexplorer/sessionview.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "sessionview.h"
|
||||
|
||||
#include "session.h"
|
||||
|
||||
#include <QItemSelection>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QHeaderView>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
namespace Internal {
|
||||
|
||||
// custom item delegate class
|
||||
class RemoveItemFocusDelegate : public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
RemoveItemFocusDelegate(QObject *parent = nullptr) : QStyledItemDelegate(parent) {
|
||||
}
|
||||
|
||||
protected:
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
};
|
||||
|
||||
void RemoveItemFocusDelegate::paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex &index) const
|
||||
{
|
||||
QStyleOptionViewItem opt = option;
|
||||
opt.state &= ~QStyle::State_HasFocus;
|
||||
QStyledItemDelegate::paint(painter, opt, index);
|
||||
}
|
||||
|
||||
SessionView::SessionView(QWidget *parent)
|
||||
: QTreeView(parent)
|
||||
{
|
||||
setItemDelegate(new RemoveItemFocusDelegate(this));
|
||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
setWordWrap(false);
|
||||
setRootIsDecorated(false);
|
||||
|
||||
setModel(&m_sessionModel);
|
||||
|
||||
QItemSelection firstRow(m_sessionModel.index(0,0), m_sessionModel.index(0, 0));
|
||||
selectionModel()->select(firstRow,
|
||||
QItemSelectionModel::QItemSelectionModel::SelectCurrent);
|
||||
|
||||
connect(this, &QTreeView::activated, [this](const QModelIndex &index){
|
||||
emit activated(m_sessionModel.sessionAt(index.row()));
|
||||
});
|
||||
connect(selectionModel(), &QItemSelectionModel::currentRowChanged, [this]
|
||||
(const QModelIndex &index) {
|
||||
emit selected(m_sessionModel.sessionAt(index.row()));
|
||||
});
|
||||
connect(&m_sessionModel, &SessionModel::sessionSwitched,
|
||||
this, &SessionView::sessionSwitched);
|
||||
|
||||
connect(&m_sessionModel, &SessionModel::modelReset,
|
||||
this, &SessionView::selectActiveSession);
|
||||
}
|
||||
|
||||
void SessionView::createNewSession()
|
||||
{
|
||||
m_sessionModel.newSession();
|
||||
}
|
||||
|
||||
void SessionView::deleteCurrentSession()
|
||||
{
|
||||
m_sessionModel.deleteSession(currentSession());
|
||||
}
|
||||
|
||||
void SessionView::cloneCurrentSession()
|
||||
{
|
||||
m_sessionModel.cloneSession(currentSession());
|
||||
}
|
||||
|
||||
void SessionView::renameCurrentSession()
|
||||
{
|
||||
m_sessionModel.renameSession(currentSession());
|
||||
}
|
||||
|
||||
void SessionView::switchToCurrentSession()
|
||||
{
|
||||
m_sessionModel.switchToSession(currentSession());
|
||||
}
|
||||
|
||||
QString SessionView::currentSession()
|
||||
{
|
||||
return m_sessionModel.sessionAt(selectionModel()->currentIndex().row());
|
||||
}
|
||||
|
||||
SessionModel *SessionView::sessionModel()
|
||||
{
|
||||
return &m_sessionModel;
|
||||
}
|
||||
|
||||
void SessionView::selectActiveSession()
|
||||
{
|
||||
int row = m_sessionModel.indexOfSession(SessionManager::activeSession());
|
||||
selectionModel()->setCurrentIndex(model()->index(row, 0),
|
||||
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||
}
|
||||
|
||||
void SessionView::showEvent(QShowEvent *event)
|
||||
{
|
||||
QTreeView::showEvent(event);
|
||||
selectActiveSession();
|
||||
setFocus();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ProjectExplorer
|
65
src/plugins/projectexplorer/sessionview.h
Normal file
65
src/plugins/projectexplorer/sessionview.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sessionmodel.h"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QTreeView>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
namespace Internal {
|
||||
|
||||
class SessionView : public QTreeView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SessionView(QWidget *parent = Q_NULLPTR);
|
||||
|
||||
void createNewSession();
|
||||
void deleteCurrentSession();
|
||||
void cloneCurrentSession();
|
||||
void renameCurrentSession();
|
||||
void switchToCurrentSession();
|
||||
|
||||
QString currentSession();
|
||||
SessionModel* sessionModel();
|
||||
void selectActiveSession();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
|
||||
signals:
|
||||
void activated(const QString &session);
|
||||
void selected(const QString &session);
|
||||
void sessionSwitched();
|
||||
|
||||
private:
|
||||
SessionModel m_sessionModel;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ProjectExplorer
|
Reference in New Issue
Block a user