From b2f5bf72a5d122e1a1d51f9899ffaa6fe8e7cd3a Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 2 Feb 2021 19:57:51 -0500 Subject: [PATCH] 2021-02-02 Fred Gleason * Added 'RDSchedCodeListModel'. * Refactored the 'Rivendell Scheduler Codes List' dialog in rdadmin(1) to use the model-based API. Signed-off-by: Fred Gleason --- ChangeLog | 4 + lib/Makefile.am | 2 + lib/lib.pro | 2 + lib/librd_cs.ts | 11 ++ lib/librd_de.ts | 11 ++ lib/librd_es.ts | 11 ++ lib/librd_fr.ts | 11 ++ lib/librd_nb.ts | 11 ++ lib/librd_nn.ts | 11 ++ lib/librd_pt_BR.ts | 11 ++ lib/rdschedcodelistmodel.cpp | 270 +++++++++++++++++++++++++++++++++++ lib/rdschedcodelistmodel.h | 70 +++++++++ rdadmin/add_schedcodes.cpp | 91 +++++------- rdadmin/add_schedcodes.h | 30 ++-- rdadmin/edit_schedcodes.cpp | 84 ++++++----- rdadmin/edit_schedcodes.h | 17 +-- rdadmin/list_schedcodes.cpp | 155 ++++++++------------ rdadmin/list_schedcodes.h | 23 +-- 18 files changed, 592 insertions(+), 233 deletions(-) create mode 100644 lib/rdschedcodelistmodel.cpp create mode 100644 lib/rdschedcodelistmodel.h diff --git a/ChangeLog b/ChangeLog index cfae4524..27e0a8fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20986,3 +20986,7 @@ 2021-02-02 Fred Gleason * Commented out support for editing hotkeys in the 'Configure RDAirPlay' dialog in rdadmin(1). +2021-02-02 Fred Gleason + * Added 'RDSchedCodeListModel'. + * Refactored the 'Rivendell Scheduler Codes List' dialog in + rdadmin(1) to use the model-based API. diff --git a/lib/Makefile.am b/lib/Makefile.am index f855d65b..8b35add7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -228,6 +228,7 @@ dist_librd_la_SOURCES = dbversion.h\ rdrsscategorybox.cpp rdrsscategorybox.h\ rdschedcartlist.cpp rdschedcartlist.h\ rdschedcode.cpp rdschedcode.h\ + rdschedcodelistmodel.cpp rdschedcodelistmodel.h\ rdschedcodes_dialog.cpp rdschedcodes_dialog.h\ rdschedruleslist.cpp rdschedruleslist.h\ rdsegmeter.cpp rdsegmeter.h\ @@ -379,6 +380,7 @@ nodist_librd_la_SOURCES = moc_rd3emptycart.cpp\ moc_rdreplicatorlistmodel.cpp\ moc_rdresourcelistmodel.cpp\ moc_rdripc.cpp\ + moc_rdschedcodelistmodel.cpp\ moc_rdschedcodes_dialog.cpp\ moc_rdrsscategorybox.cpp\ moc_rdsegmeter.cpp\ diff --git a/lib/lib.pro b/lib/lib.pro index d0b1400f..1cc77aaa 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -170,6 +170,7 @@ SOURCES += rdripc.cpp SOURCES += rdrssschemas.cpp SOURCES += rdrsscategorybox.cpp SOURCES += rdschedcode.cpp +SOURCES += rdschedcodelistmodel.cpp SOURCES += rdsegmeter.cpp SOURCES += rdsendmail.cpp SOURCES += rdsettings.cpp @@ -343,6 +344,7 @@ HEADERS += rdripc.h HEADERS += rdrssschemas.h HEADERS += rdrsscategorybox.h HEADERS += rdschedcode.h +HEADERS += rdschedcodelistmodel.h HEADERS += rdsegmeter.h HEADERS += rdsendmail.h HEADERS += rdservicelistmodel.h diff --git a/lib/librd_cs.ts b/lib/librd_cs.ts index 57abc315..9f481346 100644 --- a/lib/librd_cs.ts +++ b/lib/librd_cs.ts @@ -3985,6 +3985,17 @@ Zkuste to, prosím, znovu! + + RDSchedCodeListModel + + Code + + + + Description + + + RDServiceListModel diff --git a/lib/librd_de.ts b/lib/librd_de.ts index 377f138e..aeb5873a 100644 --- a/lib/librd_de.ts +++ b/lib/librd_de.ts @@ -3966,6 +3966,17 @@ bitte erneut versuchen! + + RDSchedCodeListModel + + Code + + + + Description + + + RDServiceListModel diff --git a/lib/librd_es.ts b/lib/librd_es.ts index 7a8ff1f7..72bc175f 100644 --- a/lib/librd_es.ts +++ b/lib/librd_es.ts @@ -3945,6 +3945,17 @@ please try again! + + RDSchedCodeListModel + + Code + + + + Description + + + RDServiceListModel diff --git a/lib/librd_fr.ts b/lib/librd_fr.ts index 0c553118..e7530271 100644 --- a/lib/librd_fr.ts +++ b/lib/librd_fr.ts @@ -3238,6 +3238,17 @@ please try again! + + RDSchedCodeListModel + + Code + + + + Description + + + RDServiceListModel diff --git a/lib/librd_nb.ts b/lib/librd_nb.ts index b577efbb..3ba59f84 100644 --- a/lib/librd_nb.ts +++ b/lib/librd_nb.ts @@ -3848,6 +3848,17 @@ prøv ein gong til! + + RDSchedCodeListModel + + Code + + + + Description + + + RDServiceListModel diff --git a/lib/librd_nn.ts b/lib/librd_nn.ts index b577efbb..3ba59f84 100644 --- a/lib/librd_nn.ts +++ b/lib/librd_nn.ts @@ -3848,6 +3848,17 @@ prøv ein gong til! + + RDSchedCodeListModel + + Code + + + + Description + + + RDServiceListModel diff --git a/lib/librd_pt_BR.ts b/lib/librd_pt_BR.ts index ae7f3753..eff70c85 100644 --- a/lib/librd_pt_BR.ts +++ b/lib/librd_pt_BR.ts @@ -3899,6 +3899,17 @@ por favor, tente novamente! + + RDSchedCodeListModel + + Code + + + + Description + + + RDServiceListModel diff --git a/lib/rdschedcodelistmodel.cpp b/lib/rdschedcodelistmodel.cpp new file mode 100644 index 00000000..49fb7387 --- /dev/null +++ b/lib/rdschedcodelistmodel.cpp @@ -0,0 +1,270 @@ +// rdschedcodelistmodel.cpp +// +// Data model for Rivendell schedule codes +// +// (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 "rdschedcodelistmodel.h" + +RDSchedCodeListModel::RDSchedCodeListModel(QObject *parent) + : QAbstractTableModel(parent) +{ + // + // Column Attributes + // + unsigned left=Qt::AlignLeft|Qt::AlignVCenter; + // unsigned center=Qt::AlignCenter; + // unsigned right=Qt::AlignRight|Qt::AlignVCenter; + + d_headers.push_back(tr("Code")); + d_alignments.push_back(left); + + d_headers.push_back(tr("Description")); + d_alignments.push_back(left); + + updateModel(); +} + + +RDSchedCodeListModel::~RDSchedCodeListModel() +{ +} + + +QPalette RDSchedCodeListModel::palette() +{ + return d_palette; +} + + +void RDSchedCodeListModel::setPalette(const QPalette &pal) +{ + d_palette=pal; +} + + +void RDSchedCodeListModel::setFont(const QFont &font) +{ + d_font=font; + d_bold_font=font; + d_bold_font.setWeight(QFont::Bold); +} + + +int RDSchedCodeListModel::columnCount(const QModelIndex &parent) const +{ + return d_headers.size(); +} + + +int RDSchedCodeListModel::rowCount(const QModelIndex &parent) const +{ + return d_texts.size(); +} + + +QVariant RDSchedCodeListModel::headerData(int section,Qt::Orientation orient, + int role) const +{ + if((orient==Qt::Horizontal)&&(role==Qt::DisplayRole)) { + return d_headers.at(section); + } + return QVariant(); +} + + +QVariant RDSchedCodeListModel::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 RDSchedCodeListModel::refresh(const QString &scode) +{ + for(int i=0;i texts; + + RDSqlQuery *q=NULL; + QString sql=sqlFields(); + sql+="order by CODE "; + beginResetModel(); + d_texts.clear(); + q=new RDSqlQuery(sql); + while(q->next()) { + d_texts.push_back(texts); + updateRow(d_texts.size()-1,q); + } + delete q; + endResetModel(); +} + + +void RDSchedCodeListModel::updateRowLine(int line) +{ + if(linefirst()) { + updateRow(line,q); + } + delete q; + } +} + + +void RDSchedCodeListModel::updateRow(int row,RDSqlQuery *q) +{ + QList texts; + + // Code + texts.push_back(q->value(0)); + + // Description + texts.push_back(q->value(1)); + + d_texts[row]=texts; +} + + +QString RDSchedCodeListModel::sqlFields() const +{ + QString sql=QString("select ")+ + "CODE,"+ // 00 + "DESCRIPTION "+ // 01 + "from SCHED_CODES "; + + return sql; +} diff --git a/lib/rdschedcodelistmodel.h b/lib/rdschedcodelistmodel.h new file mode 100644 index 00000000..a33b461a --- /dev/null +++ b/lib/rdschedcodelistmodel.h @@ -0,0 +1,70 @@ +// rdschedcodelistmodel.h +// +// Data model for Rivendell schedule codes +// +// (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 RDSCHEDCODELISTMODEL_H +#define RDSCHEDCODELISTMODEL_H + +#include +#include +#include +#include + +#include +#include +#include + +class RDSchedCodeListModel : public QAbstractTableModel +{ + Q_OBJECT + public: + RDSchedCodeListModel(QObject *parent=0); + ~RDSchedCodeListModel(); + 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; + QString schedCode(const QModelIndex &row) const; + QModelIndex addSchedCode(const QString &scode); + void removeSchedCode(const QModelIndex &row); + void removeSchedCode(const QString &scode); + void refresh(const QModelIndex &row); + void refresh(const QString &scode); + + 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; +}; + + +#endif // RDSCHEDCODELISTMODEL_H diff --git a/rdadmin/add_schedcodes.cpp b/rdadmin/add_schedcodes.cpp index 0d47f29e..17d5286b 100644 --- a/rdadmin/add_schedcodes.cpp +++ b/rdadmin/add_schedcodes.cpp @@ -3,7 +3,7 @@ // Add scheduler codes dialog // // (C) Copyright 2005-2018 Stefan Gabriel -// (C) Copyright 2018-2019 Fred Gleason +// (C) Copyright 2018-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 @@ -19,56 +19,33 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include #include -#include -#include #include "edit_schedcodes.h" #include "add_schedcodes.h" -AddSchedCode::AddSchedCode(QString *schedCode,QWidget *parent) +AddSchedCode::AddSchedCode(QWidget *parent) : RDDialog(parent) { - setModal(true); - - schedcode_schedCode=schedCode; - // // Fix the Window Size // - setMinimumWidth(sizeHint().width()); - setMaximumWidth(sizeHint().width()); - setMinimumHeight(sizeHint().height()); - setMaximumHeight(sizeHint().height()); + setMinimumSize(sizeHint()); + setMaximumSize(sizeHint()); setWindowTitle("RDAdmin - "+tr("Add Scheduler Code")); - // - // Text Validator - // - RDTextValidator *validator=new RDTextValidator(this,"validator"); - validator->addBannedChar(' '); - // // Code Name // - schedcode_name_edit=new QLineEdit(this); - schedcode_name_edit->setGeometry(105,11,sizeHint().width()-150,19); - schedcode_name_edit->setMaxLength(10); - schedcode_name_edit->setValidator(validator); - QLabel *label=new QLabel(schedcode_name_edit,tr("&New Code:"),this); + d_code_edit=new QLineEdit(this); + d_code_edit->setGeometry(105,11,sizeHint().width()-150,19); + d_code_edit->setMaxLength(10); + QLabel *label=new QLabel(d_code_edit,tr("&New Code:"),this); label->setGeometry(10,11,90,19); label->setFont(labelFont()); label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); @@ -97,7 +74,7 @@ AddSchedCode::AddSchedCode(QString *schedCode,QWidget *parent) AddSchedCode::~AddSchedCode() { - delete schedcode_name_edit; + delete d_code_edit; } @@ -113,42 +90,38 @@ QSizePolicy AddSchedCode::sizePolicy() const } +int AddSchedCode::exec(QString *scode) +{ + d_sched_code=scode; + + d_code_edit->setText(""); + + return QDialog::exec(); +} + + void AddSchedCode::okData() { - RDSqlQuery *q; - QString sql; - - if(schedcode_name_edit->text().isEmpty()) { - QMessageBox::warning(this,tr("Invalid Name"),tr("Invalid Name!")); + if(d_code_edit->text().isEmpty()) { + QMessageBox::warning(this,"RDAdmin - "+tr("Error"), + tr("Invalid Schedule Code!")); return; } - sql=QString("insert into SCHED_CODES set ")+ - "CODE=\""+RDEscapeString(schedcode_name_edit->text())+"\""; - q=new RDSqlQuery(sql); - if(!q->isActive()) { - QMessageBox::warning(this,tr("Code Exists"),tr("Code Already Exists!"), - 1,0,0); - delete q; + QString sql=QString("insert into SCHED_CODES set ")+ + "CODE=\""+RDEscapeString(d_code_edit->text())+"\""; + if(!RDSqlQuery::apply(sql)) { + QMessageBox::warning(this,"RDAdmin - "+tr("Error"), + tr("Schedule Code Already Exists!")); return; } - delete q; + *d_sched_code=d_code_edit->text(); - EditSchedCode *schedCode= - new EditSchedCode(schedcode_name_edit->text(),"",this); - if(schedCode->exec()<0) { - delete schedCode; - done(-1); - return; - } - delete schedCode; - *schedcode_schedCode=schedcode_name_edit->text(); - done(0); + done(true); } void AddSchedCode::cancelData() { - done(-1); + done(false); } - diff --git a/rdadmin/add_schedcodes.h b/rdadmin/add_schedcodes.h index ffbf0ab7..99e608ac 100644 --- a/rdadmin/add_schedcodes.h +++ b/rdadmin/add_schedcodes.h @@ -3,7 +3,7 @@ // Add scheduler codes dialog // // (C) Copyright Stefan Gabriel -// (C) Copyright 2002-2019 Fred Gleason +// (C) Copyright 2002-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 @@ -22,27 +22,29 @@ #ifndef ADD_SCHEDCODES_H #define ADD_SCHEDCODES_H -#include -#include +#include #include class AddSchedCode : public RDDialog { Q_OBJECT - public: - AddSchedCode(QString *schedCode,QWidget *parent=0); - ~AddSchedCode(); - QSize sizeHint() const; - QSizePolicy sizePolicy() const; + public: + AddSchedCode(QWidget *parent=0); + ~AddSchedCode(); + QSize sizeHint() const; + QSizePolicy sizePolicy() const; - private slots: - void okData(); - void cancelData(); + public slots: + int exec(QString *scode); - private: - QLineEdit *schedcode_name_edit; - QString *schedcode_schedCode; + private slots: + void okData(); + void cancelData(); + + private: + QLineEdit *d_code_edit; + QString *d_sched_code; }; #endif // ADD_SCHEDCODES_H diff --git a/rdadmin/edit_schedcodes.cpp b/rdadmin/edit_schedcodes.cpp index 5bf23634..26f6f233 100644 --- a/rdadmin/edit_schedcodes.cpp +++ b/rdadmin/edit_schedcodes.cpp @@ -2,9 +2,9 @@ // // Edit scheduler codes dialog // -// Stefan Gabriel +// Based on original code by Stefan Gabriel // (C) Copyright 2005-2018 -// (C) Copyright 2002-2019 Fred Gleason +// (C) Copyright 2002-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 @@ -22,44 +22,28 @@ #include #include -#include #include "edit_group.h" #include "edit_schedcodes.h" -EditSchedCode::EditSchedCode(QString schedcode,QString description, - QWidget *parent) +EditSchedCode::EditSchedCode(QWidget *parent) : RDDialog(parent) { - setModal(true); - // // Fix the Window Size // - setMinimumWidth(sizeHint().width()); - setMaximumWidth(sizeHint().width()); - setMinimumHeight(sizeHint().height()); - setMaximumHeight(sizeHint().height()); - - schedcode_code=new QString(schedcode); - schedcode_description=new QString(description); - - setWindowTitle("RDAdmin - "+tr("Scheduler Code: ")+schedcode); - - // - // Text Validators - // - RDTextValidator *validator=new RDTextValidator(this); + setMinimumSize(sizeHint()); + setMaximumSize(sizeHint()); // // Code Name // - schedcode_name_edit=new QLineEdit(this); - schedcode_name_edit->setGeometry(125,11,100,19); - schedcode_name_edit->setMaxLength(10); - schedcode_name_edit->setReadOnly(true); + d_code_edit=new QLineEdit(this); + d_code_edit->setGeometry(125,11,100,19); + d_code_edit->setMaxLength(10); + d_code_edit->setReadOnly(true); QLabel *schedcode_name_label= - new QLabel(schedcode_name_edit,tr("Scheduler Code:"),this); + new QLabel(d_code_edit,tr("Scheduler Code:"),this); schedcode_name_label->setGeometry(10,11,110,19); schedcode_name_label->setFont(labelFont()); schedcode_name_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); @@ -67,12 +51,11 @@ EditSchedCode::EditSchedCode(QString schedcode,QString description, // // Code Description // - schedcode_description_edit=new QLineEdit(this); - schedcode_description_edit->setGeometry(125,32,sizeHint().width()-135,19); - schedcode_description_edit->setMaxLength(255); - schedcode_description_edit->setValidator(validator); + d_description_edit=new QLineEdit(this); + d_description_edit->setGeometry(125,32,sizeHint().width()-135,19); + d_description_edit->setMaxLength(255); QLabel *schedcode_description_label= - new QLabel(schedcode_description_edit,tr("Code Description:"),this); + new QLabel(d_description_edit,tr("Code Description:"),this); schedcode_description_label->setGeometry(10,32,110,19); schedcode_description_label->setFont(labelFont()); schedcode_description_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); @@ -96,19 +79,13 @@ EditSchedCode::EditSchedCode(QString schedcode,QString description, cancel_button->setFont(buttonFont()); cancel_button->setText(tr("&Cancel")); connect(cancel_button,SIGNAL(clicked()),this,SLOT(cancelData())); - - // - // Populate Fields - // - schedcode_name_edit->setText(*schedcode_code); - schedcode_description_edit->setText(*schedcode_description); } EditSchedCode::~EditSchedCode() { - delete schedcode_name_edit; - delete schedcode_description_edit; + delete d_code_edit; + delete d_description_edit; } @@ -124,24 +101,43 @@ QSizePolicy EditSchedCode::sizePolicy() const } +int EditSchedCode::exec(const QString &scode) +{ + setWindowTitle("RDAdmin - "+tr("Scheduler Code: ")+scode); + + d_code_edit->setText(scode); + + QString sql=QString("select ")+ + "DESCRIPTION "+ // 00 + "from SCHED_CODES where "+ + "CODE=\""+RDEscapeString(scode)+"\""; + RDSqlQuery *q=new RDSqlQuery(sql); + if(q->first()) { + d_description_edit->setText(q->value(0).toString()); + } + delete q; + + return QDialog::exec(); +} + + void EditSchedCode::okData() { RDSqlQuery *q; QString sql; sql=QString("update SCHED_CODES set ")+ - "DESCRIPTION=\""+RDEscapeString(schedcode_description_edit->text())+"\" "+ - "where CODE=\""+RDEscapeString(schedcode_name_edit->text())+"\""; + "DESCRIPTION=\""+RDEscapeString(d_description_edit->text())+"\" "+ + "where CODE=\""+RDEscapeString(d_code_edit->text())+"\""; q=new RDSqlQuery(sql); delete q; - *schedcode_description=schedcode_description_edit->text(); - done(0); + done(true); } void EditSchedCode::cancelData() { - done(-1); + done(false); } diff --git a/rdadmin/edit_schedcodes.h b/rdadmin/edit_schedcodes.h index be3c72ba..586c7690 100644 --- a/rdadmin/edit_schedcodes.h +++ b/rdadmin/edit_schedcodes.h @@ -2,8 +2,8 @@ // // Edit scheduler codes dialog // -// Stefan Gabriel -// (C) Copyright 2002-2019 Fred Gleason +// Based on original code by Stefan Gabriel +// (C) Copyright 2002-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 @@ -22,7 +22,7 @@ #ifndef EDIT_SCHEDCODES_H #define EDIT_SCHEDCODES_H -#include +#include #include @@ -30,20 +30,21 @@ class EditSchedCode : public RDDialog { Q_OBJECT public: - EditSchedCode(QString schedcode,QString description,QWidget *parent=0); + EditSchedCode(QWidget *parent=0); ~EditSchedCode(); QSize sizeHint() const; QSizePolicy sizePolicy() const; + public slots: + int exec(const QString &scode); + private slots: void okData(); void cancelData(); private: - QString *schedcode_code; - QString *schedcode_description; - QLineEdit *schedcode_name_edit; - QLineEdit *schedcode_description_edit; + QLineEdit *d_code_edit; + QLineEdit *d_description_edit; }; diff --git a/rdadmin/list_schedcodes.cpp b/rdadmin/list_schedcodes.cpp index 775eef2b..f413e781 100644 --- a/rdadmin/list_schedcodes.cpp +++ b/rdadmin/list_schedcodes.cpp @@ -2,8 +2,8 @@ // // The scheduler codes dialog for rdadmin // -// Stefan Gabriel -// (C) Copyright 2002-2019 Fred Gleason +// Based on original code by Stefan Gabriel +// (C) Copyright 2002-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 @@ -19,7 +19,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include +#include #include #include @@ -33,8 +33,6 @@ ListSchedCodes::ListSchedCodes(QWidget *parent) : RDDialog(parent) { - setModal(true); - // // Fix the Window Size // @@ -42,6 +40,12 @@ ListSchedCodes::ListSchedCodes(QWidget *parent) setWindowTitle("RDAdmin - "+tr("Rivendell Scheduler Codes List")); + // + // Dialogs + // + list_add_schedcode_dialog=new AddSchedCode(this); + list_edit_schedcode_dialog=new EditSchedCode(this); + // // Add Button // @@ -76,27 +80,28 @@ ListSchedCodes::ListSchedCodes(QWidget *parent) connect(list_close_button,SIGNAL(clicked()),this,SLOT(closeData())); // - // Group List + // Schedule Codes List // - list_schedCodes_view=new Q3ListView(this); - list_schedCodes_view->setAllColumnsShowFocus(true); - list_schedCodes_view->addColumn(tr("CODE")); - list_schedCodes_view->addColumn(tr("DESCRIPTION")); - QLabel *list_box_label= - new QLabel(list_schedCodes_view,tr("Scheduler Codes:"),this); - list_box_label->setFont(buttonFont()); - list_box_label->setGeometry(14,11,200,19); - connect(list_schedCodes_view, - SIGNAL(doubleClicked(Q3ListViewItem *,const QPoint &,int)), - this, - SLOT(doubleClickedData(Q3ListViewItem *,const QPoint &,int))); - - RefreshList(); + list_schedcodes_view=new RDTableView(this); + list_schedcodes_model=new RDSchedCodeListModel(this); + list_schedcodes_model->setFont(defaultFont()); + list_schedcodes_model->setPalette(palette()); + list_schedcodes_view->setModel(list_schedcodes_model); + list_schedcodes_label= + new QLabel(list_schedcodes_view,tr("Replicators:"),this); + list_schedcodes_label->setFont(labelFont()); + connect(list_schedcodes_view,SIGNAL(doubleClicked(const QModelIndex &)), + this,SLOT(doubleClickedData(const QModelIndex &))); + connect(list_schedcodes_model,SIGNAL(modelReset()), + list_schedcodes_view,SLOT(resizeColumnsToContents())); + list_schedcodes_view->resizeColumnsToContents(); } ListSchedCodes::~ListSchedCodes() { + delete list_edit_schedcode_dialog; + delete list_add_schedcode_dialog; } @@ -114,55 +119,49 @@ QSizePolicy ListSchedCodes::sizePolicy() const void ListSchedCodes::addData() { - QString schedCode; + QString scode; - AddSchedCode *add_schedCode=new AddSchedCode(&schedCode,this); - if(add_schedCode->exec()<0) { - delete add_schedCode; - return; + if(list_add_schedcode_dialog->exec(&scode)) { + QModelIndex index=list_schedcodes_model->addSchedCode(scode); + if(index.isValid()) { + list_schedcodes_view->selectRow(index.row()); + } + } + else { + QString sql=QString("delete from SCHED_CODES where ")+ + "CODE=\""+RDEscapeString(scode)+"\""; + RDSqlQuery::apply(sql); } - delete add_schedCode; - add_schedCode=NULL; - Q3ListViewItem *item=new Q3ListViewItem(list_schedCodes_view); - item->setText(0,schedCode); - RefreshItem(item); - item->setSelected(true); - list_schedCodes_view->setCurrentItem(item); - list_schedCodes_view->ensureItemVisible(item); } void ListSchedCodes::editData() { - Q3ListViewItem *item=list_schedCodes_view->selectedItem(); - if(item==NULL) { + QModelIndexList rows=list_schedcodes_view->selectionModel()->selectedRows(); + + if(rows.size()!=1) { return; } - EditSchedCode *edit_schedCode= - new EditSchedCode(item->text(0),item->text(1),this); - edit_schedCode->exec(); - delete edit_schedCode; - edit_schedCode=NULL; - RefreshItem(item); + + if(list_edit_schedcode_dialog-> + exec(list_schedcodes_model->schedCode(rows.first()))) { + list_schedcodes_model->refresh(rows.first()); + } } void ListSchedCodes::deleteData() { - Q3ListViewItem *item=list_schedCodes_view->selectedItem(); - if(item==NULL) { + QModelIndexList rows=list_schedcodes_view->selectionModel()->selectedRows(); + + if(rows.size()!=1) { return; } - QString sql; - RDSqlQuery *q; QString warning; QString str; - QString codename=item->text(0); - if(codename.isEmpty()) { - return; - } + QString codename=list_schedcodes_model->schedCode(rows.first()); if(QMessageBox::question(this,"RDAdmin - "+tr("Delete Scheduler Code"), tr("This operation will delete the selected scheduler code and")+ "\n"+tr("all of its associated data.")+" "+ @@ -174,20 +173,16 @@ void ListSchedCodes::deleteData() sql=QString("delete from DROPBOX_SCHED_CODES where ")+ "SCHED_CODE=\""+RDEscapeString(codename)+"\""; - q=new RDSqlQuery(sql); - delete q; + RDSqlQuery::apply(sql); sql=QString("delete from SCHED_CODES where ")+ "CODE=\""+RDEscapeString(codename)+"\""; - q=new RDSqlQuery(sql); - delete q; - item->setSelected(false); - delete item; + RDSqlQuery::apply(sql); + list_schedcodes_model->removeSchedCode(rows.first()); } -void ListSchedCodes::doubleClickedData(Q3ListViewItem *item,const QPoint &pt, - int col) +void ListSchedCodes::doubleClickedData(const QModelIndex &index) { editData(); } @@ -195,7 +190,7 @@ void ListSchedCodes::doubleClickedData(Q3ListViewItem *item,const QPoint &pt, void ListSchedCodes::closeData() { - done(0); + done(true); } @@ -203,46 +198,8 @@ void ListSchedCodes::resizeEvent(QResizeEvent *e) { list_add_button->setGeometry(size().width()-90,30,80,50); list_edit_button->setGeometry(size().width()-90,90,80,50); - list_delete_button->setGeometry(size().width()-90,210,80,50); + list_delete_button->setGeometry(size().width()-90,150,80,50); list_close_button->setGeometry(size().width()-90,size().height()-60,80,50); - list_schedCodes_view->setGeometry(10,30,size().width()-120,size().height()-40); + list_schedcodes_view-> + setGeometry(10,30,size().width()-120,size().height()-40); } - - -void ListSchedCodes::RefreshList() -{ - QString sql; - RDSqlQuery *q; - Q3ListViewItem *item; - - list_schedCodes_view->clear(); - q=new RDSqlQuery("select CODE,DESCRIPTION from SCHED_CODES"); - while (q->next()) { - item=new Q3ListViewItem(list_schedCodes_view); - WriteItem(item,q); - } - delete q; -} - - -void ListSchedCodes::RefreshItem(Q3ListViewItem *item) -{ - QString sql; - RDSqlQuery *q; - - sql=QString().sprintf("select CODE,DESCRIPTION from SCHED_CODES where CODE=\"%s\"", - (const char *)item->text(0)); - q=new RDSqlQuery(sql); - if(q->next()) { - WriteItem(item,q); - } - delete q; -} - - -void ListSchedCodes::WriteItem(Q3ListViewItem *item,RDSqlQuery *q) -{ - item->setText(0,q->value(0).toString()); - item->setText(1,q->value(1).toString()); -} - diff --git a/rdadmin/list_schedcodes.h b/rdadmin/list_schedcodes.h index 416d6e4e..5060d5b6 100644 --- a/rdadmin/list_schedcodes.h +++ b/rdadmin/list_schedcodes.h @@ -2,7 +2,7 @@ // // The scheduler codes dialog for rdadmin // -// Stefan Gabriel +// Based on original code by Stefan Gabriel // (C) Copyright 2002-2019 Fred Gleason // // This program is free software; you can redistribute it and/or modify @@ -22,12 +22,16 @@ #ifndef LIST_SCHEDCODES_H #define LIST_SCHEDCODES_H -#include -#include +#include +#include #include #include -#include +#include +#include + +#include "add_schedcodes.h" +#include "edit_schedcodes.h" class ListSchedCodes : public RDDialog { @@ -42,21 +46,22 @@ class ListSchedCodes : public RDDialog void addData(); void editData(); void deleteData(); - void doubleClickedData(Q3ListViewItem *item,const QPoint &pt,int col); + void doubleClickedData(const QModelIndex &index); void closeData(); protected: void resizeEvent(QResizeEvent *e); private: - void RefreshList(); - void RefreshItem(Q3ListViewItem *item); - void WriteItem(Q3ListViewItem *item,RDSqlQuery *q); - Q3ListView *list_schedCodes_view; + RDTableView *list_schedcodes_view; + QLabel *list_schedcodes_label; + RDSchedCodeListModel *list_schedcodes_model; QPushButton *list_add_button; QPushButton *list_edit_button; QPushButton *list_delete_button; QPushButton *list_close_button; + AddSchedCode *list_add_schedcode_dialog; + EditSchedCode *list_edit_schedcode_dialog; };