1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include <QAbstractTableModel> 29 30 #include <functional> 31 32 namespace ProjectExplorer { 33 namespace Internal { 34 35 const char SESSION_BASE_ID[] = "Welcome.OpenSession"; 36 37 class SessionNameInputDialog; 38 39 class SessionModel : public QAbstractTableModel 40 { 41 Q_OBJECT 42 43 public: 44 enum { 45 DefaultSessionRole = Qt::UserRole+1, 46 LastSessionRole, 47 ActiveSessionRole, 48 ProjectsPathRole, 49 ProjectsDisplayRole, 50 ShortcutRole 51 }; 52 53 explicit SessionModel(QObject *parent = nullptr); 54 55 int indexOfSession(const QString &session); 56 QString sessionAt(int row) const; 57 58 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 59 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 60 61 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 62 QVariant data(const QModelIndex &index, int role) const override; 63 QHash<int, QByteArray> roleNames() const override; 64 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; 65 66 Q_SCRIPTABLE bool isDefaultVirgin() const; 67 68 signals: 69 void sessionSwitched(); 70 void sessionCreated(const QString &sessionName); 71 72 public slots: 73 void resetSessions(); 74 void newSession(QWidget *parent); 75 void cloneSession(QWidget *parent, const QString &session); 76 void deleteSessions(const QStringList &sessions); 77 void renameSession(QWidget *parent, const QString &session); 78 void switchToSession(const QString &session); 79 80 private: 81 void runSessionNameInputDialog(ProjectExplorer::Internal::SessionNameInputDialog *sessionInputDialog, std::function<void(const QString &)> createSession); 82 83 QStringList m_sortedSessions; 84 int m_currentSortColumn = 0; 85 Qt::SortOrder m_currentSortOrder = Qt::AscendingOrder; 86 }; 87 88 } // namespace Internal 89 } // namespace ProjectExplorer 90