From 8c2972be05b311fcbbd3c4ad5f1947bdbfb56b52 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 4 May 2012 18:32:12 +0200 Subject: [PATCH] remotelinux: fix index computation in the presence of hidden devices Change-Id: I65bb3854003783ad36dfad76c35535c83ab6d427 Reviewed-by: Christian Kandeler --- .../devicesupport/devicemanagermodel.h | 2 +- .../remotelinux/startgdbserverdialog.cpp | 18 +++++++++--------- src/plugins/remotelinux/startgdbserverdialog.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/plugins/projectexplorer/devicesupport/devicemanagermodel.h b/src/plugins/projectexplorer/devicesupport/devicemanagermodel.h index 53c1a6a8f8a..3317fb5110c 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanagermodel.h +++ b/src/plugins/projectexplorer/devicesupport/devicemanagermodel.h @@ -56,6 +56,7 @@ public: IDevice::ConstPtr device(int pos) const; Core::Id deviceId(int pos) const; int indexOf(IDevice::ConstPtr dev) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; private slots: void handleDeviceAdded(Core::Id id); @@ -64,7 +65,6 @@ private slots: void handleDeviceListChanged(); private: - int rowCount(const QModelIndex &parent = QModelIndex()) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; int indexForId(Core::Id id) const; diff --git a/src/plugins/remotelinux/startgdbserverdialog.cpp b/src/plugins/remotelinux/startgdbserverdialog.cpp index 6f8b8952edf..27236586937 100644 --- a/src/plugins/remotelinux/startgdbserverdialog.cpp +++ b/src/plugins/remotelinux/startgdbserverdialog.cpp @@ -87,8 +87,7 @@ public: LinuxDeviceConfiguration::ConstPtr currentDevice() const { - DeviceManager *devices = DeviceManager::instance(); - return devices->deviceAt(deviceComboBox->currentIndex()) + return deviceManagerModel->device(deviceComboBox->currentIndex()) .dynamicCast(); } @@ -96,6 +95,7 @@ public: bool startServerOnly; AbstractRemoteLinuxProcessList *processList; QSortFilterProxyModel proxyModel; + DeviceManagerModel *deviceManagerModel; QComboBox *deviceComboBox; QLineEdit *processFilterLineEdit; @@ -175,16 +175,15 @@ StartGdbServerDialog::StartGdbServerDialog(QWidget *parent) : { setWindowTitle(tr("List of Remote Processes")); - DeviceManager *devices = DeviceManager::instance(); - DeviceManagerModel * const model = new DeviceManagerModel(devices, this); + d->deviceManagerModel = new DeviceManagerModel(DeviceManager::instance(), this); QObject::connect(d->closeButton, SIGNAL(clicked()), this, SLOT(reject())); - d->deviceComboBox->setModel(model); + d->deviceComboBox->setModel(d->deviceManagerModel); d->deviceComboBox->setCurrentIndex(d->settings->value(LastDevice).toInt()); connect(&d->gatherer, SIGNAL(error(QString)), SLOT(portGathererError(QString))); connect(&d->gatherer, SIGNAL(portListReady()), SLOT(portListReady())); - if (devices->deviceCount() == 0) { + if (d->deviceManagerModel->rowCount() == 0) { d->tableView->setEnabled(false); } else { d->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); @@ -217,11 +216,12 @@ StartGdbServerDialog::~StartGdbServerDialog() delete d; } -void StartGdbServerDialog::attachToDevice(int index) +void StartGdbServerDialog::attachToDevice(int modelIndex) { - DeviceManager *devices = DeviceManager::instance(); LinuxDeviceConfiguration::ConstPtr device - = devices->deviceAt(index).dynamicCast(); + = d->deviceManagerModel->device(modelIndex) + .dynamicCast(); + // TODO: display error on non-matching device. if (!device) return; delete d->processList; diff --git a/src/plugins/remotelinux/startgdbserverdialog.h b/src/plugins/remotelinux/startgdbserverdialog.h index e22f207c31a..e996af3669f 100644 --- a/src/plugins/remotelinux/startgdbserverdialog.h +++ b/src/plugins/remotelinux/startgdbserverdialog.h @@ -56,7 +56,7 @@ signals: void processAborted(); private slots: - void attachToDevice(int index); + void attachToDevice(int modelIndex); void handleRemoteError(const QString &errorMessage); void handleProcessListUpdated(); void updateProcessList();