• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
CopyInputDialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2008 by Robert Knight <robertknight@gmail.com>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301 USA.
18 */
19 
20 // Own
21 #include "CopyInputDialog.h"
22 
23 // Qt
24 #include <QSortFilterProxyModel>
25 
26 // Konsole
27 #include "ui_CopyInputDialog.h"
28 
29 using namespace Konsole;
30 
31 CopyInputDialog::CopyInputDialog(QWidget* parent)
32  : KDialog(parent)
33 {
34  setCaption(i18n("Copy Input"));
35  setButtons(KDialog::Ok | KDialog::Cancel);
36 
37  setWindowModality(Qt::WindowModal);
38 
39  _ui = new Ui::CopyInputDialog();
40  _ui->setupUi(mainWidget());
41 
42  connect(_ui->selectAllButton, SIGNAL(clicked()), this, SLOT(selectAll()));
43  connect(_ui->deselectAllButton, SIGNAL(clicked()), this, SLOT(deselectAll()));
44 
45  _ui->filterEdit->setClearButtonShown(true);
46  _ui->filterEdit->setFocus();
47 
48  _model = new CheckableSessionModel(parent);
49  _model->setCheckColumn(1);
50  _model->setSessions(SessionManager::instance()->sessions());
51 
52  QSortFilterProxyModel* filterProxyModel = new QSortFilterProxyModel(this);
53  filterProxyModel->setDynamicSortFilter(true);
54  filterProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
55  filterProxyModel->setSourceModel(_model);
56  filterProxyModel->setFilterKeyColumn(-1);
57 
58  connect(_ui->filterEdit, SIGNAL(textChanged(QString)),
59  filterProxyModel, SLOT(setFilterFixedString(QString)));
60 
61  _ui->sessionList->setModel(filterProxyModel);
62  _ui->sessionList->setColumnHidden(0, true); // Hide number column
63  _ui->sessionList->header()->hide();
64 }
65 
66 CopyInputDialog::~CopyInputDialog()
67 {
68  delete _ui;
69 }
70 
71 void CopyInputDialog::setChosenSessions(const QSet<Session*>& sessions)
72 {
73  QSet<Session*> checked = sessions;
74  if (_masterSession)
75  checked.insert(_masterSession);
76 
77  _model->setCheckedSessions(checked);
78 }
79 QSet<Session*> CopyInputDialog::chosenSessions() const
80 {
81  return _model->checkedSessions();
82 }
83 void CopyInputDialog::setMasterSession(Session* session)
84 {
85  if (_masterSession)
86  _model->setCheckable(_masterSession, true);
87 
88  _model->setCheckable(session, false);
89  QSet<Session*> checked = _model->checkedSessions();
90  checked.insert(session);
91  _model->setCheckedSessions(checked);
92 
93  _masterSession = session;
94 }
95 void CopyInputDialog::setSelectionChecked(bool checked)
96 {
97  QAbstractItemModel* model = _ui->sessionList->model();
98  int rows = model->rowCount();
99 
100  QModelIndexList selected = _ui->sessionList->selectionModel()->selectedIndexes();
101 
102  if (selected.count() > 1) {
103  foreach(const QModelIndex & index, selected) {
104  setRowChecked(index.row(), checked);
105  }
106  } else {
107  for (int i = 0; i < rows; i++)
108  setRowChecked(i, checked);
109  }
110 }
111 void CopyInputDialog::setRowChecked(int row, bool checked)
112 {
113  QAbstractItemModel* model = _ui->sessionList->model();
114  QModelIndex index = model->index(row, _model->checkColumn());
115  if (checked)
116  model->setData(index, static_cast<int>(Qt::Checked), Qt::CheckStateRole);
117  else
118  model->setData(index, static_cast<int>(Qt::Unchecked), Qt::CheckStateRole);
119 }
120 CheckableSessionModel::CheckableSessionModel(QObject* parent)
121  : SessionListModel(parent)
122  , _checkColumn(0)
123 {
124 }
125 void CheckableSessionModel::setCheckColumn(int column)
126 {
127  _checkColumn = column;
128  reset();
129 }
130 Qt::ItemFlags CheckableSessionModel::flags(const QModelIndex& index) const
131 {
132  Session* session = static_cast<Session*>(index.internalPointer());
133 
134  if (_fixedSessions.contains(session))
135  return SessionListModel::flags(index) & ~Qt::ItemIsEnabled;
136  else
137  return SessionListModel::flags(index) | Qt::ItemIsUserCheckable;
138 }
139 QVariant CheckableSessionModel::data(const QModelIndex& index, int role) const
140 {
141  if (role == Qt::CheckStateRole && index.column() == _checkColumn) {
142  Session* session = static_cast<Session*>(index.internalPointer());
143 
144  if (_checkedSessions.contains(session))
145  return QVariant::fromValue(static_cast<int>(Qt::Checked));
146  else
147  return QVariant::fromValue(static_cast<int>(Qt::Unchecked));
148  } else {
149  return SessionListModel::data(index, role);
150  }
151 }
152 bool CheckableSessionModel::setData(const QModelIndex& index, const QVariant& value, int role)
153 {
154  if (role == Qt::CheckStateRole && index.column() == _checkColumn) {
155  Session* session = static_cast<Session*>(index.internalPointer());
156 
157  if (_fixedSessions.contains(session))
158  return false;
159 
160  if (value.value<int>() == Qt::Checked)
161  _checkedSessions.insert(session);
162  else
163  _checkedSessions.remove(session);
164 
165  emit dataChanged(index, index);
166  return true;
167  } else {
168  return SessionListModel::setData(index, value, role);
169  }
170 }
171 void CheckableSessionModel::setCheckedSessions(const QSet<Session*> sessions)
172 {
173  _checkedSessions = sessions;
174  reset();
175 }
176 QSet<Session*> CheckableSessionModel::checkedSessions() const
177 {
178  return _checkedSessions;
179 }
180 void CheckableSessionModel::setCheckable(Session* session, bool checkable)
181 {
182  if (!checkable)
183  _fixedSessions.insert(session);
184  else
185  _fixedSessions.remove(session);
186 
187  reset();
188 }
189 void CheckableSessionModel::sessionRemoved(Session* session)
190 {
191  _checkedSessions.remove(session);
192  _fixedSessions.remove(session);
193 }
194 
QModelIndex
Konsole::SessionManager::instance
static SessionManager * instance()
Returns the session manager instance.
Definition: SessionManager.cpp:69
QWidget
QAbstractItemModel::rowCount
virtual int rowCount(const QModelIndex &parent) const =0
Konsole::Session
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition: Session.h:78
QSortFilterProxyModel::setFilterCaseSensitivity
void setFilterCaseSensitivity(Qt::CaseSensitivity cs)
QAbstractItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
QSortFilterProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
Konsole::CopyInputDialog::setMasterSession
void setMasterSession(Session *master)
Sets the 'source' session whose input will be copied to other sessions.
Definition: CopyInputDialog.cpp:83
Konsole::CheckableSessionModel::checkedSessions
QSet< Session * > checkedSessions() const
Returns the set of checked sessions.
Definition: CopyInputDialog.cpp:176
QVariant::value
T value() const
KDialog
QSet::insert
const_iterator insert(const T &value)
Konsole::CopyInputDialog::setChosenSessions
void setChosenSessions(const QSet< Session * > &sessions)
Sets the sessions in the list which are checked.
Definition: CopyInputDialog.cpp:71
Konsole::SessionListModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: SessionListModel.cpp:51
Konsole::SessionListModel
Item-view model which contains a flat list of sessions.
Definition: SessionListModel.h:42
Konsole::CopyInputDialog::chosenSessions
QSet< Session * > chosenSessions() const
Set setChosenSessions()
Definition: CopyInputDialog.cpp:79
QAbstractItemModel::reset
void reset()
CopyInputDialog.h
QAbstractItemModel::dataChanged
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Konsole::CheckableSessionModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
Definition: CopyInputDialog.cpp:152
QObject
Konsole::CheckableSessionModel::CheckableSessionModel
CheckableSessionModel(QObject *parent)
Definition: CopyInputDialog.cpp:120
QModelIndex::row
int row() const
Konsole::SessionListModel::setSessions
void setSessions(const QList< Session * > &sessions)
Sets the list of sessions displayed in the model.
Definition: SessionListModel.cpp:40
QSortFilterProxyModel::setDynamicSortFilter
void setDynamicSortFilter(bool enable)
QModelIndex::internalPointer
void * internalPointer() const
QSet
QString
Konsole::CheckableSessionModel::setCheckedSessions
void setCheckedSessions(const QSet< Session * > sessions)
Sets the list of sessions which are currently checked.
Definition: CopyInputDialog.cpp:171
Konsole::CheckableSessionModel::setCheckable
void setCheckable(Session *session, bool checkable)
Sets whether a session can be checked or un-checked.
Definition: CopyInputDialog.cpp:180
QSortFilterProxyModel
Konsole::CheckableSessionModel
A list of sessions with a checkbox next to each one which allows the user to select a subset of the a...
Definition: CopyInputDialog.h:95
QVariant::fromValue
QVariant fromValue(const T &value)
Konsole::CheckableSessionModel::checkColumn
int checkColumn() const
Definition: CopyInputDialog.h:130
Konsole::CheckableSessionModel::setCheckColumn
void setCheckColumn(int column)
Definition: CopyInputDialog.cpp:125
Konsole::CopyInputDialog::CopyInputDialog
CopyInputDialog(QWidget *parent=0)
Definition: CopyInputDialog.cpp:31
QModelIndex::column
int column() const
QAbstractItemModel
QAbstractItemModel::setData
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
QAbstractItemModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Konsole::CheckableSessionModel::data
virtual QVariant data(const QModelIndex &index, int role) const
Definition: CopyInputDialog.cpp:139
Konsole::CheckableSessionModel::flags
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: CopyInputDialog.cpp:130
QSortFilterProxyModel::setFilterKeyColumn
void setFilterKeyColumn(int column)
Konsole::CopyInputDialog::~CopyInputDialog
~CopyInputDialog()
Definition: CopyInputDialog.cpp:66
QVariant
Qt::ItemFlags
typedef ItemFlags
Konsole::CheckableSessionModel::sessionRemoved
virtual void sessionRemoved(Session *)
Definition: CopyInputDialog.cpp:189
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal