Sort the devices in TelldusCenter by its name.
If anyone thinks to breaks their preferred order, please read http://xkcd.com/1172/ This closes #112.
This commit is contained in:
parent
475fdb9d59
commit
9a28b1444b
3 changed files with 19 additions and 7 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "devicemodel.h"
|
#include "devicemodel.h"
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
class MethodDelegate : public QStyledItemDelegate {
|
class MethodDelegate : public QStyledItemDelegate {
|
||||||
|
@ -32,7 +33,7 @@ void DeviceView::setModel ( QAbstractItemModel * model ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceView::rowsUpdated ( const QModelIndex & /*parent*/, int start, int end ) {
|
void DeviceView::rowsUpdated ( const QModelIndex & /*parent*/, int start, int end ) {
|
||||||
DeviceModel *model = qobject_cast<DeviceModel*>( this->model() );
|
QSortFilterProxyModel *model = qobject_cast<QSortFilterProxyModel*>( this->model() );
|
||||||
if (!model) {
|
if (!model) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -56,10 +57,15 @@ QWidget *MethodDelegate::createEditor(QWidget *parent, const QStyleOptionViewIte
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DeviceModel *model = qobject_cast<DeviceModel*>( p->model() );
|
QSortFilterProxyModel *sModel = qobject_cast<QSortFilterProxyModel*>( p->model() );
|
||||||
|
if (!sModel) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceModel *model = qobject_cast<DeviceModel*>( sModel->sourceModel() );
|
||||||
if (!model) {
|
if (!model) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
MethodWidget *widget = new MethodWidget(model->device(index), parent);
|
MethodWidget *widget = new MethodWidget(model->device(sModel->mapToSource(index)), parent);
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,11 @@ DeviceWidget::DeviceWidget(QWidget *parent) :
|
||||||
removeToolButton(this),
|
removeToolButton(this),
|
||||||
editToolButton(this)
|
editToolButton(this)
|
||||||
{
|
{
|
||||||
deviceView.setModel( &model );
|
sortedModel.setSourceModel(&model);
|
||||||
|
sortedModel.setDynamicSortFilter(true);
|
||||||
|
sortedModel.setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
sortedModel.sort(1, Qt::AscendingOrder);
|
||||||
|
deviceView.setModel( &sortedModel );
|
||||||
deviceView.resizeColumnsToContents();
|
deviceView.resizeColumnsToContents();
|
||||||
deviceView.resizeRowsToContents();
|
deviceView.resizeRowsToContents();
|
||||||
connect( &deviceView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(listActivated(const QModelIndex &)) );
|
connect( &deviceView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(listActivated(const QModelIndex &)) );
|
||||||
|
@ -134,7 +138,7 @@ void DeviceWidget::deleteDevice() {
|
||||||
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
|
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
|
||||||
msgBox.setDefaultButton( QMessageBox::No );
|
msgBox.setDefaultButton( QMessageBox::No );
|
||||||
if ( msgBox.exec() == QMessageBox::Yes) {
|
if ( msgBox.exec() == QMessageBox::Yes) {
|
||||||
QModelIndex index = deviceView.currentIndex();
|
QModelIndex index = sortedModel.mapToSource(deviceView.currentIndex());
|
||||||
Device *device = model.device(index);
|
Device *device = model.device(index);
|
||||||
if (device) {
|
if (device) {
|
||||||
device->remove();
|
device->remove();
|
||||||
|
@ -143,7 +147,7 @@ void DeviceWidget::deleteDevice() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceWidget::editDevice() {
|
void DeviceWidget::editDevice() {
|
||||||
QModelIndex index = deviceView.currentIndex();
|
QModelIndex index = sortedModel.mapToSource(deviceView.currentIndex());
|
||||||
Device device( model.deviceId(index), 0 );
|
Device device( model.deviceId(index), 0 );
|
||||||
|
|
||||||
QDialog *dialog;
|
QDialog *dialog;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
#include <QtGui/QTableView>
|
#include <QtGui/QTableView>
|
||||||
#include <QtGui/QToolButton>
|
#include <QtGui/QToolButton>
|
||||||
|
#include <QtGui/QSortFilterProxyModel>
|
||||||
#include "devicemodel.h"
|
#include "devicemodel.h"
|
||||||
#include "deviceview.h"
|
#include "deviceview.h"
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceModel model;
|
DeviceModel model;
|
||||||
|
QSortFilterProxyModel sortedModel;
|
||||||
DeviceView deviceView;
|
DeviceView deviceView;
|
||||||
QToolButton addToolButton, removeToolButton, editToolButton;
|
QToolButton addToolButton, removeToolButton, editToolButton;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue