Device group functionallity added to Telldus Center.
This commit is contained in:
parent
1244d0b22c
commit
7651831397
4 changed files with 101 additions and 24 deletions
|
@ -21,20 +21,21 @@ public:
|
|||
|
||||
Device *device( const QModelIndex & );
|
||||
int deviceId( const QModelIndex & );
|
||||
|
||||
|
||||
signals:
|
||||
void deviceChange(int deviceId, int, int);
|
||||
void showMessage( const QString &title, const QString &message, const QString &detailedMessage );
|
||||
void eventTriggered( const QString &name, const QString &title );
|
||||
|
||||
private slots:
|
||||
void deviceStateChanged( int deviceId );
|
||||
void deviceChanged( int deviceId, int, int );
|
||||
void deviceStateChanged( int deviceId );
|
||||
void nameChanged ( int, const QString& );
|
||||
|
||||
|
||||
private:
|
||||
void triggerCellUpdate(int row, int column);
|
||||
int rowForId( int deviceId ) const;
|
||||
void triggerCellUpdate(int row, int column);
|
||||
// static void deviceEvent(int deviceId, int method, const char *data, int callbackId, void *context);
|
||||
static void WINAPI deviceChangeEvent(int deviceId, int, int, int, void *);
|
||||
|
||||
|
|
|
@ -44,8 +44,8 @@ DeviceWidget::DeviceWidget(QWidget *parent) :
|
|||
addToolButton.setIcon( QIcon( ":/images/list-add.png" ) );
|
||||
addToolButton.setText( tr("New") );
|
||||
addToolButton.setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
|
||||
//addToolButton.setPopupMode( QToolButton::MenuButtonPopup );
|
||||
//addToolButton.setMenu( newMenu );
|
||||
addToolButton.setPopupMode( QToolButton::MenuButtonPopup );
|
||||
addToolButton.setMenu( newMenu );
|
||||
connect(&addToolButton, SIGNAL(clicked()), this, SLOT(addDevice()));
|
||||
buttonLayout->addWidget( &addToolButton );
|
||||
|
||||
|
@ -100,16 +100,17 @@ void DeviceWidget::addDevice() {
|
|||
}
|
||||
|
||||
void DeviceWidget::addGroup() {
|
||||
/*Device *device = model.newDevice();
|
||||
|
||||
EditGroupDialog *dialog = new EditGroupDialog(device, &model);
|
||||
//Device *device = model.newDevice();
|
||||
Device device(0, 0);
|
||||
|
||||
EditGroupDialog *dialog = new EditGroupDialog(&device, &model);
|
||||
if (dialog->exec() == QDialog::Accepted) {
|
||||
device->save();
|
||||
device.save();
|
||||
} else {
|
||||
delete device;
|
||||
//delete device;
|
||||
}
|
||||
|
||||
delete dialog;*/
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
void DeviceWidget::deleteDevice() {
|
||||
|
|
|
@ -13,6 +13,12 @@
|
|||
#include <QDialogButtonBox>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QLineEdit>
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
||||
class ProxyModel : public QSortFilterProxyModel {
|
||||
public:
|
||||
ProxyModel( QObject * parent = 0 );
|
||||
|
@ -22,21 +28,41 @@ public:
|
|||
void showAllRows();
|
||||
void hideRow( int row );
|
||||
void showRow( int row );
|
||||
QString getShownIds();
|
||||
|
||||
protected:
|
||||
virtual bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const;
|
||||
private:
|
||||
QSet<int> rows;
|
||||
};
|
||||
|
||||
EditGroupDialog::EditGroupDialog(Device *d, DeviceModel *m, QWidget *parent, Qt::WFlags flags)
|
||||
class EditGroupDialog::PrivateData {
|
||||
public:
|
||||
QLineEdit *nameLineEdit;
|
||||
|
||||
};
|
||||
|
||||
|
||||
EditGroupDialog::EditGroupDialog(Device *devicein, DeviceModel *m, QWidget *parent, Qt::WFlags flags)
|
||||
:QDialog(parent, flags),
|
||||
device(d),
|
||||
model(m)
|
||||
device(devicein),
|
||||
model(m),
|
||||
d(new PrivateData)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
|
||||
QHBoxLayout *nameLayout = new QHBoxLayout;
|
||||
QLabel *nameLabel = new QLabel(this);
|
||||
nameLabel->setText( tr("&Name:") );
|
||||
d->nameLineEdit = new QLineEdit(device->name(), this );
|
||||
nameLabel->setBuddy(d->nameLineEdit);
|
||||
nameLayout->addWidget(nameLabel);
|
||||
nameLayout->addWidget(d->nameLineEdit);
|
||||
nameLayout->addStretch();
|
||||
layout->addLayout(nameLayout);
|
||||
|
||||
availableProxyModel = new ProxyModel( this );
|
||||
availableProxyModel->setSourceModel( model );
|
||||
availableProxyModel->showAllRows();
|
||||
|
@ -72,6 +98,7 @@ EditGroupDialog::EditGroupDialog(Device *d, DeviceModel *m, QWidget *parent, Qt:
|
|||
|
||||
addedProxyModel = new ProxyModel( this );
|
||||
addedProxyModel->setSourceModel( model );
|
||||
setDevicesVisible();
|
||||
|
||||
addedListView = new QTableView( this );
|
||||
addedListView->setAlternatingRowColors( true );
|
||||
|
@ -97,9 +124,31 @@ EditGroupDialog::EditGroupDialog(Device *d, DeviceModel *m, QWidget *parent, Qt:
|
|||
EditGroupDialog::~EditGroupDialog() {
|
||||
}
|
||||
|
||||
void EditGroupDialog::setDevicesVisible(){
|
||||
QString devicesstring = device->parameter("devices", "");
|
||||
QList<int> devices;
|
||||
foreach(QString device, devicesstring.split(",")) {
|
||||
devices << device.toInt();
|
||||
}
|
||||
|
||||
for (int i = 0; i < model->rowCount(); ++i){
|
||||
int id = model->deviceId(model->index(i, 0));
|
||||
if (id == device->id()) {
|
||||
//shouldnt be able to add itself, check that here
|
||||
availableProxyModel->hideRow(i);
|
||||
} else if (devices.contains(id)) {
|
||||
availableProxyModel->hideRow(i);
|
||||
addedProxyModel->showRow(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void EditGroupDialog::addClicked() {
|
||||
int row = availableProxyModel->mapToSource( availableListView->currentIndex() ).row();
|
||||
availableProxyModel->hideRow(row);
|
||||
|
||||
addedProxyModel->showRow(row);
|
||||
}
|
||||
|
||||
|
@ -111,15 +160,21 @@ void EditGroupDialog::removeClicked() {
|
|||
|
||||
void EditGroupDialog::okClicked() {
|
||||
|
||||
// if (!item || !item->isDevice()) {
|
||||
// QMessageBox msgBox;
|
||||
// msgBox.setText( tr("You must choose a device") );
|
||||
// msgBox.setInformativeText( tr("Please select the device you have.") );
|
||||
// msgBox.setIcon( QMessageBox::Critical );
|
||||
// msgBox.setStandardButtons( QMessageBox::Ok );
|
||||
// msgBox.exec();
|
||||
// return;
|
||||
// }
|
||||
if (d->nameLineEdit->text().trimmed() == "") {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText( tr("The device must have a name.") );
|
||||
msgBox.setInformativeText( tr("Please fill in a name in the field under 'Name'") );
|
||||
msgBox.setIcon( QMessageBox::Critical );
|
||||
msgBox.setStandardButtons( QMessageBox::Ok );
|
||||
msgBox.exec();
|
||||
d->nameLineEdit->setFocus();
|
||||
return;
|
||||
}
|
||||
device->setName( d->nameLineEdit->text().trimmed() );
|
||||
device->setModel("group");
|
||||
device->setProtocol("group");
|
||||
QString shownIds = addedProxyModel->getShownIds();
|
||||
device->setParameter("devices", shownIds);
|
||||
this->accept();
|
||||
}
|
||||
|
||||
|
@ -145,6 +200,21 @@ void ProxyModel::showAllRows() {
|
|||
}
|
||||
}
|
||||
|
||||
QString ProxyModel::getShownIds(){
|
||||
QStringList addedIds;
|
||||
foreach (int index, rows){ //TODO why does this crash when debugging? Unsafe?
|
||||
if(index >= 0){ //TODO why can this be
|
||||
DeviceModel *model = reinterpret_cast<DeviceModel *>(this->sourceModel());
|
||||
if (model) {
|
||||
int deviceId = model->deviceId(model->index(index, 0));
|
||||
addedIds << QString::number(deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return addedIds.join(",");
|
||||
}
|
||||
|
||||
void ProxyModel::hideRow( int row ) {
|
||||
if (rows.contains(row)) {
|
||||
rows.remove(row);
|
||||
|
@ -153,6 +223,7 @@ void ProxyModel::hideRow( int row ) {
|
|||
}
|
||||
|
||||
void ProxyModel::showRow( int row ) {
|
||||
|
||||
if (!rows.contains(row)) {
|
||||
rows.insert(row);
|
||||
invalidateFilter();
|
||||
|
|
|
@ -16,13 +16,14 @@ class EditGroupDialog : public QDialog
|
|||
public:
|
||||
EditGroupDialog(Device *device, DeviceModel *model, QWidget *parent = 0, Qt::WFlags flags = 0);
|
||||
virtual ~EditGroupDialog();
|
||||
|
||||
|
||||
private slots:
|
||||
void availableListActivated(const QModelIndex &);
|
||||
void addedListActivated(const QModelIndex &);
|
||||
void addClicked();
|
||||
void removeClicked();
|
||||
void okClicked();
|
||||
void setDevicesVisible();
|
||||
|
||||
private:
|
||||
QToolButton *addToolButton, *removeToolButton;
|
||||
|
@ -30,6 +31,9 @@ private:
|
|||
Device *device;
|
||||
DeviceModel *model;
|
||||
ProxyModel *availableProxyModel, *addedProxyModel;
|
||||
|
||||
class PrivateData;
|
||||
PrivateData *d;
|
||||
};
|
||||
|
||||
#endif // EDITGROUPDIALOG_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue