2021-01-22 Fred Gleason <fredg@paravelsystems.com>

* Refactored the 'Edit Host' dialog in rdadmin(1) to use the
	model-based API.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-01-22 14:31:30 -05:00
parent 1d40b6076c
commit d5c465d78f
6 changed files with 57 additions and 45 deletions

View File

@ -20871,3 +20871,6 @@
2021-01-22 Fred Gleason <fredg@paravelsystems.com>
* Added an 'RDIconEngine::stationIcon()' method.
* Added an icons for 'host' objects.
2021-01-22 Fred Gleason <fredg@paravelsystems.com>
* Refactored the 'Edit Host' dialog in rdadmin(1) to use the
model-based API.

View File

@ -22,9 +22,12 @@
#include "rdescape_string.h"
#include "rdstationlistmodel.h"
RDStationListModel::RDStationListModel(QObject *parent)
RDStationListModel::RDStationListModel(const QString &localhost_name,
QObject *parent)
: QAbstractTableModel(parent)
{
d_localhost_name=localhost_name;
//
// Column Attributes
//
@ -167,7 +170,7 @@ QVariant RDStationListModel::data(const QModelIndex &index,int role) const
QString RDStationListModel::stationName(const QModelIndex &row) const
{
return d_texts.at(row.row()).at(0).toString();
return d_hostnames.at(row.row());
}
@ -178,7 +181,7 @@ QModelIndex RDStationListModel::addStation(const QString &hostname)
//
int offset=d_texts.size();
for(int i=0;i<d_texts.size();i++) {
if(hostname.toLower()<d_texts.at(i).at(0).toString().toLower()) {
if(hostname.toLower()<d_hostnames.at(i).toLower()) {
offset=i;
break;
}
@ -188,7 +191,13 @@ QModelIndex RDStationListModel::addStation(const QString &hostname)
for(int i=0;i<columnCount();i++) {
list.push_back(QVariant());
}
if(hostname==d_localhost_name) {
list[0]="localhost";
}
else {
list[0]=hostname;
}
d_hostnames.insert(offset,hostname);
d_texts.insert(offset,list);
d_icons.insert(offset,list);
updateRowLine(offset);
@ -202,6 +211,7 @@ void RDStationListModel::removeStation(const QModelIndex &row)
{
beginRemoveRows(QModelIndex(),row.row(),row.row());
d_hostnames.removeAt(row.row());
d_texts.removeAt(row.row());
d_icons.removeAt(row.row());
@ -212,7 +222,7 @@ void RDStationListModel::removeStation(const QModelIndex &row)
void RDStationListModel::removeStation(const QString &hostname)
{
for(int i=0;i<d_texts.size();i++) {
if(d_texts.at(i).at(0)==hostname) {
if(d_hostnames.at(i)==hostname) {
removeStation(createIndex(i,0));
return;
}
@ -224,9 +234,7 @@ void RDStationListModel::refresh(const QModelIndex &row)
{
if(row.row()<d_texts.size()) {
QString sql=sqlFields()+
"where STATIONS.NAME=\""+
RDEscapeString(d_texts.at(row.row()).at(0).toString())+
"\"";
"where STATIONS.NAME=\""+RDEscapeString(d_hostnames.at(0))+"\"";
RDSqlQuery *q=new RDSqlQuery(sql);
if(q->first()) {
updateRow(row.row(),q);
@ -258,10 +266,12 @@ void RDStationListModel::updateModel()
QString sql=sqlFields();
sql+="order by NAME ";
beginResetModel();
d_hostnames.clear();
d_texts.clear();
d_icons.clear();
q=new RDSqlQuery(sql);
while(q->next()) {
d_hostnames.push_back(QString());
d_texts.push_back(texts);
d_icons.push_back(texts);
updateRow(d_texts.size()-1,q);
@ -275,7 +285,7 @@ void RDStationListModel::updateRowLine(int line)
{
if(line<d_texts.size()) {
QString sql=sqlFields()+
"where NAME=\""+RDEscapeString(d_texts.at(line).at(0).toString())+"\"";
"where NAME=\""+RDEscapeString(d_hostnames.at(0))+"\"";
RDSqlQuery *q=new RDSqlQuery(sql);
if(q->first()) {
updateRow(line,q);
@ -291,7 +301,13 @@ void RDStationListModel::updateRow(int row,RDSqlQuery *q)
QList<QVariant> icons;
// Hostname
d_hostnames[row]=q->value(0).toString();
if(q->value(0).toString()==d_localhost_name) {
texts.push_back("localhost");
}
else {
texts.push_back(q->value(0));
}
icons.push_back(rda->iconEngine()->stationIcon());
// Description

View File

@ -41,7 +41,7 @@ class RDStationListModel : public QAbstractTableModel
{
Q_OBJECT
public:
RDStationListModel(QObject *parent=0);
RDStationListModel(const QString &localhost_name,QObject *parent=0);
~RDStationListModel();
QPalette palette();
void setPalette(const QPalette &pal);
@ -68,9 +68,10 @@ class RDStationListModel : public QAbstractTableModel
QPalette d_palette;
QFont d_font;
QFont d_bold_font;
QStringList d_service_names;
QString d_localhost_name;
QList<QVariant> d_headers;
QList<QVariant> d_alignments;
QStringList d_hostnames;
QList<QList<QVariant> > d_texts;
QList<QList<QVariant> > d_icons;
};

View File

@ -18,7 +18,7 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <qmessagebox.h>
#include <QMessageBox>
#include <rdapplication.h>
#include <rdcatch_connect.h>
@ -48,9 +48,7 @@
EditStation::EditStation(QString sname,QWidget *parent)
: RDDialog(parent)
{
RDSqlQuery *q;
QString sql;
char temp[256];
char temp[1024];
//
// Fix the Window Size
@ -74,6 +72,12 @@ EditStation::EditStation(QString sname,QWidget *parent)
RDTextValidator *validator=new RDTextValidator(this);
QIntValidator *macro_validator=new QIntValidator(1,RD_MAX_CART_NUMBER,this);
//
// Models
//
station_username_model=new RDUserListModel(this);
station_station_model=new RDStationListModel(sname,this);
//
// Station Name
//
@ -109,7 +113,6 @@ EditStation::EditStation(QString sname,QWidget *parent)
//
station_username_box=new QComboBox(this);
station_username_box->setEditable(false);
station_username_model=new RDUserListModel(this);
station_username_model->setTypeFilter(RDUser::TypeUser);
station_username_box->setModel(station_username_model);
station_username_label=
@ -319,6 +322,7 @@ EditStation::EditStation(QString sname,QWidget *parent)
//
station_http_station_box=new QComboBox(this);
station_http_station_box->setEditable(false);
station_http_station_box->setModel(station_station_model);
station_http_station_label=
new QLabel(station_http_station_box,tr("HTTP Xport:"),this);
station_http_station_label->setFont(labelFont());
@ -329,6 +333,7 @@ EditStation::EditStation(QString sname,QWidget *parent)
//
station_cae_station_box=new QComboBox(this);
station_cae_station_box->setEditable(false);
station_cae_station_box->setModel(station_station_model);
connect(station_cae_station_box,SIGNAL(activated(const QString &)),
this,SLOT(caeStationActivatedData(const QString &)));
station_cae_station_label=
@ -342,7 +347,8 @@ EditStation::EditStation(QString sname,QWidget *parent)
station_rdlibrary_button=new QPushButton(this);
station_rdlibrary_button->setFont(buttonFont());
station_rdlibrary_button->setText(tr("RD&Library"));
connect(station_rdlibrary_button,SIGNAL(clicked()),this,SLOT(editLibraryData()));
connect(station_rdlibrary_button,SIGNAL(clicked()),
this,SLOT(editLibraryData()));
//
// RDCatch Configuration Button
@ -549,25 +555,8 @@ EditStation::EditStation(QString sname,QWidget *parent)
station_panel_enforce_label->setDisabled(true);
station_panel_enforce_box->setDisabled(true);
}
station_http_station_box->insertItem("localhost");
station_cae_station_box->insertItem("localhost");
sql=QString("select NAME from STATIONS where ")+
"NAME!=\""+RDEscapeString(sname)+"\" order by NAME";
q=new RDSqlQuery(sql);
while(q->next()) {
station_http_station_box->insertItem(q->value(0).toString());
if(q->value(0).toString()==station_station->httpStation()) {
station_http_station_box->
setCurrentItem(station_http_station_box->count()-1);
}
station_cae_station_box->insertItem(q->value(0).toString());
if(q->value(0).toString()==station_station->caeStation()) {
station_cae_station_box->
setCurrentItem(station_cae_station_box->count()-1);
}
}
delete q;
station_http_station_box->setCurrentText(station_station->httpStation());
station_cae_station_box->setCurrentText(station_station->caeStation());
for(int i=0;i<station_http_station_box->count();i++) {
if(station_http_station_box->text(i)==station_station->httpStation()) {
station_http_station_box->setCurrentItem(i);
@ -584,6 +573,7 @@ EditStation::~EditStation()
delete station_station;
delete station_cae_station;
delete station_username_model;
delete station_station_model;
}

View File

@ -21,19 +21,20 @@
#ifndef EDIT_STATION_H
#define EDIT_STATION_H
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <QComboBox>
#include <QCheckBox>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSpinBox>
#include <rddialog.h>
#include <rdcardselector.h>
#include <rdcatch_connect.h>
#include <rdripc.h>
#include <rdstation.h>
#include <rdstationlistmodel.h>
#include <rduserlistmodel.h>
class EditStation : public RDDialog
@ -134,6 +135,7 @@ class EditStation : public RDDialog
QComboBox *station_http_station_box;
QLabel *station_cae_station_label;
QComboBox *station_cae_station_box;
RDStationListModel *station_station_model;
QPushButton *station_rdlibrary_button;
QPushButton *station_rdcatch_button;
QPushButton *station_rdairplay_button;

View File

@ -83,7 +83,7 @@ ListStations::ListStations(QWidget *parent)
list_stations_view->setShowGrid(false);
list_stations_view->setSortingEnabled(false);
list_stations_view->setWordWrap(false);
list_stations_model=new RDStationListModel(this);
list_stations_model=new RDStationListModel("",this);
list_stations_model->setFont(defaultFont());
list_stations_model->setPalette(palette());
list_stations_view->setModel(list_stations_model);