4 This file is part of GammaRay, the Qt application inspection and
7 Copyright (C) 2010-2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8 Author: Milian Wolff <milian.wolff@kdab.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "attachdialog.h"
26 #include "processfiltermodel.h"
27 #include "processmodel.h"
29 #include <QPushButton>
30 #include <QStandardItemModel>
33 #include <QFutureWatcher>
34 #include <QtConcurrentRun>
36 using namespace GammaRay
;
38 AttachDialog::AttachDialog(QWidget
*parent
, Qt::WindowFlags f
)
42 ui
.buttonBox
->button(QDialogButtonBox::Ok
)->setText(tr("Attach"));
44 m_model
= new ProcessModel(this);
46 m_proxyModel
= new ProcessFilterModel(this);
47 m_proxyModel
->setSourceModel(m_model
);
48 m_proxyModel
->setDynamicSortFilter(true);
50 ui
.view
->setModel(m_proxyModel
);
52 ui
.view
->hideColumn(ProcessModel::StateColumn
);
53 ui
.view
->sortByColumn(ProcessModel::NameColumn
, Qt::AscendingOrder
);
54 ui
.view
->setSortingEnabled(true);
56 ui
.view
->setEditTriggers(QAbstractItemView::NoEditTriggers
);
58 ui
.view
->setSelectionBehavior(QAbstractItemView::SelectRows
);
59 ui
.view
->setSelectionMode(QAbstractItemView::SingleSelection
);
60 connect(ui
.view
->selectionModel(), SIGNAL(currentRowChanged(QModelIndex
,QModelIndex
)),
61 this, SLOT(selectionChanged()));
63 connect(ui
.view
, SIGNAL(activated(QModelIndex
)),
64 ui
.buttonBox
->button(QDialogButtonBox::Ok
), SLOT(click()));
66 ui
.filter
->setProxy(m_proxyModel
);
68 setWindowTitle(tr("GammaRay - Attach to Process"));
69 setWindowIcon(QIcon(":gammaray/GammaRay-128x128.png"));
71 m_timer
= new QTimer(this);
72 connect(m_timer
, SIGNAL(timeout()), this, SLOT(updateProcesses()));
75 // set process list syncronously the first time
76 m_model
->setProcesses(processList());
80 void AttachDialog::selectionChanged()
82 ui
.buttonBox
->button(QDialogButtonBox::Ok
)->setEnabled(ui
.view
->currentIndex().isValid());
85 QString
AttachDialog::pid() const
87 return ui
.view
->currentIndex().data(ProcessModel::PIDRole
).toString();
90 void AttachDialog::updateProcesses()
92 QFutureWatcher
<ProcDataList
>* watcher
= new QFutureWatcher
<ProcDataList
>(this);
93 connect(watcher
, SIGNAL(finished()),
94 this, SLOT(updateProcessesFinished()));
95 watcher
->setFuture(QtConcurrent::run(processList
));
98 void AttachDialog::updateProcessesFinished()
100 QFutureWatcher
<ProcDataList
>* watcher
= dynamic_cast<QFutureWatcher
<ProcDataList
>*>(sender());
102 const QString oldPid
= pid();
103 m_model
->mergeProcesses(watcher
->result());
104 if (oldPid
!= pid()) {
105 ui
.view
->setCurrentIndex(QModelIndex());
107 watcher
->deleteLater();
110 #include "attachdialog.moc"