File indexing completed on 2024-03-24 05:54:12
0001 /* 0002 SPDX-FileCopyrightText: 2008 Robert Knight <robertknight@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef CHECKABLESESSIONMODEL_H 0008 #define CHECKABLESESSIONMODEL_H 0009 0010 // Qt 0011 #include <QSet> 0012 0013 // Konsole 0014 #include "session/Session.h" 0015 #include "session/SessionListModel.h" 0016 0017 namespace Konsole 0018 { 0019 /** 0020 * A list of sessions with a checkbox next to each one which allows the 0021 * user to select a subset of the available sessions to perform 0022 * some action on them. 0023 */ 0024 class CheckableSessionModel : public SessionListModel 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 explicit CheckableSessionModel(QObject *parent); 0030 0031 void setCheckColumn(int column); 0032 int checkColumn() const; 0033 0034 /** 0035 * Sets whether a session can be checked or un-checked. 0036 * Non-checkable items have the Qt::ItemIsEnabled flag unset. 0037 */ 0038 void setCheckable(Session *session, bool checkable); 0039 0040 /** Sets the list of sessions which are currently checked. */ 0041 void setCheckedSessions(const QSet<Session *> &sessions); 0042 /** Returns the set of checked sessions. */ 0043 QSet<Session *> checkedSessions() const; 0044 0045 // reimplemented from QAbstractItemModel 0046 Qt::ItemFlags flags(const QModelIndex &index) const override; 0047 QVariant data(const QModelIndex &index, int role) const override; 0048 bool setData(const QModelIndex &index, const QVariant &value, int role) override; 0049 0050 protected: 0051 void sessionRemoved(Session *) override; 0052 0053 private: 0054 QSet<Session *> _checkedSessions; 0055 QSet<Session *> _fixedSessions; 0056 int _checkColumn; 0057 }; 0058 0059 inline int CheckableSessionModel::checkColumn() const 0060 { 0061 return _checkColumn; 0062 } 0063 0064 } 0065 0066 #endif