diff --git a/ChangeLog b/ChangeLog index f9af5fac..f39c32bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20965,3 +20965,7 @@ * Added 'RDNodeSlotsModel'. * Refactored the 'Viewing Livewire Node' dialog in rdadmin(1) to use the model-based API. +2021-02-01 Fred Gleason + * Added 'RDGpioSlotsModel'. + * Refactored the 'Livewire GPIO Source Assignments' dialog in + rdadmin(1) to use the model-based API. diff --git a/lib/Makefile.am b/lib/Makefile.am index 477ec2ea..b850d60d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -145,6 +145,7 @@ dist_librd_la_SOURCES = dbversion.h\ rdgetpasswd.cpp rdgetpasswd.h\ rdgpio.cpp rdgpio.h\ rdgpioselector.cpp rdgpioselector.h\ + rdgpioslotsmodel.cpp rdgpioslotsmodel.h\ rdgrid.cpp rdgrid.h\ rdgroup.cpp rdgroup.h\ rdgroup_list.cpp rdgroup_list.h\ @@ -328,6 +329,7 @@ nodist_librd_la_SOURCES = moc_rd3emptycart.cpp\ moc_rdgetpasswd.cpp\ moc_rdgpio.cpp\ moc_rdgpioselector.cpp\ + moc_rdgpioslotsmodel.cpp\ moc_rdgrouplistmodel.cpp\ moc_rdhotkeys.cpp\ moc_rdhotkeylist.cpp\ diff --git a/lib/lib.pro b/lib/lib.pro index b0a8d4e2..a20038ca 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -106,6 +106,7 @@ SOURCES += rdframe.cpp SOURCES += rdget_ath.cpp SOURCES += rdgetpasswd.cpp SOURCES += rdgpioselector.cpp +SOURCES += rdgpioslotsmodel.cpp SOURCES += rdgrid.cpp SOURCES += rdgroup.cpp SOURCES += rdgroup_list.cpp @@ -274,6 +275,7 @@ HEADERS += rdframe.h HEADERS += rdget_ath.h HEADERS += rdgetpasswd.h HEADERS += rdgpioselector.h +HEADERS += rdgpioslotsmodel.h HEADERS += rdgrid.h HEADERS += rdgpio.h HEADERS += rdgroup_list.h diff --git a/lib/librd_cs.ts b/lib/librd_cs.ts index db577025..2344ae37 100644 --- a/lib/librd_cs.ts +++ b/lib/librd_cs.ts @@ -2505,6 +2505,29 @@ pro dobu zprávy. PIN: + + RDGpioSlotsModel + + Lines + + + + Source # + + + + Surface Address + + + + [none] + + + + [all] + + + RDGroupListModel diff --git a/lib/librd_de.ts b/lib/librd_de.ts index 6378b7ec..a559957d 100644 --- a/lib/librd_de.ts +++ b/lib/librd_de.ts @@ -2482,6 +2482,29 @@ figure for the report period. PIN: + + RDGpioSlotsModel + + Lines + + + + Source # + + + + Surface Address + + + + [none] + + + + [all] + + + RDGroupListModel diff --git a/lib/librd_es.ts b/lib/librd_es.ts index d8b2b564..27bb1da9 100644 --- a/lib/librd_es.ts +++ b/lib/librd_es.ts @@ -2477,6 +2477,29 @@ para el período a reportar. Pin: + + RDGpioSlotsModel + + Lines + + + + Source # + + + + Surface Address + + + + [none] + + + + [all] + + + RDGroupListModel diff --git a/lib/librd_fr.ts b/lib/librd_fr.ts index ce6006d0..bdd02ebc 100644 --- a/lib/librd_fr.ts +++ b/lib/librd_fr.ts @@ -2128,6 +2128,29 @@ figure for the report period. + + RDGpioSlotsModel + + Lines + + + + Source # + + + + Surface Address + + + + [none] + + + + [all] + + + RDGroupListModel diff --git a/lib/librd_nb.ts b/lib/librd_nb.ts index 8faae615..ff938768 100644 --- a/lib/librd_nb.ts +++ b/lib/librd_nb.ts @@ -2463,6 +2463,29 @@ for rapportperioden. Pin-nummer: + + RDGpioSlotsModel + + Lines + + + + Source # + + + + Surface Address + + + + [none] + + + + [all] + + + RDGroupListModel diff --git a/lib/librd_nn.ts b/lib/librd_nn.ts index 8faae615..ff938768 100644 --- a/lib/librd_nn.ts +++ b/lib/librd_nn.ts @@ -2463,6 +2463,29 @@ for rapportperioden. Pin-nummer: + + RDGpioSlotsModel + + Lines + + + + Source # + + + + Surface Address + + + + [none] + + + + [all] + + + RDGroupListModel diff --git a/lib/librd_pt_BR.ts b/lib/librd_pt_BR.ts index 3230dae9..3366fb4d 100644 --- a/lib/librd_pt_BR.ts +++ b/lib/librd_pt_BR.ts @@ -2470,6 +2470,29 @@ para o período do relatório Pin: + + RDGpioSlotsModel + + Lines + + + + Source # + + + + Surface Address + + + + [none] + + + + [all] + + + RDGroupListModel diff --git a/lib/rdgpioslotsmodel.cpp b/lib/rdgpioslotsmodel.cpp new file mode 100644 index 00000000..e2f6b909 --- /dev/null +++ b/lib/rdgpioslotsmodel.cpp @@ -0,0 +1,297 @@ +// rdgpioslotsmodel.cpp +// +// Data model for Livewire multicast GPIO slots +// +// (C) Copyright 2021 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#include "rdapplication.h" +#include "rdescape_string.h" +#include "rdgpioslotsmodel.h" + +RDGpioSlotsModel::RDGpioSlotsModel(RDMatrix *mtx,int slot_quan,QObject *parent) + : QAbstractTableModel(parent) +{ + d_mtx=mtx; + d_slot_quantity=slot_quan; + + // + // Column Attributes + // + unsigned left=Qt::AlignLeft|Qt::AlignVCenter; + unsigned center=Qt::AlignCenter; + // unsigned right=Qt::AlignRight|Qt::AlignVCenter; + + d_headers.push_back(tr("Lines")); + d_alignments.push_back(center); + + d_headers.push_back(tr("Source #")); + d_alignments.push_back(center); + + d_headers.push_back(tr("Surface Address")); + d_alignments.push_back(left); + + + updateModel(); +} + + +RDGpioSlotsModel::~RDGpioSlotsModel() +{ +} + + +QPalette RDGpioSlotsModel::palette() +{ + return d_palette; +} + + +void RDGpioSlotsModel::setPalette(const QPalette &pal) +{ + d_palette=pal; +} + + +void RDGpioSlotsModel::setFont(const QFont &font) +{ + d_font=font; + d_bold_font=font; + d_bold_font.setWeight(QFont::Bold); +} + + +int RDGpioSlotsModel::columnCount(const QModelIndex &parent) const +{ + return d_headers.size(); +} + + +int RDGpioSlotsModel::rowCount(const QModelIndex &parent) const +{ + return d_texts.size(); +} + + +QVariant RDGpioSlotsModel::headerData(int section,Qt::Orientation orient, + int role) const +{ + if((orient==Qt::Horizontal)&&(role==Qt::DisplayRole)) { + return d_headers.at(section); + } + return QVariant(); +} + + +QVariant RDGpioSlotsModel::data(const QModelIndex &index,int role) const +{ + QString str; + int col=index.column(); + int row=index.row(); + + if(row list; + for(int i=0;ifirst()) { + updateRow(row.row(),q); + emit dataChanged(createIndex(row.row(),0), + createIndex(row.row(),columnCount())); + } + delete q; + } +} + + +void RDGpioSlotsModel::refresh(int id) +{ + for(int i=0;i texts; + + RDSqlQuery *q=NULL; + QString sql=sqlFields()+ + "where "+ + "STATION_NAME=\""+RDEscapeString(d_mtx->station())+"\" && "+ + QString().sprintf("MATRIX=%d && ",d_mtx->matrix())+ + QString().sprintf("SLOT<%d ",d_slot_quantity/5)+ + "order by SLOT "; + beginResetModel(); + d_texts.clear(); + q=new RDSqlQuery(sql); + while(q->next()) { + d_ids.push_back(0); + d_texts.push_back(texts); + updateRow(d_texts.size()-1,q); + } + delete q; + endResetModel(); +} + + +void RDGpioSlotsModel::updateRowLine(int line) +{ + if(linefirst()) { + updateRow(line,q); + } + delete q; + } +} + + +void RDGpioSlotsModel::updateRow(int row,RDSqlQuery *q) +{ + QList texts; + + // Lines + texts.push_back(QString().sprintf("%d - %d",5*row+1,5*row+5)); + + // Source Number + if(q->value(2).toInt()>0) { + texts.push_back(QString().sprintf("%05d",q->value(2).toInt())); + } + else { + texts.push_back(tr("[none]")); + } + + // Surface Address + if(q->value(3).toString().isEmpty()) { + texts.push_back(tr("[all]")); + } + else { + texts.push_back(q->value(3)); + } + + d_ids[row]=q->value(0).toInt(); + d_texts[row]=texts; +} + + +QString RDGpioSlotsModel::sqlFields() const +{ + QString sql=QString("select ")+ + "ID," // 00 + "SLOT,"+ // 01 + "SOURCE_NUMBER," // 02 + "IP_ADDRESS "+ // 03 + "from LIVEWIRE_GPIO_SLOTS "; + + return sql; +} diff --git a/lib/rdgpioslotsmodel.h b/lib/rdgpioslotsmodel.h new file mode 100644 index 00000000..d06c23d7 --- /dev/null +++ b/lib/rdgpioslotsmodel.h @@ -0,0 +1,75 @@ +// rdgpioslotsmodel.h +// +// Data model for Livewire multicast GPIO slots +// +// (C) Copyright 2021 Fred Gleason +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#ifndef RDGPIOSLOTSMODEL_H +#define RDGPIOSLOTSMODEL_H + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +class RDGpioSlotsModel : public QAbstractTableModel +{ + Q_OBJECT + public: + RDGpioSlotsModel(RDMatrix *mtx,int slot_quan,QObject *parent=0); + ~RDGpioSlotsModel(); + QPalette palette(); + void setPalette(const QPalette &pal); + void setFont(const QFont &font); + int columnCount(const QModelIndex &parent=QModelIndex()) const; + int rowCount(const QModelIndex &parent=QModelIndex()) const; + QVariant headerData(int section,Qt::Orientation orient, + int role=Qt::DisplayRole) const; + QVariant data(const QModelIndex &index,int role=Qt::DisplayRole) const; + int slotId(const QModelIndex &row) const; + QModelIndex addSlot(int id); + void removeSlot(const QModelIndex &row); + void removeSlot(int id); + void refresh(const QModelIndex &row); + void refresh(int id); + + protected: + void updateModel(); + void updateRowLine(int line); + void updateRow(int row,RDSqlQuery *q); + QString sqlFields() const; + + private: + QPalette d_palette; + QFont d_font; + QFont d_bold_font; + QList d_headers; + QList d_alignments; + QList > d_texts; + QList d_ids; + RDMatrix *d_mtx; + int d_slot_quantity; +}; + + +#endif // RDGPIOSLOTSMODEL_H diff --git a/lib/rdresourcelistmodel.cpp b/lib/rdresourcelistmodel.cpp index dde63842..77608ad6 100644 --- a/lib/rdresourcelistmodel.cpp +++ b/lib/rdresourcelistmodel.cpp @@ -340,7 +340,7 @@ void RDResourceListModel::updateRow(int row,RDSqlQuery *q) } break; - defaults: + default: break; } diff --git a/rdadmin/edit_livewiregpio.cpp b/rdadmin/edit_livewiregpio.cpp index 10f781b3..d4da6556 100644 --- a/rdadmin/edit_livewiregpio.cpp +++ b/rdadmin/edit_livewiregpio.cpp @@ -2,7 +2,7 @@ // // Edit a Rivendell Livewire GPIO Slot Association // -// (C) Copyright 2013-2019 Fred Gleason +// (C) Copyright 2013-2021 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -23,36 +23,27 @@ #include #include +#include -#include +#include "edit_livewiregpio.h" -EditLiveWireGpio::EditLiveWireGpio(int slot,int *source,QHostAddress *addr, - QWidget *parent) +EditLiveWireGpio::EditLiveWireGpio(QWidget *parent) : RDDialog(parent) { - setModal(true); - - edit_slot=slot; - edit_source=source; - edit_address=addr; - // // Fix the Window Size // - setMinimumWidth(sizeHint().width()); - setMaximumWidth(sizeHint().width()); - setMinimumHeight(sizeHint().height()); - setMaximumHeight(sizeHint().height()); + setMinimumSize(sizeHint()); + setMaximumSize(sizeHint()); setWindowTitle("RDAdmin - "+tr("Edit GPIO Source")); // // GPIO Lines // - QLabel *label=new QLabel(tr("GPIO Lines")+ - QString().sprintf(" %d - %d",5*slot+1,5*slot+5),this); - label->setGeometry(10,10,sizeHint().width()-20,20); - label->setFont(labelFont()); - label->setAlignment(Qt::AlignCenter); + edit_title_label=new QLabel(this); + edit_title_label->setGeometry(10,10,sizeHint().width()-20,20); + edit_title_label->setFont(labelFont()); + edit_title_label->setAlignment(Qt::AlignCenter); // // Livewire Source Number @@ -61,7 +52,7 @@ EditLiveWireGpio::EditLiveWireGpio(int slot,int *source,QHostAddress *addr, edit_source_number_spin->setGeometry(130,32,60,20); edit_source_number_spin->setRange(0,RD_LIVEWIRE_MAX_SOURCE); edit_source_number_spin->setSpecialValueText(tr("None")); - label=new QLabel(tr("Livewire Source: "),this); + QLabel *label=new QLabel(tr("Livewire Source: "),this); label->setGeometry(10,32,115,20); label->setFont(labelFont()); label->setAlignment(Qt::AlignVCenter|Qt::AlignRight); @@ -94,14 +85,6 @@ EditLiveWireGpio::EditLiveWireGpio(int slot,int *source,QHostAddress *addr, button->setFont(buttonFont()); button->setText(tr("&Cancel")); connect(button,SIGNAL(clicked()),this,SLOT(cancelData())); - - // - // Load Data - // - edit_source_number_spin->setValue(*edit_source); - if(!edit_address->isNull()) { - edit_ip_address_edit->setText(edit_address->toString()); - } } @@ -117,6 +100,37 @@ QSizePolicy EditLiveWireGpio::sizePolicy() const } +int EditLiveWireGpio::exec(int slot_id) +{ + QHostAddress addr; + + edit_id=slot_id; + + QString sql=QString("select ")+ + "SLOT,"+ // 00 + "SOURCE_NUMBER,"+ // 01 + "IP_ADDRESS "+ // 02 + "from LIVEWIRE_GPIO_SLOTS where "+ + QString().sprintf("ID=%u",slot_id); + RDSqlQuery *q=new RDSqlQuery(sql); + if(q->first()) { + edit_title_label-> + setText(tr("GPIO Lines")+ + QString().sprintf(" %d - %d", + 5*q->value(0).toInt()+1,5*q->value(0).toInt()+5)); + edit_source_number_spin->setValue(q->value(1).toInt()); + if(addr.setAddress(q->value(2).toString())) { + edit_ip_address_edit->setText(addr.toString()); + } + else { + edit_ip_address_edit->setText(""); + } + } + + return QDialog::exec(); +} + + void EditLiveWireGpio::okData() { QHostAddress addr; @@ -125,17 +139,20 @@ void EditLiveWireGpio::okData() if(addr.isNull()&&(!edit_ip_address_edit->text().isEmpty())&& (edit_ip_address_edit->text()!="0.0.0.0")) { QMessageBox::warning(this,"RDAdmin - "+tr("Invalid IP Address"), - tr("The IP address is invalid!")); + tr("The Surface Address is invalid!")); return; } - *edit_source=edit_source_number_spin->value(); - edit_address->setAddress(addr.toString()); + QString sql=QString("update LIVEWIRE_GPIO_SLOTS set ")+ + QString().sprintf("SOURCE_NUMBER=%d,",edit_source_number_spin->value())+ + "IP_ADDRESS=\""+RDEscapeString(addr.toString())+"\" "+ + QString().sprintf("where ID=%u",edit_id); + RDSqlQuery::apply(sql); - done(0); + done(true); } void EditLiveWireGpio::cancelData() { - done(-1); + done(false); } diff --git a/rdadmin/edit_livewiregpio.h b/rdadmin/edit_livewiregpio.h index 764e69ca..651b789b 100644 --- a/rdadmin/edit_livewiregpio.h +++ b/rdadmin/edit_livewiregpio.h @@ -2,7 +2,7 @@ // // Edit a Rivendell Livewire GPIO Slot Association // -// (C) Copyright 2013-2019 Fred Gleason +// (C) Copyright 2013-2021 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -21,9 +21,10 @@ #ifndef EDIT_LIVEWIREGPIO_H #define EDIT_LIVEWIREGPIO_H -#include -#include -#include +#include +#include +#include +#include #include #include @@ -32,18 +33,20 @@ class EditLiveWireGpio : public RDDialog { Q_OBJECT public: - EditLiveWireGpio(int slot,int *source,QHostAddress *addr,QWidget *parent=0); + EditLiveWireGpio(QWidget *parent=0); QSize sizeHint() const; QSizePolicy sizePolicy() const; + public slots: + int exec(int slot_id); + private slots: void okData(); void cancelData(); private: - int edit_slot; - int *edit_source; - QHostAddress *edit_address; + int edit_id; + QLabel *edit_title_label; QSpinBox *edit_source_number_spin; QLineEdit *edit_ip_address_edit; }; diff --git a/rdadmin/edit_matrix.cpp b/rdadmin/edit_matrix.cpp index 847dfe4d..ef5b9f83 100644 --- a/rdadmin/edit_matrix.cpp +++ b/rdadmin/edit_matrix.cpp @@ -1068,8 +1068,9 @@ void EditMatrix::livewireButtonData() void EditMatrix::livewireGpioButtonData() { - ListLiveWireGpios *dialog=new ListLiveWireGpios(edit_matrix, - edit_gpis_box->value()/RD_LIVEWIRE_GPIO_BUNDLE_SIZE,this); + AddGpioSlots(); + ListLiveWireGpios *dialog= + new ListLiveWireGpios(edit_matrix,edit_gpis_box->value(),this); dialog->exec(); delete dialog; } @@ -1326,6 +1327,8 @@ bool EditMatrix::WriteMatrix() AddEndpoints(RDMatrix::Output); AddResources(RDMatrix::VguestTypeRelay); AddResources(RDMatrix::VguestTypeDisplay); + AddGpioSlots(); + PurgeGpioSlots(); // // Update GPIO Tables @@ -1544,8 +1547,8 @@ void EditMatrix::AddResources(RDMatrix::VguestType type) const sql+=QString().sprintf("NUMBER=%d",i+1); RDSqlQuery::apply(sql); } + delete q; } - delete q; } @@ -1610,3 +1613,40 @@ bool EditMatrix::ConfirmPruneResources(RDMatrix::VguestType type) delete q; return true; } + + +void EditMatrix::AddGpioSlots() +{ + if(edit_matrix->type()==RDMatrix::LiveWireMcastGpio) { + int bundle_end=edit_gpis_box->value()/5; + for(int i=0;istation())+"\" && "+ + QString().sprintf("MATRIX=%d && ",edit_matrix->matrix())+ + QString().sprintf("SLOT=%d",i); + RDSqlQuery *q=new RDSqlQuery(sql); + if(!q->first()) { + sql=QString("insert into LIVEWIRE_GPIO_SLOTS set ")+ + "STATION_NAME=\""+RDEscapeString(edit_matrix->station())+"\","+ + QString().sprintf("MATRIX=%d,",edit_matrix->matrix())+ + QString().sprintf("SLOT=%d",i); + RDSqlQuery::apply(sql); + } + delete q; + } + } +} + + +void EditMatrix::PurgeGpioSlots() +{ + if(edit_matrix->type()==RDMatrix::LiveWireMcastGpio) { + QString sql=QString("delete from LIVEWIRE_GPIO_SLOTS where ")+ + "STATION_NAME=\""+RDEscapeString(edit_matrix->station())+"\" && "+ + QString().sprintf("MATRIX=%d && ",edit_matrix->matrix())+ + QString().sprintf("SLOT>=%d",edit_gpis_box->value()/5); + RDSqlQuery::apply(sql); + } +} diff --git a/rdadmin/edit_matrix.h b/rdadmin/edit_matrix.h index 9b85fe0f..83d3ee17 100644 --- a/rdadmin/edit_matrix.h +++ b/rdadmin/edit_matrix.h @@ -77,6 +77,9 @@ class EditMatrix : public RDDialog void PruneResources(RDMatrix::VguestType type) const; bool ConfirmPruneResources(RDMatrix::VguestType type); + void AddGpioSlots(); + void PurgeGpioSlots(); + RDMatrix *edit_matrix; QString edit_stationname; int edit_matrix_number; @@ -142,9 +145,7 @@ class EditMatrix : public RDDialog QSpinBox *edit_card_box; QLabel *edit_displays_label; QSpinBox *edit_displays_box; - }; -#endif - +#endif // EDIT_MATRIX_H diff --git a/rdadmin/list_livewiregpios.cpp b/rdadmin/list_livewiregpios.cpp index da0976b3..42e04892 100644 --- a/rdadmin/list_livewiregpios.cpp +++ b/rdadmin/list_livewiregpios.cpp @@ -2,7 +2,7 @@ // // List Rivendell Livewire GPIO Slot Associations // -// (C) Copyright 2013-2019 Fred Gleason +// (C) Copyright 2013-2021 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -30,8 +30,6 @@ ListLiveWireGpios::ListLiveWireGpios(RDMatrix *matrix,int slot_quan, QWidget *parent) : RDDialog(parent) { - setModal(true); - // // Fix the Window Size // @@ -41,25 +39,24 @@ ListLiveWireGpios::ListLiveWireGpios(RDMatrix *matrix,int slot_quan, list_slot_quan=slot_quan; setWindowTitle("RDAdmin - "+tr("Livewire GPIO Source Assignments")); + // + // Dialogs + // + list_gpio_dialog=new EditLiveWireGpio(this); + // // Matrix List Box // - list_view=new RDListView(this); - list_title_label=new QLabel(list_view,tr("Switchers:"),this); - list_title_label->setFont(labelFont()); - list_view->setAllColumnsShowFocus(true); - list_view->setItemMargin(5); - list_view->addColumn(tr("Lines")); - list_view->setColumnAlignment(0,Qt::AlignHCenter); - list_view->addColumn(tr("Source #")); - list_view->setColumnAlignment(1,Qt::AlignCenter); - list_view->addColumn(tr("Surface Address")); - list_view->setColumnAlignment(2,Qt::AlignCenter); - list_view->setColumnSortType(0,RDListView::GpioSort); - connect(list_view,SIGNAL(doubleClicked(Q3ListViewItem *,const QPoint &,int)), - this,SLOT(doubleClickedData(Q3ListViewItem *,const QPoint &,int))); - - RefreshList(); + list_view=new RDTableView(this); + list_model=new RDGpioSlotsModel(matrix,slot_quan,this); + list_model->setFont(defaultFont()); + list_model->setPalette(palette()); + list_view->setModel(list_model); + connect(list_view,SIGNAL(doubleClicked(const QModelIndex &)), + this,SLOT(doubleClickedData(const QModelIndex &))); + connect(list_model,SIGNAL(modelReset()), + list_view,SLOT(resizeColumnsToContents())); + list_view->resizeColumnsToContents(); // // Edit Button @@ -70,28 +67,21 @@ ListLiveWireGpios::ListLiveWireGpios(RDMatrix *matrix,int slot_quan, connect(list_edit_button,SIGNAL(clicked()),this,SLOT(editData())); // - // Ok Button + // Close Button // - list_ok_button=new QPushButton(this); - list_ok_button->setDefault(true); - list_ok_button->setFont(buttonFont()); - list_ok_button->setText(tr("&OK")); - connect(list_ok_button,SIGNAL(clicked()),this,SLOT(okData())); - - // - // Cancel Button - // - list_cancel_button=new QPushButton(this); - list_cancel_button->setDefault(true); - list_cancel_button->setFont(buttonFont()); - list_cancel_button->setText(tr("&Cancel")); - connect(list_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData())); + list_close_button=new QPushButton(this); + list_close_button->setDefault(true); + list_close_button->setFont(buttonFont()); + list_close_button->setText(tr("&Close")); + connect(list_close_button,SIGNAL(clicked()),this,SLOT(closeData())); } ListLiveWireGpios::~ListLiveWireGpios() { + delete list_gpio_dialog; delete list_view; + delete list_model; } @@ -109,129 +99,33 @@ QSizePolicy ListLiveWireGpios::sizePolicy() const void ListLiveWireGpios::editData() { - if(list_view->selectedItem()==NULL) { + QModelIndexList rows=list_view->selectionModel()->selectedRows(); + + if(rows.size()!=1) { return; } - int source=list_view->currentItem()->text(1).toInt(); - QHostAddress addr; - addr.setAddress(list_view->currentItem()->text(2)); - EditLiveWireGpio *d= - new EditLiveWireGpio(list_view->currentItem()->text(0).toInt(), - &source,&addr); - if(d->exec()==0) { - if(source==0) { - list_view->currentItem()->setText(1,tr("[none]")); - } - else { - list_view->currentItem()->setText(1,QString().sprintf("%d",source)); - } - if(addr.isNull()) { - list_view->currentItem()->setText(2,tr("[all]")); - } - else { - list_view->currentItem()->setText(2,addr.toString()); - } + int id=list_model->slotId(rows.first()); + if(list_gpio_dialog->exec(id)) { + list_model->refresh(rows.first()); } - delete d; } -void ListLiveWireGpios::doubleClickedData(Q3ListViewItem *item,const QPoint &pt, - int col) +void ListLiveWireGpios::doubleClickedData(const QModelIndex &index) { editData(); } -void ListLiveWireGpios::okData() +void ListLiveWireGpios::closeData() { - QString sql; - RDSqlQuery *q; - int slot=0; - QString addr_str="NULL"; - - RDListViewItem *item=(RDListViewItem *)list_view->firstChild(); - while(item!=NULL) { - QHostAddress addr; - addr_str="NULL"; - addr.setAddress(item->text(2)); - if(!addr.isNull()) { - addr_str="\""+addr.toString()+"\""; - } - sql=QString("update LIVEWIRE_GPIO_SLOTS set ")+ - QString().sprintf("SOURCE_NUMBER=%d,",item->text(1).toInt())+ - "IP_ADDRESS="+addr_str+" "+ - "where (STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\")&&"+ - QString().sprintf("(MATRIX=%d)&&",list_matrix->matrix())+ - QString().sprintf("(SLOT=%d)",slot); - q=new RDSqlQuery(sql); - delete q; - slot++; - item=(RDListViewItem *)item->nextSibling(); - } - - done(0); -} - - -void ListLiveWireGpios::cancelData() -{ - done(-1); + done(true); } void ListLiveWireGpios::resizeEvent(QResizeEvent *e) { - list_view->setGeometry(10,24,size().width()-20,size().height()-94); - list_title_label->setGeometry(14,5,85,19); + list_view->setGeometry(10,3,size().width()-20,size().height()-73); list_edit_button->setGeometry(10,size().height()-60,80,50); - list_ok_button->setGeometry(size().width()-180,size().height()-60,80,50); - list_cancel_button->setGeometry(size().width()-90,size().height()-60,80,50); -} - - -void ListLiveWireGpios::RefreshList() -{ - Q3ListViewItem *l; - QString sql; - RDSqlQuery *q; - RDSqlQuery *q1; - - list_view->clear(); - sql=QString("select SLOT,SOURCE_NUMBER,IP_ADDRESS from LIVEWIRE_GPIO_SLOTS ")+ - "where (STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\")&&"+ - QString().sprintf("(MATRIX=%d) ",list_matrix->matrix())+ - "order by SLOT"; - q=new RDSqlQuery(sql); - q->first(); - for(int i=0;isetText(0,QString().sprintf("%d - %d",5*i+1,5*i+5)); - if(q->isValid()&&(q->value(0).toInt()==i)) { - if(q->value(1).toInt()==0) { - l->setText(1,tr("[none]")); - } - else { - l->setText(1,QString().sprintf("%d",q->value(1).toInt())); - } - if(q->value(2).toString().isEmpty()) { - l->setText(2,tr("[all]")); - } - else { - l->setText(2,q->value(2).toString()); - } - q->next(); - } - else { - sql=QString("insert into LIVEWIRE_GPIO_SLOTS set ")+ - "STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\","+ - QString().sprintf("MATRIX=%d,",list_matrix->matrix())+ - QString().sprintf("SLOT=%d",i); - q1=new RDSqlQuery(sql); - delete q1; - l->setText(1,tr("[none]")); - l->setText(2,tr("[all]")); - } - } - delete q; + list_close_button->setGeometry(size().width()-90,size().height()-60,80,50); } diff --git a/rdadmin/list_livewiregpios.h b/rdadmin/list_livewiregpios.h index 3e188e6d..339bfd7d 100644 --- a/rdadmin/list_livewiregpios.h +++ b/rdadmin/list_livewiregpios.h @@ -2,7 +2,7 @@ // // List Rivendell Livewire GPIO Slot Associations // -// (C) Copyright 2013-2019 Fred Gleason +// (C) Copyright 2013-2021 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -21,13 +21,16 @@ #ifndef LIST_LIVEWIREGPIOS_H #define LIST_LIVEWIREGPIOS_H -#include #include #include #include -#include +//#include +#include #include +#include + +#include "edit_livewiregpio.h" class ListLiveWireGpios : public RDDialog { @@ -40,22 +43,25 @@ class ListLiveWireGpios : public RDDialog private slots: void editData(); - void doubleClickedData(Q3ListViewItem *item,const QPoint &pt,int col); - void okData(); - void cancelData(); + void doubleClickedData(const QModelIndex &index); + void closeData(); + // void cancelData(); protected: void resizeEvent(QResizeEvent *e); private: - void RefreshList(); - QLabel *list_title_label; + // void RefreshList(); + // QLabel *list_title_label; QPushButton *list_edit_button; - QPushButton *list_ok_button; - QPushButton *list_cancel_button; - RDListView *list_view; + QPushButton *list_close_button; + // QPushButton *list_cancel_button; + // RDListView *list_view; + RDTableView *list_view; + RDGpioSlotsModel *list_model; RDMatrix *list_matrix; int list_slot_quan; + EditLiveWireGpio *list_gpio_dialog; }; diff --git a/rdadmin/rdadmin_cs.ts b/rdadmin/rdadmin_cs.ts index 76ea5086..235ba21e 100644 --- a/rdadmin/rdadmin_cs.ts +++ b/rdadmin/rdadmin_cs.ts @@ -2152,11 +2152,11 @@ Stále ještě chcete uložit? - The IP address is invalid! + None - None + The Surface Address is invalid! @@ -5786,7 +5786,7 @@ Stále ještě jej chcete smazat? ListLiveWireGpios Switchers: - Přepínače: + Přepínače: &Edit @@ -5794,36 +5794,24 @@ Stále ještě jej chcete smazat? &OK - &OK + &OK &Cancel - Z&rušit + Z&rušit [none] - [žádný] - - - Lines - - - - Surface Address - - - - [all] - - - - Source # - + [žádný] Livewire GPIO Source Assignments + + &Close + &Zavřít + ListMatrices diff --git a/rdadmin/rdadmin_de.ts b/rdadmin/rdadmin_de.ts index 017f16b0..8b298a80 100644 --- a/rdadmin/rdadmin_de.ts +++ b/rdadmin/rdadmin_de.ts @@ -1998,11 +1998,11 @@ Do you still want to save? - The IP address is invalid! + None - None + The Surface Address is invalid! @@ -5432,7 +5432,7 @@ Generieren ListLiveWireGpios Switchers: - Schalter: + Schalter: &Edit @@ -5440,36 +5440,24 @@ Generieren &OK - &OK + &OK &Cancel - Abbre&chen + Abbre&chen [none] - [keine] - - - Lines - - - - Surface Address - - - - [all] - - - - Source # - + [keine] Livewire GPIO Source Assignments + + &Close + &Schliessen + ListMatrices diff --git a/rdadmin/rdadmin_es.ts b/rdadmin/rdadmin_es.ts index 6dbd5e31..5760f3a6 100644 --- a/rdadmin/rdadmin_es.ts +++ b/rdadmin/rdadmin_es.ts @@ -2166,7 +2166,7 @@ Do you still want to save? - The IP address is invalid! + The Surface Address is invalid! @@ -5737,7 +5737,7 @@ Do you still want to delete it? ListLiveWireGpios Switchers: - Suicheras: + Suicheras: &Edit @@ -5745,36 +5745,20 @@ Do you still want to delete it? &OK - &Aceptar + &Aceptar &Cancel - &Cancelar - - - [none] - - - - Lines - - - - Surface Address - - - - [all] - - - - Source # - + &Cancelar Livewire GPIO Source Assignments + + &Close + &Cerrar + ListMatrices diff --git a/rdadmin/rdadmin_fr.ts b/rdadmin/rdadmin_fr.ts index 98ca461f..4811356f 100644 --- a/rdadmin/rdadmin_fr.ts +++ b/rdadmin/rdadmin_fr.ts @@ -1592,11 +1592,11 @@ Do you still want to save? - The IP address is invalid! + None - None + The Surface Address is invalid! @@ -4308,46 +4308,18 @@ Permissions ListLiveWireGpios - - Switchers: - - &Edit - - &OK - - - - &Cancel - - - - [none] - - - - Lines - - - - Surface Address - - - - [all] - - - - Source # - - Livewire GPIO Source Assignments + + &Close + + ListMatrices diff --git a/rdadmin/rdadmin_nb.ts b/rdadmin/rdadmin_nb.ts index 6efe7d36..fec27c93 100644 --- a/rdadmin/rdadmin_nb.ts +++ b/rdadmin/rdadmin_nb.ts @@ -1973,7 +1973,7 @@ Vil du framleis lagra? - The IP address is invalid! + The Surface Address is invalid! @@ -5297,7 +5297,7 @@ Klikk på "Lisens"-knappen for fleire opplysningar. ListLiveWireGpios Switchers: - Svitsjarar: + Svitsjarar: &Edit @@ -5305,36 +5305,24 @@ Klikk på "Lisens"-knappen for fleire opplysningar. &OK - &OK + &OK &Cancel - &Avbryt + &Avbryt [none] - [ingen] - - - Lines - - - - Surface Address - - - - [all] - - - - Source # - + [ingen] Livewire GPIO Source Assignments + + &Close + &Lukk + ListMatrices diff --git a/rdadmin/rdadmin_nn.ts b/rdadmin/rdadmin_nn.ts index 6efe7d36..fec27c93 100644 --- a/rdadmin/rdadmin_nn.ts +++ b/rdadmin/rdadmin_nn.ts @@ -1973,7 +1973,7 @@ Vil du framleis lagra? - The IP address is invalid! + The Surface Address is invalid! @@ -5297,7 +5297,7 @@ Klikk på "Lisens"-knappen for fleire opplysningar. ListLiveWireGpios Switchers: - Svitsjarar: + Svitsjarar: &Edit @@ -5305,36 +5305,24 @@ Klikk på "Lisens"-knappen for fleire opplysningar. &OK - &OK + &OK &Cancel - &Avbryt + &Avbryt [none] - [ingen] - - - Lines - - - - Surface Address - - - - [all] - - - - Source # - + [ingen] Livewire GPIO Source Assignments + + &Close + &Lukk + ListMatrices diff --git a/rdadmin/rdadmin_pt_BR.ts b/rdadmin/rdadmin_pt_BR.ts index 37f12415..d5796a8c 100644 --- a/rdadmin/rdadmin_pt_BR.ts +++ b/rdadmin/rdadmin_pt_BR.ts @@ -1979,7 +1979,7 @@ Você ainda quer salvar? - The IP address is invalid! + The Surface Address is invalid! @@ -5412,44 +5412,28 @@ Você ainda quer Deletar? ListLiveWireGpios Switchers: - Switchers: + Switchers: &Edit &Editar - - &OK - - &Cancel - &Cancelar + &Cancelar [none] - [Nenhum] - - - Lines - - - - Surface Address - - - - [all] - - - - Source # - + [Nenhum] Livewire GPIO Source Assignments + + &Close + &Fechar + ListMatrices