From 8496b72f13bc11724b8471c741ca3c5e233859cf Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 20 Jul 2021 20:17:06 -0400 Subject: [PATCH] 2021-07-20 Fred Gleason * Refactored the 'Edit Switcher Event' dialog in rdcatch(1) to improve modularity. Signed-off-by: Fred Gleason --- ChangeLog | 3 + rdcatch/edit_switchevent.cpp | 289 +++++++++++------------------------ rdcatch/edit_switchevent.h | 30 ++-- rdcatch/rdcatch_fr.ts | 44 ------ 4 files changed, 107 insertions(+), 259 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7a56f420..ebc15464 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22079,3 +22079,6 @@ 2021-07-20 Fred Gleason * Fixed a regression in rdadmin(1) that caused the username and description fields to be blank on the main window. +2021-07-20 Fred Gleason + * Refactored the 'Edit Switcher Event' dialog in rdcatch(1) to improve + modularity. diff --git a/rdcatch/edit_switchevent.cpp b/rdcatch/edit_switchevent.cpp index 7674f658..632e00d6 100644 --- a/rdcatch/edit_switchevent.cpp +++ b/rdcatch/edit_switchevent.cpp @@ -30,9 +30,6 @@ EditSwitchEvent::EditSwitchEvent(int id,std::vector *adds,QWidget *parent) : RDDialog(parent) { - QString sql; - RDSqlQuery *q=NULL; - QString temp; edit_matrix=NULL; edit_added_events=adds; @@ -57,63 +54,28 @@ EditSwitchEvent::EditSwitchEvent(int id,std::vector *adds,QWidget *parent) edit_recording=new RDRecording(id); // - // Active Button + // Event Widget // - edit_active_button=new QCheckBox(this); - edit_active_button->setGeometry(10,11,20,20); - QLabel *label=new QLabel(tr("Event Active"),this); - label->setGeometry(30,11,125,20); - label->setFont(labelFont()); - label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); - - // - // Station - // - edit_station_box=new RDComboBox(this); - // - // FIXME: Make this work with a model - // - // edit_station_model=new RDStationListModel(false,"",this); - // edit_station_box->setModel(edit_station_model); - edit_station_box->setGeometry(200,10,140,23); - label=new QLabel(tr("Location:"),this); - label->setGeometry(125,10,70,23); - label->setFont(labelFont()); - label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); - connect(edit_station_box,SIGNAL(activated(const QString &)), + edit_event_widget=new EventWidget(EventWidget::OtherEvent,this); + connect(edit_event_widget,SIGNAL(locationChanged(const QString &)), this,SLOT(activateStationData(const QString &))); - - // - // Start Time - // - edit_starttime_edit=new QTimeEdit(this); - edit_starttime_edit->setGeometry(sizeHint().width()-90,12,80,20); - edit_starttime_edit->setDisplayFormat("hh:mm:ss"); - label=new QLabel(tr("Start Time:"),this); - label->setGeometry(sizeHint().width()-175,12,80,20); - label->setFont(labelFont()); - label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); - + // // Description // edit_description_edit=new QLineEdit(this); - edit_description_edit->setGeometry(120,43,sizeHint().width()-130,20); edit_description_edit->setValidator(validator); - label=new QLabel(tr("Description:"),this); - label->setGeometry(10,43,105,20); - label->setFont(labelFont()); - label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + edit_description_label=new QLabel(tr("Description:"),this); + edit_description_label->setFont(labelFont()); + edit_description_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); // // Switch Matrix // edit_matrix_box=new RDComboBox(this); - edit_matrix_box->setGeometry(120,70,sizeHint().width()-130,20); - label=new QLabel(tr("Switch Matrix:"),this); - label->setGeometry(10,70,105,20); - label->setFont(labelFont()); - label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + edit_matrix_label=new QLabel(tr("Switch Matrix:"),this); + edit_matrix_label->setFont(labelFont()); + edit_matrix_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); connect(edit_matrix_box,SIGNAL(activated(const QString &)), this,SLOT(activateMatrixData(const QString &))); @@ -121,13 +83,10 @@ EditSwitchEvent::EditSwitchEvent(int id,std::vector *adds,QWidget *parent) // Switch Input // edit_input_box=new RDComboBox(this); - edit_input_box->setGeometry(120,100,sizeHint().width()-130,20); - label=new QLabel(tr("Switch Input:"),this); - label->setGeometry(10,100,105,20); - label->setFont(labelFont()); - label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + edit_input_label=new QLabel(tr("Switch Input:"),this); + edit_input_label->setFont(labelFont()); + edit_input_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); edit_input_spin=new QSpinBox(this); - edit_input_spin->setGeometry(140,125,50,20); connect(edit_input_box,SIGNAL(activated(const QString &)), this,SLOT(activateInputData(const QString &))); @@ -135,158 +94,62 @@ EditSwitchEvent::EditSwitchEvent(int id,std::vector *adds,QWidget *parent) // Switch Output // edit_output_box=new RDComboBox(this); - edit_output_box->setGeometry(120,155,sizeHint().width()-130,20); - label=new QLabel(tr("Switch Output:"),this); - label->setGeometry(10,155,105,20); - label->setFont(labelFont()); - label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + edit_output_label=new QLabel(tr("Switch Output:"),this); + edit_output_label->setFont(labelFont()); + edit_output_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter); edit_output_spin=new QSpinBox(this); - edit_output_spin->setGeometry(140,180,50,20); connect(edit_output_box,SIGNAL(activated(const QString &)), this,SLOT(activateOutputData(const QString &))); // - // Button Label + // DOW Selector // - QGroupBox *groupbox=new QGroupBox(tr("Active Days"),this); - groupbox->setFont(labelFont()); - groupbox->setGeometry(10,213,sizeHint().width()-20,62); - - // - // Monday Button - // - edit_mon_button=new QCheckBox(this); - edit_mon_button->setGeometry(20,228,20,20); - label=new QLabel(tr("Monday"),this); - label->setGeometry(40,228,115,20); - label->setFont(subLabelFont()); - label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); - - // - // Tuesday Button - // - edit_tue_button=new QCheckBox(this); - edit_tue_button->setGeometry(115,228,20,20); - label=new QLabel(tr("Tuesday"),this); - label->setGeometry(135,228,115,20); - label->setFont(subLabelFont()); - label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); - - // - // Wednesday Button - // - edit_wed_button=new QCheckBox(this); - edit_wed_button->setGeometry(215,228,20,20); - label=new QLabel(tr("Wednesday"),this); - label->setGeometry(235,228,115,20); - label->setFont(subLabelFont()); - label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); - - // - // Thursday Button - // - edit_thu_button=new QCheckBox(this); - edit_thu_button->setGeometry(335,228,20,20); - label=new QLabel(tr("Thursday"),this); - label->setGeometry(355,228,115,20); - label->setFont(subLabelFont()); - label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); - - // - // Friday Button - // - edit_fri_button=new QCheckBox(this); - edit_fri_button->setGeometry(440,228,20,20); - label=new QLabel(tr("Friday"),this); - label->setGeometry(460,228,40,20); - label->setFont(subLabelFont()); - label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); - - // - // Saturday Button - // - edit_sat_button=new QCheckBox(this); - edit_sat_button->setGeometry(130,253,20,20); - label=new QLabel(tr("Saturday"),this); - label->setGeometry(150,253,60,20); - label->setFont(subLabelFont()); - label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); - - // - // Sunday Button - // - edit_sun_button=new QCheckBox(this); - edit_sun_button->setGeometry(300,253,20,20); - label=new QLabel(tr("Sunday"),this); - label->setGeometry(320,253,60,20); - label->setFont(subLabelFont()); - label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); + edit_dow_selector=new DowSelector(this); // // OneShot Button // edit_oneshot_box=new QCheckBox(this); - edit_oneshot_box->setGeometry(20,290,15,15); - label=new QLabel(tr("Make OneShot"),this); - label->setGeometry(40,288,115,20); - label->setFont(labelFont()); - label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); + edit_oneshot_label=new QLabel(tr("Make OneShot"),this); + edit_oneshot_label->setFont(labelFont()); + edit_oneshot_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); // // Save As Button // - QPushButton *button=new QPushButton(this); - button->setGeometry(sizeHint().width()-300,sizeHint().height()-60,80,50); - button->setFont(buttonFont()); - button->setText(tr("Save As\nNew")); - connect(button,SIGNAL(clicked()),this,SLOT(saveasData())); + edit_saveas_button=new QPushButton(this); + edit_saveas_button->setFont(buttonFont()); + edit_saveas_button->setText(tr("Save As\nNew")); + connect(edit_saveas_button,SIGNAL(clicked()),this,SLOT(saveasData())); if(adds==NULL) { - button->hide(); + edit_saveas_button->hide(); } // // Ok Button // - button=new QPushButton(this); - button->setGeometry(sizeHint().width()-180,sizeHint().height()-60,80,50); - button->setDefault(true); - button->setFont(buttonFont()); - button->setText(tr("OK")); - connect(button,SIGNAL(clicked()),this,SLOT(okData())); + edit_ok_button=new QPushButton(this); + edit_ok_button->setDefault(true); + edit_ok_button->setFont(buttonFont()); + edit_ok_button->setText(tr("OK")); + connect(edit_ok_button,SIGNAL(clicked()),this,SLOT(okData())); // // Cancel Button // - button=new QPushButton(this); - button->setGeometry(sizeHint().width()-90,sizeHint().height()-60,80,50); - button->setFont(buttonFont()); - button->setText(tr("Cancel")); - connect(button,SIGNAL(clicked()),this,SLOT(cancelData())); + edit_cancel_button=new QPushButton(this); + edit_cancel_button->setFont(buttonFont()); + edit_cancel_button->setText(tr("Cancel")); + connect(edit_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData())); // // Populate Data // - edit_active_button->setChecked(edit_recording->isActive()); - q=new RDSqlQuery("select `NAME` from `STATIONS` where `NAME`!='DEFAULT'"); - while(q->next()) { - edit_station_box->insertItem(q->value(0).toString()); - if(edit_recording->station()==q->value(0).toString()) { - edit_station_box->setCurrentIndex(edit_station_box->count()-1); - } - } - delete q; - // edit_station_box->setCurrentText(edit_recording->station()); - edit_starttime_edit->setTime(edit_recording->startTime()); + edit_event_widget->fromRecording(edit_recording->id()); edit_description_edit->setText(edit_recording->description()); - edit_mon_button->setChecked(edit_recording->mon()); - edit_tue_button->setChecked(edit_recording->tue()); - edit_wed_button->setChecked(edit_recording->wed()); - edit_thu_button->setChecked(edit_recording->thu()); - edit_fri_button->setChecked(edit_recording->fri()); - edit_sat_button->setChecked(edit_recording->sat()); - edit_sun_button->setChecked(edit_recording->sun()); + edit_dow_selector->fromRecording(edit_recording->id()); edit_oneshot_box->setChecked(edit_recording->oneShot()); - activateStationData(edit_station_box->currentText()); + activateStationData(edit_event_widget->stationName()); // // Input/Output Spin Box Connections @@ -301,7 +164,8 @@ EditSwitchEvent::EditSwitchEvent(int id,std::vector *adds,QWidget *parent) EditSwitchEvent::~EditSwitchEvent() { - delete edit_station_box; + delete edit_event_widget; + delete edit_dow_selector; if(edit_deck!=NULL) { delete edit_deck; } @@ -352,12 +216,12 @@ void EditSwitchEvent::activateMatrixData(const QString &str) if(edit_matrix!=NULL) { delete edit_matrix; } - edit_matrix=new RDMatrix(edit_station_box->currentText(),GetMatrix()); + edit_matrix=new RDMatrix(edit_event_widget->stationName(),GetMatrix()); QString sql=QString("select ")+ "`NAME`," "`NUMBER` "+ "from `INPUTS` where "+ - "(`STATION_NAME`='"+RDEscapeString(edit_station_box->currentText())+"')&&"+ + "(`STATION_NAME`='"+RDEscapeString(edit_event_widget->stationName())+"')&&"+ QString().sprintf("(`MATRIX`=%d) ",GetMatrix())+ "order by `NAME`"; edit_input_box->clear(); @@ -385,7 +249,7 @@ void EditSwitchEvent::activateMatrixData(const QString &str) "`NAME`,"+ "`NUMBER` "+ "from `OUTPUTS` where "+ - "(`STATION_NAME`='"+RDEscapeString(edit_station_box->currentText())+"')&&"+ + "(`STATION_NAME`='"+RDEscapeString(edit_event_widget->stationName())+"')&&"+ QString().sprintf("(`MATRIX`=%d) ",GetMatrix())+ "order by `NAME`"; edit_output_box->clear(); @@ -473,6 +337,37 @@ void EditSwitchEvent::cancelData() } +void EditSwitchEvent::resizeEvent(QResizeEvent *e) +{ + edit_event_widget->setGeometry(10,11,edit_event_widget->sizeHint().width(), + edit_event_widget->sizeHint().height()); + + edit_description_edit->setGeometry(120,43,size().width()-130,20); + edit_description_label->setGeometry(10,43,105,20); + + edit_matrix_box->setGeometry(120,70,size().width()-130,20); + edit_matrix_label->setGeometry(10,70,105,20); + + edit_input_box->setGeometry(120,100,size().width()-130,20); + edit_input_label->setGeometry(10,100,105,20); + edit_input_spin->setGeometry(140,125,50,20); + + edit_output_box->setGeometry(120,155,size().width()-130,20); + edit_output_label->setGeometry(10,155,105,20); + edit_output_spin->setGeometry(140,180,50,20); + + edit_dow_selector->setGeometry(10,213,edit_dow_selector->sizeHint().width(), + edit_dow_selector->sizeHint().height()); + + edit_oneshot_box->setGeometry(20,290,15,15); + edit_oneshot_label->setGeometry(40,288,115,20); + + edit_saveas_button->setGeometry(size().width()-300,size().height()-60,80,50); + edit_ok_button->setGeometry(size().width()-180,size().height()-60,80,50); + edit_cancel_button->setGeometry(size().width()-90,size().height()-60,80,50); +} + + void EditSwitchEvent::keyPressEvent(QKeyEvent *e) { switch(e->key()) { @@ -500,21 +395,13 @@ void EditSwitchEvent::Save() int source=GetSource(); int dest=GetDestination(); - edit_recording->setIsActive(edit_active_button->isChecked()); - edit_recording->setStation(edit_station_box->currentText()); + edit_event_widget->toRecording(edit_recording->id()); edit_recording->setType(RDRecording::SwitchEvent); - edit_recording->setStartTime(edit_starttime_edit->time()); edit_recording->setDescription(edit_description_edit->text()); edit_recording->setChannel(matrix); edit_recording->setSwitchSource(source); edit_recording->setSwitchDestination(dest); - edit_recording->setMon(edit_mon_button->isChecked()); - edit_recording->setTue(edit_tue_button->isChecked()); - edit_recording->setWed(edit_wed_button->isChecked()); - edit_recording->setThu(edit_thu_button->isChecked()); - edit_recording->setFri(edit_fri_button->isChecked()); - edit_recording->setSat(edit_sat_button->isChecked()); - edit_recording->setSun(edit_sun_button->isChecked()); + edit_dow_selector->toRecording(edit_recording->id()); edit_recording->setOneShot(edit_oneshot_box->isChecked()); } @@ -526,7 +413,7 @@ int EditSwitchEvent::GetMatrix() QString sql=QString("select ")+ "`MATRIX` "+ "from `MATRICES` where "+ - "(`STATION_NAME`='"+RDEscapeString(edit_station_box->currentText())+"')&&" + "(`STATION_NAME`='"+RDEscapeString(edit_event_widget->stationName())+"')&&" "(`NAME`='"+RDEscapeString(edit_matrix_box->currentText())+"')&&"+ "(`INPUTS`>0)&&"+ "(`OUTPUTS`>0)"; @@ -546,7 +433,7 @@ int EditSwitchEvent::GetSource() QString sql=QString("select ")+ "`NUMBER` "+ "from `INPUTS` where "+ - "(`STATION_NAME`='"+RDEscapeString(edit_station_box->currentText())+"')&&"+ + "(`STATION_NAME`='"+RDEscapeString(edit_event_widget->stationName())+"')&&"+ QString().sprintf("(`MATRIX`=%d)&&",GetMatrix())+ "(`NAME`='"+RDEscapeString(edit_input_box->currentText())+"')"; RDSqlQuery *q=new RDSqlQuery(sql); @@ -565,7 +452,7 @@ int EditSwitchEvent::GetDestination() QString sql=QString("select ")+ "`NUMBER` "+ "from `OUTPUTS` where "+ - "(`STATION_NAME`='"+RDEscapeString(edit_station_box->currentText())+"')&&"+ + "(`STATION_NAME`='"+RDEscapeString(edit_event_widget->stationName())+"')&&"+ QString().sprintf("(`MATRIX`=%d)&&",GetMatrix())+ "(`NAME`='"+RDEscapeString(edit_output_box->currentText())+"')"; RDSqlQuery *q=new RDSqlQuery(sql); @@ -582,32 +469,32 @@ bool EditSwitchEvent::CheckEvent(bool include_myself) QString sql=QString("select ")+ "`ID` "+ "from `RECORDINGS` where "+ - "(`STATION_NAME`='"+RDEscapeString(edit_station_box->currentText())+"')&&"+ + "(`STATION_NAME`='"+RDEscapeString(edit_event_widget->stationName())+"')&&"+ QString().sprintf("(`TYPE`=%d)&&",RDRecording::SwitchEvent)+ "(`START_TIME`='"+ - RDEscapeString(edit_starttime_edit->time().toString("hh:mm:ss"))+"')&&"+ + RDEscapeString(edit_event_widget->startTime().toString("hh:mm:ss"))+"')&&"+ QString().sprintf("(`CHANNEL`=%d)&&",GetMatrix())+ QString().sprintf("(`SWITCH_INPUT`=%d)&&",GetSource())+ QString().sprintf("(`SWITCH_OUTPUT`=%d)",GetDestination()); - if(edit_sun_button->isChecked()) { + if(edit_dow_selector->dayOfWeekEnabled(7)) { sql+="&&(`SUN`='Y')"; } - if(edit_mon_button->isChecked()) { + if(edit_dow_selector->dayOfWeekEnabled(1)) { sql+="&&(`MON`='Y')"; } - if(edit_tue_button->isChecked()) { + if(edit_dow_selector->dayOfWeekEnabled(2)) { sql+="&&(`TUE`='Y')"; } - if(edit_wed_button->isChecked()) { + if(edit_dow_selector->dayOfWeekEnabled(3)) { sql+="&&(`WED`='Y')"; } - if(edit_thu_button->isChecked()) { + if(edit_dow_selector->dayOfWeekEnabled(4)) { sql+="&&(`THU`='Y')"; } - if(edit_fri_button->isChecked()) { + if(edit_dow_selector->dayOfWeekEnabled(5)) { sql+="&&(`FRI`='Y')"; } - if(edit_sat_button->isChecked()) { + if(edit_dow_selector->dayOfWeekEnabled(6)) { sql+="&&(`SAT`='Y')"; } if(!include_myself) { diff --git a/rdcatch/edit_switchevent.h b/rdcatch/edit_switchevent.h index b7d95779..8e868d92 100644 --- a/rdcatch/edit_switchevent.h +++ b/rdcatch/edit_switchevent.h @@ -32,6 +32,9 @@ #include #include +#include "dowselector.h" +#include "eventwidget.h" + class EditSwitchEvent : public RDDialog { Q_OBJECT @@ -53,7 +56,8 @@ class EditSwitchEvent : public RDDialog void cancelData(); protected: - void keyPressEvent(QKeyEvent *); + void resizeEvent(QResizeEvent *e); + void keyPressEvent(QKeyEvent *e); void closeEvent(QCloseEvent *e); private: @@ -65,28 +69,26 @@ class EditSwitchEvent : public RDDialog RDMatrix *edit_matrix; RDDeck *edit_deck; RDRecording *edit_recording; - QCheckBox *edit_active_button; - RDComboBox *edit_station_box; - RDStationListModel *edit_station_model; - QTimeEdit *edit_starttime_edit; + QLabel *edit_description_label; QLineEdit *edit_description_edit; + QLabel *edit_matrix_label; RDComboBox *edit_matrix_box; + QLabel *edit_input_label; RDComboBox *edit_input_box; QSpinBox *edit_input_spin; + QLabel *edit_output_label; RDComboBox *edit_output_box; QSpinBox *edit_output_spin; - QCheckBox *edit_sun_button; - QCheckBox *edit_mon_button; - QCheckBox *edit_tue_button; - QCheckBox *edit_wed_button; - QCheckBox *edit_thu_button; - QCheckBox *edit_fri_button; - QCheckBox *edit_sat_button; QString *edit_filter; QCheckBox *edit_oneshot_box; + QLabel *edit_oneshot_label; + QPushButton *edit_saveas_button; + QPushButton *edit_ok_button; + QPushButton *edit_cancel_button; + EventWidget *edit_event_widget; + DowSelector *edit_dow_selector; std::vector*edit_added_events; }; -#endif - +#endif // EDIT_SWITCHEVENT_H diff --git a/rdcatch/rdcatch_fr.ts b/rdcatch/rdcatch_fr.ts index 473ea76b..564e1a24 100644 --- a/rdcatch/rdcatch_fr.ts +++ b/rdcatch/rdcatch_fr.ts @@ -583,18 +583,6 @@ New Edit Switcher Event - - Event Active - - - - Location: - - - - Start Time: - - Description: @@ -611,38 +599,6 @@ New Switch Output: - - Active Days - - - - Monday - - - - Tuesday - - - - Wednesday - - - - Thursday - - - - Friday - - - - Saturday - - - - Sunday - - Make OneShot