2021-10-27 Fred Gleason <fredg@paravelsystems.com>

* Refactored the 'Add Clock' dialog in rdlogmanager(1) to allow
	specification of the clock code as well as name.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-10-27 15:06:39 -04:00
parent 4a98b80c28
commit 0ae01975b9
7 changed files with 154 additions and 85 deletions

View File

@ -22555,3 +22555,6 @@
that caused a 'phantom' additional entry in the event list to
be created when overwriting an existing event during a 'Save As'
operation.
2021-10-27 Fred Gleason <fredg@paravelsystems.com>
* Refactored the 'Add Clock' dialog in rdlogmanager(1) to allow
specification of the clock code as well as name.

View File

@ -18,25 +18,25 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <QMessageBox>
#include <QStringList>
#include <rdescape_string.h>
#include <rdpasswd.h>
#include <rdtextvalidator.h>
#include "add_clock.h"
AddClock::AddClock(QString *logname,QWidget *parent)
AddClock::AddClock(QWidget *parent)
: RDDialog(parent)
{
setModal(true);
clock_name=logname;
setWindowTitle("RDLogManager - "+tr("Add Clock"));
//
// Fix the Window Size
//
setMinimumSize(sizeHint());
setMaximumSize(sizeHint());
setMaximumHeight(sizeHint().height());
//
// Create Validators
@ -77,39 +77,44 @@ AddClock::AddClock(QString *logname,QWidget *parent)
// Clock Name
//
clock_name_edit=new QLineEdit(this);
clock_name_edit->setGeometry(145,11,sizeHint().width()-155,19);
clock_name_edit->setMaxLength(58); // MySQL limitation!
clock_name_edit->setValidator(validator);
QLabel *clock_name_label=new QLabel(tr("New Clock Name:"),this);
clock_name_label->setGeometry(10,11,130,19);
connect(clock_name_edit,SIGNAL(textChanged(const QString &)),
this,SLOT(clockNameChangedData(const QString &)));
connect(clock_name_edit,SIGNAL(textChanged(const QString &)),
this,SLOT(textChangedData(const QString &)));
clock_name_label=new QLabel(tr("New Clock Name:"),this);
clock_name_label->setFont(labelFont());
clock_name_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
//
// Clock Code
//
clock_code_edit=new QLineEdit(this);
clock_code_edit->setMaxLength(3); // MySQL limitation!
clock_code_edit->setValidator(validator);
connect(clock_code_edit,SIGNAL(textChanged(const QString &)),
this,SLOT(textChangedData(const QString &)));
clock_code_label=new QLabel(tr("New Clock Code:"),this);
clock_code_label->setFont(labelFont());
clock_code_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
//
// Ok Button
//
QPushButton *ok_button=new QPushButton(this);
ok_button->setGeometry(sizeHint().width()-180,sizeHint().height()-60,80,50);
ok_button->setDefault(true);
ok_button->setFont(buttonFont());
ok_button->setText(tr("OK"));
connect(ok_button,SIGNAL(clicked()),this,SLOT(okData()));
clock_ok_button=new QPushButton(this);
clock_ok_button->setDefault(true);
clock_ok_button->setFont(buttonFont());
clock_ok_button->setText(tr("OK"));
connect(clock_ok_button,SIGNAL(clicked()),this,SLOT(okData()));
//
// Cancel Button
//
QPushButton *cancel_button=new QPushButton(this);
cancel_button->setGeometry(sizeHint().width()-90,sizeHint().height()-60,
80,50);
cancel_button->setFont(buttonFont());
cancel_button->setText(tr("Cancel"));
connect(cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
//
// Populate Data
//
clock_name_edit->setText(*clock_name);
clock_name_edit->selectAll();
clock_cancel_button=new QPushButton(this);
clock_cancel_button->setFont(buttonFont());
clock_cancel_button->setText(tr("Cancel"));
connect(clock_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
}
@ -121,7 +126,7 @@ AddClock::~AddClock()
QSize AddClock::sizeHint() const
{
return QSize(400,105);
return QSize(400,127);
}
@ -131,16 +136,86 @@ QSizePolicy AddClock::sizePolicy() const
}
int AddClock::exec(QString *clk_name,QString *clk_code)
{
clock_name=clk_name;
clock_code=clk_code;
clock_name_edit->setText(*clock_name);
clock_name_edit->selectAll();
clock_code_edit->setText(*clock_code);
textChangedData("");
return QDialog::exec();
}
void AddClock::clockNameChangedData(const QString &str)
{
QStringList f0=str.split(" ",QString::SkipEmptyParts);
QString code;
while(f0.size()>3) {
f0.removeLast();
}
for(int i=0;i<f0.size();i++) {
code+=f0.at(i).left(1).toUpper();
}
clock_code_edit->setText(code);
}
void AddClock::textChangedData(const QString &str)
{
clock_ok_button->setDisabled(clock_name_edit->text().isEmpty()&&
clock_code_edit->text().isEmpty());
}
void AddClock::okData()
{
QString sql;
RDSqlQuery *q=NULL;
//
// Sanity Checks
//
sql=QString("select ")+
"`NAME` "+ // 00
"from `CLOCKS` where "+
"`NAME`='"+RDEscapeString(clock_name_edit->text())+"'";
q=new RDSqlQuery(sql);
if(q->first()) {
QMessageBox::information(this,"RDLogManager "+tr("Name in use"),
tr("A clock with that name already exists!"));
delete q;
return;
}
delete q;
sql=QString("select ")+
"`SHORT_NAME` "+ // 00
"from `CLOCKS` where "+
"`SHORT_NAME`='"+RDEscapeString(clock_code_edit->text())+"'";
q=new RDSqlQuery(sql);
if(q->first()) {
QMessageBox::information(this,"RDLogManager "+tr("Code in use"),
tr("That code is already in use!"));
delete q;
return;
}
delete q;
*clock_name=clock_name_edit->text();
done(0);
*clock_code=clock_code_edit->text();
done(true);
}
void AddClock::cancelData()
{
done(-1);
done(false);
}
@ -148,3 +223,16 @@ void AddClock::closeEvent(QCloseEvent *e)
{
cancelData();
}
void AddClock::resizeEvent(QResizeEvent *e)
{
clock_name_edit->setGeometry(145,11,size().width()-155,19);
clock_name_label->setGeometry(10,11,130,19);
clock_code_edit->setGeometry(145,33,50,19);
clock_code_label->setGeometry(10,33,130,19);
clock_ok_button->setGeometry(size().width()-180,size().height()-60,80,50);
clock_cancel_button->setGeometry(size().width()-90,size().height()-60,80,50);
}

View File

@ -21,7 +21,9 @@
#ifndef ADD_CLOCK_H
#define ADD_CLOCK_H
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <rdclock.h>
#include <rddialog.h>
@ -30,23 +32,34 @@ class AddClock : public RDDialog
{
Q_OBJECT
public:
AddClock(QString *logname,QWidget *parent=0);
AddClock(QWidget *parent=0);
~AddClock();
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
public slots:
int exec(QString *clk_name,QString *clk_code);
private slots:
void clockNameChangedData(const QString &str);
void textChangedData(const QString &str);
void okData();
void cancelData();
protected:
void closeEvent(QCloseEvent *e);
void resizeEvent(QResizeEvent *e);
private:
QLabel *clock_name_label;
QLineEdit *clock_name_edit;
QLabel *clock_code_label;
QLineEdit *clock_code_edit;
QString *clock_name;
QString *clock_code;
QPushButton *clock_ok_button;
QPushButton *clock_cancel_button;
};
#endif
#endif // ADD_CLOCK_H

View File

@ -35,7 +35,7 @@
#include "list_clocks.h"
EditClock::EditClock(QString clockname,bool new_clock,
std::vector<QString> *new_clocks,QWidget *parent)
QStringList *new_clocks,QWidget *parent)
: RDDialog(parent)
{
QString str;
@ -423,8 +423,7 @@ void EditClock::saveData()
void EditClock::saveAsData()
{
QString clockname=edit_name;
QString sql;
RDSqlQuery *q;
QString code=edit_shortname_edit->text();
if(!ValidateCode()) {
return;
@ -443,41 +442,15 @@ void EditClock::saveAsData()
break;
}
}
if(edit_shortname_edit->text().isEmpty()) {
QMessageBox::warning(this,tr("Missing Clock Code"),
tr("You must specify a clock code!"));
return;
}
sql=
QString("select `SHORT_NAME` from `CLOCKS` where ")+
"`SHORT_NAME`='"+RDEscapeString(edit_shortname_edit->text())+"'";
q=new RDSqlQuery(sql);
if(q->first()) {
QMessageBox::warning(this,tr("Code Exists"),
tr("The clock code is already in use!"));
delete q;
return;
}
delete q;
AddClock *addclock=new AddClock(&clockname,this);
if(addclock->exec()<0) {
AddClock *addclock=new AddClock(this);
if(!addclock->exec(&clockname,&code)) {
delete addclock;
return;
}
delete addclock;
edit_name=clockname;
sql=QString("select `NAME` from `CLOCKS` where ")+
"`NAME`='"+RDEscapeString(clockname)+"'";
q=new RDSqlQuery(sql);
if(q->first()) {
if(QMessageBox::question(this,tr("Clock Exists"),
tr("Clock already exists! Overwrite?"),QMessageBox::Yes,QMessageBox::No)!=QMessageBox::Yes) {
delete q;
return;
}
}
delete q;
edit_shortname_edit->setText(code);
edit_clocks_model->setClockName(clockname);
Save();

View File

@ -21,6 +21,7 @@
#ifndef EDIT_CLOCK_H
#define EDIT_CLOCK_H
#include <QStringList>
#include <QTextEdit>
#include <rdclockmodel.h>
@ -40,7 +41,7 @@ class EditClock : public RDDialog
{
Q_OBJECT
public:
EditClock(QString clockname,bool new_clock,std::vector<QString> *new_clocks,
EditClock(QString clockname,bool new_clock,QStringList *new_clocks,
QWidget *parent=0);
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
@ -88,7 +89,7 @@ class EditClock : public RDDialog
bool edit_modified;
QString edit_name;
bool edit_new_clock;
std::vector<QString> *edit_new_clocks;
QStringList *edit_new_clocks;
RDSchedRulesList* sched_rules_list;
QTextEdit *edit_remarks_edit;
};

View File

@ -213,7 +213,7 @@ void EditGrid::aboutToShowData()
void EditGrid::editClockData()
{
std::vector<QString> new_clocks;
QStringList new_clocks;
int dayofweek=edit_rightclick_id/24+1;
int hour=edit_rightclick_id-24*(dayofweek-1);

View File

@ -188,31 +188,22 @@ QSizePolicy ListClocks::sizePolicy() const
void ListClocks::addData()
{
QString clockname;
QString clockname;
QString code;
QString sql;
RDSqlQuery *q;
RDSqlQuery *q1;
std::vector<QString> new_clocks;
QStringList new_clocks;
AddClock *add_dialog=new AddClock(&clockname,this);
if(add_dialog->exec()<0) {
AddClock *add_dialog=new AddClock(this);
if(!add_dialog->exec(&clockname,&code)) {
delete add_dialog;
return;
}
delete add_dialog;
sql=QString("select `NAME` from `CLOCKS` where ")+
"NAME='"+RDEscapeString(clockname)+"'";
q=new RDSqlQuery(sql);
if(q->first()) {
QMessageBox::
information(this,tr("Clock Exists"),
tr("An clock with that name already exists!"));
delete q;
return;
}
delete q;
sql=QString("insert into `CLOCKS` set ")+
"`NAME`='"+RDEscapeString(clockname)+"',"+
"`SHORT_NAME`='"+RDEscapeString(code)+"',"+
"`ARTISTSEP`=15";
RDSqlQuery::apply(sql);
@ -285,7 +276,7 @@ void ListClocks::addData()
void ListClocks::editData()
{
std::vector<QString> new_clocks;
QStringList new_clocks;
QModelIndexList rows=edit_clocks_view->selectionModel()->selectedRows();
if(rows.size()!=1) {
@ -300,7 +291,7 @@ void ListClocks::editData()
}
delete clock_dialog;
edit_clocks_model->refresh(rows.first());
for(unsigned i=0;i<new_clocks.size();i++) {
for(int i=0;i<new_clocks.size();i++) {
edit_clocks_model->addClock(new_clocks.at(i));
}
}