diff options
author | Tobias Hunger <tobias.hunger@nokia.com> | 2012-05-02 15:55:34 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@nokia.com> | 2012-05-03 13:29:47 +0200 |
commit | 566642731f8d351ac66bcd12f5d2be353cfb91e6 (patch) | |
tree | 659d29858f3e36a88947d36c4c807e8ed10e1dc2 /src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp | |
parent | 1cc3a5ecd9169b301d7c1de5f18e1f951bac51f4 (diff) | |
download | qt-creator-566642731f8d351ac66bcd12f5d2be353cfb91e6.tar.gz |
Device: Decouple DeviceManager and DeviceSettingsWidget
Decouple DeviceSettingsWidget from the DeviceManager by
extending the DeviceModel with some methods to query information
from there.
This allows to add things like filtering to the model.
Change-Id: I8ac45d3ae254c31e2fe36556978bd6af5adccd32
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
Diffstat (limited to 'src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp')
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp b/src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp index f3c006ef6e..5d59864394 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanagermodel.cpp @@ -33,6 +33,8 @@ #include "devicemanager.h" +#include <coreplugin/id.h> + #include <QString> namespace ProjectExplorer { @@ -66,6 +68,31 @@ void DeviceManagerModel::updateDevice(Core::Id id) handleDeviceUpdated(id); } +IDevice::ConstPtr DeviceManagerModel::device(int pos) const +{ + if (pos < 0 || pos >= d->devices.count()) + return IDevice::ConstPtr(); + return d->devices.at(pos); +} + +Core::Id DeviceManagerModel::deviceId(int pos) const +{ + IDevice::ConstPtr dev = device(pos); + if (dev.isNull()) + return IDevice::invalidId(); + return dev->id(); +} + +int DeviceManagerModel::indexOf(IDevice::ConstPtr dev) const +{ + for (int i = 0; i < d->devices.count(); ++i) { + IDevice::ConstPtr current = d->devices.at(i); + if (current->id() == dev->id()) + return i; + } + return -1; +} + void DeviceManagerModel::handleDeviceAdded(Core::Id id) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); @@ -93,6 +120,7 @@ void DeviceManagerModel::handleDeviceListChanged() { beginResetModel(); d->devices.clear(); + for (int i = 0; i < d->deviceManager->deviceCount(); ++i) d->devices << d->deviceManager->deviceAt(i); endResetModel(); @@ -106,12 +134,18 @@ int DeviceManagerModel::rowCount(const QModelIndex &parent) const QVariant DeviceManagerModel::data(const QModelIndex &index, int role) const { - if (!index.isValid() || index.row() >= rowCount() || role != Qt::DisplayRole) + if (!index.isValid() || index.row() >= rowCount()) + return QVariant(); + if (role != Qt::DisplayRole && role != Qt::UserRole) return QVariant(); - const IDevice::ConstPtr device = d->devices.at(index.row()); - QString name = device->displayName(); - if (d->deviceManager->defaultDevice(device->type()) == device) - name = tr("%1 (default for %2)").arg(name, device->displayType()); + const IDevice::ConstPtr dev = device(index.row()); + if (role == Qt::UserRole) + return dev->id().uniqueIdentifier(); + QString name; + if (d->deviceManager->defaultDevice(dev->type()) == dev) + name = tr("%1 (default for %2)").arg(dev->displayName(), dev->displayType()); + else + name = dev->displayName(); return name; } |