mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-10-12 09:33:37 +02:00
2021-01-31 Fred Gleason <fredg@paravelsystems.com>
* Refactored the 'SAS Switches' dialog in rdadmin(1) to use the model-based API. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
@@ -1077,7 +1077,7 @@ void EditMatrix::livewireGpioButtonData()
|
||||
|
||||
void EditMatrix::vguestRelaysButtonData()
|
||||
{
|
||||
AddVguest(RDMatrix::VguestTypeRelay);
|
||||
AddResources(RDMatrix::VguestTypeRelay);
|
||||
ListVguestResources *dialog=
|
||||
new ListVguestResources(edit_matrix,RDMatrix::VguestTypeRelay,
|
||||
edit_gpos_box->value(),this);
|
||||
@@ -1088,7 +1088,7 @@ void EditMatrix::vguestRelaysButtonData()
|
||||
|
||||
void EditMatrix::vguestDisplaysButtonData()
|
||||
{
|
||||
AddVguest(RDMatrix::VguestTypeDisplay);
|
||||
AddResources(RDMatrix::VguestTypeDisplay);
|
||||
ListVguestResources *dialog=
|
||||
new ListVguestResources(edit_matrix,RDMatrix::VguestTypeDisplay,
|
||||
edit_displays_box->value(),this);
|
||||
@@ -1164,16 +1164,29 @@ void EditMatrix::stopCart2Data()
|
||||
|
||||
void EditMatrix::okData()
|
||||
{
|
||||
if((!ConfirmPruneEndpoints(RDMatrix::Input))||
|
||||
(!ConfirmPruneEndpoints(RDMatrix::Output))||
|
||||
(!ConfirmPruneVguest(RDMatrix::VguestTypeRelay))||
|
||||
(!ConfirmPruneVguest(RDMatrix::VguestTypeDisplay))) {
|
||||
return;
|
||||
if(edit_matrix->type()==RDMatrix::LogitekVguest) {
|
||||
if((!ConfirmPruneEndpoints(RDMatrix::Input))||
|
||||
(!ConfirmPruneEndpoints(RDMatrix::Output))||
|
||||
(!ConfirmPruneResources(RDMatrix::VguestTypeRelay))||
|
||||
(!ConfirmPruneResources(RDMatrix::VguestTypeDisplay))) {
|
||||
return;
|
||||
}
|
||||
PruneEndpoints(RDMatrix::Input);
|
||||
PruneEndpoints(RDMatrix::Output);
|
||||
PruneResources(RDMatrix::VguestTypeRelay);
|
||||
PruneResources(RDMatrix::VguestTypeDisplay);
|
||||
}
|
||||
PruneEndpoints(RDMatrix::Input);
|
||||
PruneEndpoints(RDMatrix::Output);
|
||||
PruneVguest(RDMatrix::VguestTypeRelay);
|
||||
PruneVguest(RDMatrix::VguestTypeDisplay);
|
||||
if(edit_matrix->type()==RDMatrix::SasUsi) {
|
||||
if((!ConfirmPruneEndpoints(RDMatrix::Input))||
|
||||
(!ConfirmPruneEndpoints(RDMatrix::Output))||
|
||||
(!ConfirmPruneResources(RDMatrix::VguestTypeNone))) {
|
||||
return;
|
||||
}
|
||||
PruneEndpoints(RDMatrix::Input);
|
||||
PruneEndpoints(RDMatrix::Output);
|
||||
PruneResources(RDMatrix::VguestTypeNone);
|
||||
}
|
||||
|
||||
if(!WriteMatrix()) {
|
||||
return;
|
||||
}
|
||||
@@ -1311,8 +1324,8 @@ bool EditMatrix::WriteMatrix()
|
||||
//
|
||||
AddEndpoints(RDMatrix::Input);
|
||||
AddEndpoints(RDMatrix::Output);
|
||||
AddVguest(RDMatrix::VguestTypeRelay);
|
||||
AddVguest(RDMatrix::VguestTypeDisplay);
|
||||
AddResources(RDMatrix::VguestTypeRelay);
|
||||
AddResources(RDMatrix::VguestTypeDisplay);
|
||||
|
||||
//
|
||||
// Update GPIO Tables
|
||||
@@ -1496,7 +1509,7 @@ bool EditMatrix::ConfirmPruneEndpoints(RDMatrix::Endpoint ep)
|
||||
}
|
||||
|
||||
|
||||
void EditMatrix::AddVguest(RDMatrix::VguestType type) const
|
||||
void EditMatrix::AddResources(RDMatrix::VguestType type) const
|
||||
{
|
||||
//
|
||||
// Ensure that we have data entries for at least the number of
|
||||
@@ -1515,16 +1528,20 @@ void EditMatrix::AddVguest(RDMatrix::VguestType type) const
|
||||
"ID "+ // 00
|
||||
"from VGUEST_RESOURCES where "+
|
||||
"STATION_NAME=\""+RDEscapeString(edit_matrix->station())+"\" && "+
|
||||
QString().sprintf("MATRIX_NUM=%d && ",edit_matrix->matrix())+
|
||||
QString().sprintf("VGUEST_TYPE=%d && ",type)+
|
||||
QString().sprintf("NUMBER=%d",i+1);
|
||||
QString().sprintf("MATRIX_NUM=%d && ",edit_matrix->matrix());
|
||||
if(edit_matrix->type()==RDMatrix::LogitekVguest) {
|
||||
sql+=QString().sprintf("VGUEST_TYPE=%d && ",type);
|
||||
}
|
||||
sql+=QString().sprintf("NUMBER=%d",i+1);
|
||||
q=new RDSqlQuery(sql);
|
||||
if(!q->first()) {
|
||||
sql=QString("insert into VGUEST_RESOURCES set ")+
|
||||
"STATION_NAME=\""+RDEscapeString(edit_matrix->station())+"\","+
|
||||
QString().sprintf("MATRIX_NUM=%d,",edit_matrix->matrix())+
|
||||
QString().sprintf("VGUEST_TYPE=%d,",type)+
|
||||
QString().sprintf("NUMBER=%d",i+1);
|
||||
QString().sprintf("MATRIX_NUM=%d,",edit_matrix->matrix());
|
||||
if(edit_matrix->type()==RDMatrix::LogitekVguest) {
|
||||
sql+=QString().sprintf("VGUEST_TYPE=%d,",type);
|
||||
}
|
||||
sql+=QString().sprintf("NUMBER=%d",i+1);
|
||||
RDSqlQuery::apply(sql);
|
||||
}
|
||||
}
|
||||
@@ -1532,7 +1549,7 @@ void EditMatrix::AddVguest(RDMatrix::VguestType type) const
|
||||
}
|
||||
|
||||
|
||||
void EditMatrix::PruneVguest(RDMatrix::VguestType type) const
|
||||
void EditMatrix::PruneResources(RDMatrix::VguestType type) const
|
||||
{
|
||||
QString sql;
|
||||
|
||||
@@ -1543,14 +1560,16 @@ void EditMatrix::PruneVguest(RDMatrix::VguestType type) const
|
||||
|
||||
sql=QString("delete from VGUEST_RESOURCES where ")+
|
||||
"STATION_NAME=\""+RDEscapeString(edit_matrix->station())+"\" && "+
|
||||
QString().sprintf("MATRIX_NUM=%d && ",edit_matrix->matrix())+
|
||||
QString().sprintf("VGUEST_TYPE=%d && ",type)+
|
||||
QString().sprintf("NUMBER>%d",entry_quan);
|
||||
QString().sprintf("MATRIX_NUM=%d && ",edit_matrix->matrix());
|
||||
if(edit_matrix->type()==RDMatrix::LogitekVguest) {
|
||||
sql+=QString().sprintf("VGUEST_TYPE=%d && ",type);
|
||||
}
|
||||
sql+=QString().sprintf("NUMBER>%d",entry_quan);
|
||||
RDSqlQuery::apply(sql);
|
||||
}
|
||||
|
||||
|
||||
bool EditMatrix::ConfirmPruneVguest(RDMatrix::VguestType type)
|
||||
bool EditMatrix::ConfirmPruneResources(RDMatrix::VguestType type)
|
||||
{
|
||||
QString sql;
|
||||
RDSqlQuery *q=NULL;
|
||||
@@ -1566,9 +1585,11 @@ bool EditMatrix::ConfirmPruneVguest(RDMatrix::VguestType type)
|
||||
"ID "+ // 00
|
||||
"from VGUEST_RESOURCES where "+
|
||||
"STATION_NAME=\""+RDEscapeString(edit_matrix->station())+"\" && "+
|
||||
QString().sprintf("MATRIX_NUM=%d && ",edit_matrix->matrix())+
|
||||
QString().sprintf("VGUEST_TYPE=%d && ",type)+
|
||||
QString().sprintf("NUMBER>%d",entry_quan);
|
||||
QString().sprintf("MATRIX_NUM=%d && ",edit_matrix->matrix());
|
||||
if(edit_matrix->type()==RDMatrix::LogitekVguest) {
|
||||
sql+=QString().sprintf("VGUEST_TYPE=%d && ",type);
|
||||
}
|
||||
sql+=QString().sprintf("NUMBER>%d",entry_quan);
|
||||
q=new RDSqlQuery(sql);
|
||||
if(q->first()) {
|
||||
if(QMessageBox::warning(this,"RDAdmin - "+tr("Warning"),
|
||||
|
@@ -73,9 +73,9 @@ class EditMatrix : public RDDialog
|
||||
void PruneEndpoints(RDMatrix::Endpoint ep) const;
|
||||
bool ConfirmPruneEndpoints(RDMatrix::Endpoint ep);
|
||||
|
||||
void AddVguest(RDMatrix::VguestType type) const;
|
||||
void PruneVguest(RDMatrix::VguestType type) const;
|
||||
bool ConfirmPruneVguest(RDMatrix::VguestType type);
|
||||
void AddResources(RDMatrix::VguestType type) const;
|
||||
void PruneResources(RDMatrix::VguestType type) const;
|
||||
bool ConfirmPruneResources(RDMatrix::VguestType type);
|
||||
|
||||
RDMatrix *edit_matrix;
|
||||
QString edit_stationname;
|
||||
|
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Edit an SAS Resource Record.
|
||||
//
|
||||
// (C) Copyright 2002-2018 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// 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
|
||||
@@ -18,21 +18,13 @@
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <qmessagebox.h>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <rdtextvalidator.h>
|
||||
#include "edit_sas_resource.h"
|
||||
|
||||
#include <edit_sas_resource.h>
|
||||
|
||||
EditSasResource::EditSasResource(int *enginenum,int *devicenum,int *relaynum,
|
||||
QWidget *parent)
|
||||
EditSasResource::EditSasResource(QWidget *parent)
|
||||
: RDDialog(parent)
|
||||
{
|
||||
setModal(true);
|
||||
|
||||
edit_enginenum=enginenum;
|
||||
edit_devicenum=devicenum;
|
||||
edit_relaynum=relaynum;
|
||||
setWindowTitle("RDAdmin - "+tr("Edit SAS Switch"));
|
||||
|
||||
//
|
||||
@@ -91,19 +83,6 @@ EditSasResource::EditSasResource(int *enginenum,int *devicenum,int *relaynum,
|
||||
button->setFont(buttonFont());
|
||||
button->setText(tr("&Cancel"));
|
||||
connect(button,SIGNAL(clicked()),this,SLOT(cancelData()));
|
||||
|
||||
//
|
||||
// Load Data
|
||||
//
|
||||
if(*enginenum>=0) {
|
||||
edit_enginenum_edit->setText(QString().sprintf("%d",*enginenum));
|
||||
}
|
||||
if(*devicenum>=0) {
|
||||
edit_devicenum_edit->setText(QString().sprintf("%d",*devicenum));
|
||||
}
|
||||
if(*relaynum>=0) {
|
||||
edit_relaynum_edit->setText(QString().sprintf("%d",*relaynum));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,6 +98,43 @@ QSizePolicy EditSasResource::sizePolicy() const
|
||||
}
|
||||
|
||||
|
||||
int EditSasResource::exec(unsigned id)
|
||||
{
|
||||
edit_id=id;
|
||||
|
||||
QString sql=QString("select ")+
|
||||
"NUMBER,"+ // 00
|
||||
"ENGINE_NUM,"+ // 01
|
||||
"DEVICE_NUM,"+ // 02
|
||||
"RELAY_NUM "+ // 03
|
||||
"from VGUEST_RESOURCES where "+
|
||||
QString().sprintf("ID=%u",edit_id);
|
||||
RDSqlQuery *q=new RDSqlQuery(sql);
|
||||
if(q->first()) {
|
||||
if(q->value(1).toInt()>=0) {
|
||||
edit_enginenum_edit->setText(QString().sprintf("%d",q->value(1).toInt()));
|
||||
}
|
||||
else {
|
||||
edit_enginenum_edit->setText("");
|
||||
}
|
||||
if(q->value(2).toInt()>=0) {
|
||||
edit_devicenum_edit->setText(QString().sprintf("%d",q->value(2).toInt()));
|
||||
}
|
||||
else {
|
||||
edit_devicenum_edit->setText("");
|
||||
}
|
||||
if(q->value(3).toInt()>=0) {
|
||||
edit_relaynum_edit->setText(QString().sprintf("%d",q->value(3).toInt()));
|
||||
}
|
||||
else {
|
||||
edit_relaynum_edit->setText("");
|
||||
}
|
||||
}
|
||||
delete q;
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
||||
|
||||
void EditSasResource::okData()
|
||||
{
|
||||
bool ok;
|
||||
@@ -155,14 +171,19 @@ void EditSasResource::okData()
|
||||
return;
|
||||
}
|
||||
}
|
||||
*edit_enginenum=enginenum;
|
||||
*edit_devicenum=devicenum;
|
||||
*edit_relaynum=relaynum;
|
||||
done(0);
|
||||
|
||||
QString sql=QString("update VGUEST_RESOURCES set ")+
|
||||
QString().sprintf("ENGINE_NUM=%d,",enginenum)+
|
||||
QString().sprintf("DEVICE_NUM=%d,",devicenum)+
|
||||
QString().sprintf("RELAY_NUM=%d ",relaynum)+
|
||||
QString().sprintf("where ID=%u",edit_id);
|
||||
RDSqlQuery::apply(sql);
|
||||
|
||||
done(true);
|
||||
}
|
||||
|
||||
|
||||
void EditSasResource::cancelData()
|
||||
{
|
||||
done(1);
|
||||
done(false);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Edit an SAS Resource Record.
|
||||
//
|
||||
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// 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,35 +21,33 @@
|
||||
#ifndef EDIT_SAS_RESOURCE_H
|
||||
#define EDIT_SAS_RESOURCE_H
|
||||
|
||||
#include <qcombobox.h>
|
||||
#include <qlabel.h>
|
||||
#include <qlineedit.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
|
||||
#include <rddialog.h>
|
||||
#include <rdmatrix.h>
|
||||
#include <rduser.h>
|
||||
|
||||
class EditSasResource : public RDDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
EditSasResource(int *enginenum,int *devicenum,int *relaynum,QWidget *parent=0);
|
||||
EditSasResource(QWidget *parent=0);
|
||||
QSize sizeHint() const;
|
||||
QSizePolicy sizePolicy() const;
|
||||
|
||||
public slots:
|
||||
int exec(unsigned id);
|
||||
|
||||
private slots:
|
||||
void okData();
|
||||
void cancelData();
|
||||
|
||||
private:
|
||||
int *edit_enginenum;
|
||||
int *edit_devicenum;
|
||||
int *edit_relaynum;
|
||||
QLineEdit *edit_enginenum_edit;
|
||||
QLineEdit *edit_devicenum_edit;
|
||||
QLabel *edit_relaynum_label;
|
||||
QLineEdit *edit_relaynum_edit;
|
||||
unsigned edit_id;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// List SAS Resources.
|
||||
//
|
||||
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// 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
|
||||
@@ -29,8 +29,6 @@
|
||||
ListSasResources::ListSasResources(RDMatrix *matrix,int size,QWidget *parent)
|
||||
: RDDialog(parent)
|
||||
{
|
||||
setModal(true);
|
||||
|
||||
QString sql;
|
||||
QString str;
|
||||
|
||||
@@ -43,27 +41,30 @@ ListSasResources::ListSasResources(RDMatrix *matrix,int size,QWidget *parent)
|
||||
//
|
||||
setMinimumSize(sizeHint());
|
||||
|
||||
//
|
||||
// Dialogs
|
||||
//
|
||||
list_edit_resource_dialog=new EditSasResource(this);
|
||||
|
||||
//
|
||||
// Resources List Box
|
||||
//
|
||||
list_list_view=new Q3ListView(this);
|
||||
list_title_label=
|
||||
new QLabel(list_list_view,tr("SAS Switches"),this);
|
||||
//
|
||||
// Resources List Box
|
||||
//
|
||||
list_list_view=new RDTableView(this);
|
||||
list_list_model=
|
||||
new RDResourceListModel(list_matrix,RDMatrix::VguestTypeNone,this);
|
||||
list_list_model->setFont(defaultFont());
|
||||
list_list_model->setPalette(palette());
|
||||
list_list_view->setModel(list_list_model);
|
||||
list_title_label=new QLabel(list_list_view,tr("SAS Switches"),this);
|
||||
list_title_label->setFont(labelFont());
|
||||
list_list_view->setAllColumnsShowFocus(true);
|
||||
list_list_view->setItemMargin(5);
|
||||
list_list_view->addColumn(tr("GPIO Line"));
|
||||
list_list_view->setColumnAlignment(0,Qt::AlignHCenter);
|
||||
list_list_view->addColumn(tr("Console"));
|
||||
list_list_view->setColumnAlignment(1,Qt::AlignHCenter);
|
||||
list_list_view->addColumn(tr("Source"));
|
||||
list_list_view->setColumnAlignment(2,Qt::AlignHCenter);
|
||||
list_list_view->addColumn(tr("Opto/Relay"));
|
||||
list_list_view->setColumnAlignment(3,Qt::AlignHCenter);
|
||||
connect(list_list_view,
|
||||
SIGNAL(doubleClicked(Q3ListViewItem *,const QPoint &,int)),
|
||||
this,
|
||||
SLOT(doubleClickedData(Q3ListViewItem *,const QPoint &,int)));
|
||||
connect(list_list_view,SIGNAL(doubleClicked(const QModelIndex &)),
|
||||
this,SLOT(doubleClickedData(const QModelIndex &)));
|
||||
connect(list_list_model,SIGNAL(modelReset()),
|
||||
list_list_view,SLOT(resizeColumnsToContents()));
|
||||
list_list_view->resizeColumnsToContents();
|
||||
|
||||
//
|
||||
// Edit Button
|
||||
@@ -74,26 +75,18 @@ ListSasResources::ListSasResources(RDMatrix *matrix,int size,QWidget *parent)
|
||||
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()));
|
||||
list_close_button=new QPushButton(this);
|
||||
list_close_button->setFont(buttonFont());
|
||||
list_close_button->setText(tr("&Close"));
|
||||
connect(list_close_button,SIGNAL(clicked()),this,SLOT(closeData()));
|
||||
}
|
||||
|
||||
//
|
||||
// Cancel Button
|
||||
//
|
||||
list_cancel_button=new QPushButton(this);
|
||||
list_cancel_button->setFont(buttonFont());
|
||||
list_cancel_button->setText(tr("&Cancel"));
|
||||
connect(list_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
|
||||
|
||||
//
|
||||
// Load Values
|
||||
//
|
||||
RefreshList();
|
||||
ListSasResources::~ListSasResources()
|
||||
{
|
||||
delete list_edit_resource_dialog;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,116 +104,28 @@ QSizePolicy ListSasResources::sizePolicy() const
|
||||
|
||||
void ListSasResources::editData()
|
||||
{
|
||||
int engine_num=-1;
|
||||
int device_num=-1;
|
||||
int relay_num=-1;
|
||||
QModelIndexList rows=list_list_view->selectionModel()->selectedRows();
|
||||
|
||||
Q3ListViewItem *item=list_list_view->selectedItem();
|
||||
if(item==NULL) {
|
||||
if(rows.size()!=1) {
|
||||
return;
|
||||
}
|
||||
if(!item->text(1).isEmpty()) {
|
||||
engine_num=item->text(1).toInt();
|
||||
|
||||
if(list_edit_resource_dialog->
|
||||
exec(list_list_model->resourceId(rows.first()))) {
|
||||
list_list_model->refresh(rows.first());
|
||||
}
|
||||
if(!item->text(2).isEmpty()) {
|
||||
device_num=item->text(2).toInt();
|
||||
}
|
||||
if(!item->text(3).isEmpty()) {
|
||||
relay_num=item->text(3).toInt();
|
||||
}
|
||||
EditSasResource *dialog=
|
||||
new EditSasResource(&engine_num,&device_num,&relay_num,this);
|
||||
if(dialog->exec()==0) {
|
||||
if(engine_num>=0) {
|
||||
item->setText(1,QString().sprintf("%d",engine_num));
|
||||
}
|
||||
else {
|
||||
item->setText(1,"");
|
||||
}
|
||||
if(device_num>=0) {
|
||||
item->setText(2,QString().sprintf("%d",device_num));
|
||||
}
|
||||
else {
|
||||
item->setText(2,"");
|
||||
}
|
||||
if(relay_num>=0) {
|
||||
item->setText(3,QString().sprintf("%d",relay_num));
|
||||
}
|
||||
else {
|
||||
item->setText(3,"");
|
||||
}
|
||||
}
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
|
||||
void ListSasResources::doubleClickedData(Q3ListViewItem *item,
|
||||
const QPoint &pt,int col)
|
||||
void ListSasResources::doubleClickedData(const QModelIndex &index)
|
||||
{
|
||||
editData();
|
||||
}
|
||||
|
||||
|
||||
void ListSasResources::okData()
|
||||
void ListSasResources::closeData()
|
||||
{
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
int engine_num=-1;
|
||||
int device_num=-1;
|
||||
int surface_num=-1;
|
||||
int relay_num=-1;
|
||||
|
||||
Q3ListViewItem *item=list_list_view->firstChild();
|
||||
while(item!=NULL) {
|
||||
engine_num=-1;
|
||||
device_num=-1;
|
||||
surface_num=-1;
|
||||
relay_num=-1;
|
||||
if(!item->text(1).isEmpty()) {
|
||||
engine_num=item->text(1).toInt();
|
||||
}
|
||||
if(!item->text(2).isEmpty()) {
|
||||
device_num=item->text(2).toInt();
|
||||
}
|
||||
if(!item->text(3).isEmpty()) {
|
||||
relay_num=item->text(3).toInt();
|
||||
}
|
||||
sql=QString("select ID from VGUEST_RESOURCES where" )+
|
||||
"(STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\")&&"+
|
||||
QString().sprintf("(MATRIX_NUM=%d)&&",list_matrix->matrix())+
|
||||
QString().sprintf("(NUMBER=%d)",item->text(0).toInt());
|
||||
q=new RDSqlQuery(sql);
|
||||
if(q->first()) {
|
||||
sql=QString("update VGUEST_RESOURCES set ")+
|
||||
QString().sprintf("ENGINE_NUM=%d,",engine_num)+
|
||||
QString().sprintf("DEVICE_NUM=%d,",device_num)+
|
||||
QString().sprintf("SURFACE_NUM=%d,",surface_num)+
|
||||
QString().sprintf("RELAY_NUM=%d where ",relay_num)+
|
||||
"(STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\")&&"+
|
||||
QString().sprintf("(MATRIX_NUM=%d)&&",list_matrix->matrix())+
|
||||
QString().sprintf("(NUMBER=%d)",item->text(0).toInt());
|
||||
}
|
||||
else {
|
||||
sql=QString("insert into VGUEST_RESOURCES set ")+
|
||||
"STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\","+
|
||||
QString().sprintf("MATRIX_NUM=%d,",list_matrix->matrix())+
|
||||
QString().sprintf("NUMBER=%d,",item->text(0).toInt())+
|
||||
QString().sprintf("ENGINE_NUM=%d,",engine_num)+
|
||||
QString().sprintf("DEVICE_NUM=%d,",device_num)+
|
||||
QString().sprintf("SURFACE_NUM=%d,",surface_num)+
|
||||
QString().sprintf("RELAY_NUM=%d",relay_num);
|
||||
}
|
||||
q=new RDSqlQuery(sql);
|
||||
delete q;
|
||||
item=item->nextSibling();
|
||||
}
|
||||
done(0);
|
||||
}
|
||||
|
||||
|
||||
void ListSasResources::cancelData()
|
||||
{
|
||||
done(-1);
|
||||
done(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -229,82 +134,5 @@ void ListSasResources::resizeEvent(QResizeEvent *e)
|
||||
list_list_view->setGeometry(10,24,size().width()-20,size().height()-94);
|
||||
list_title_label->setGeometry(14,5,85,19);
|
||||
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 ListSasResources::RefreshList()
|
||||
{
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
RDSqlQuery *q1;
|
||||
Q3ListViewItem *item;
|
||||
int n=1;
|
||||
int gpis;
|
||||
|
||||
//
|
||||
// Populate Resource Records
|
||||
//
|
||||
sql=QString("select GPIS from MATRICES where ")+
|
||||
"(STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\")&&"+
|
||||
QString().sprintf("(MATRIX=%d)",list_matrix->matrix());
|
||||
q=new RDSqlQuery(sql);
|
||||
if(!q->first()) {
|
||||
delete q;
|
||||
return;
|
||||
}
|
||||
gpis=q->value(0).toInt();
|
||||
delete q;
|
||||
for(int i=0;i<gpis;i++) {
|
||||
sql=QString("select NUMBER from VGUEST_RESOURCES where ")+
|
||||
"(STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\")&&"+
|
||||
QString().sprintf("(MATRIX_NUM=%d)&&",list_matrix->matrix())+
|
||||
QString().sprintf("(NUMBER=%d)",i+1);
|
||||
q=new RDSqlQuery(sql);
|
||||
if(!q->first()) {
|
||||
sql=QString("insert into VGUEST_RESOURCES set ")+
|
||||
QString().sprintf("NUMBER=%d,",i+1)+
|
||||
"STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\","+
|
||||
QString().sprintf("MATRIX_NUM=%d",list_matrix->matrix());
|
||||
q1=new RDSqlQuery(sql);
|
||||
delete q1;
|
||||
}
|
||||
delete q;
|
||||
}
|
||||
|
||||
sql=QString("select ")+
|
||||
"NUMBER,"+
|
||||
"ENGINE_NUM,"+
|
||||
"DEVICE_NUM,"+
|
||||
"RELAY_NUM "+
|
||||
"from VGUEST_RESOURCES where "+
|
||||
"(STATION_NAME=\""+RDEscapeString(list_matrix->station())+"\")&&"+
|
||||
QString().sprintf("(MATRIX_NUM=%d)",list_matrix->matrix())+
|
||||
"order by NUMBER";
|
||||
q=new RDSqlQuery(sql);
|
||||
list_list_view->clear();
|
||||
while(q->next()) {
|
||||
while(q->value(0).toInt()>n) {
|
||||
item=new Q3ListViewItem(list_list_view);
|
||||
item->setText(0,QString().sprintf("%03d",n++));
|
||||
}
|
||||
item=new Q3ListViewItem(list_list_view);
|
||||
item->setText(0,QString().sprintf("%03d",q->value(0).toInt()));
|
||||
if(q->value(1).toInt()>=0) {
|
||||
item->setText(1,QString().sprintf("%d",q->value(1).toInt()));
|
||||
}
|
||||
if(q->value(2).toInt()>=0) {
|
||||
item->setText(2,QString().sprintf("%d",q->value(2).toInt()));
|
||||
}
|
||||
if(q->value(3).toInt()>=0) {
|
||||
item->setText(3,QString().sprintf("%d",q->value(3).toInt()));
|
||||
}
|
||||
n++;
|
||||
}
|
||||
for(int i=n;i<(list_size+1);i++) {
|
||||
item=new Q3ListViewItem(list_list_view);
|
||||
item->setText(0,QString().sprintf("%03d",i));
|
||||
}
|
||||
delete q;
|
||||
list_close_button->setGeometry(size().width()-90,size().height()-60,80,50);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// List SAS Resources
|
||||
//
|
||||
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// 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,39 +21,38 @@
|
||||
#ifndef LIST_SAS_RESOURCES_H
|
||||
#define LIST_SAS_RESOURCES_H
|
||||
|
||||
#include <qlabel.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <q3listview.h>
|
||||
|
||||
#include <rddialog.h>
|
||||
#include <rdmatrix.h>
|
||||
#include <rduser.h>
|
||||
#include <rdresourcelistmodel.h>
|
||||
#include <rdtableview.h>
|
||||
|
||||
#include "edit_sas_resource.h"
|
||||
|
||||
class ListSasResources : public RDDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ListSasResources(RDMatrix *matrix,int size,QWidget *parent=0);
|
||||
ListSasResources(RDMatrix *matrix,int size,QWidget *parent=0);
|
||||
~ListSasResources();
|
||||
QSize sizeHint() const;
|
||||
QSizePolicy sizePolicy() const;
|
||||
|
||||
private slots:
|
||||
void editData();
|
||||
void doubleClickedData(Q3ListViewItem *item,const QPoint &pt,int col);
|
||||
void okData();
|
||||
void cancelData();
|
||||
void doubleClickedData(const QModelIndex &index);
|
||||
void closeData();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
|
||||
private:
|
||||
void RefreshList();
|
||||
EditSasResource *list_edit_resource_dialog;
|
||||
RDMatrix *list_matrix;
|
||||
QLabel *list_title_label;
|
||||
Q3ListView *list_list_view;
|
||||
RDTableView *list_list_view;
|
||||
RDResourceListModel *list_list_model;
|
||||
QPushButton *list_edit_button;
|
||||
QPushButton *list_ok_button;
|
||||
QPushButton *list_cancel_button;
|
||||
QPushButton *list_close_button;
|
||||
int list_size;
|
||||
QString list_table;
|
||||
};
|
||||
|
@@ -57,6 +57,9 @@ ListVguestResources::ListVguestResources(RDMatrix *matrix,
|
||||
case RDMatrix::VguestTypeRelay:
|
||||
setWindowTitle("RDAdmin - "+tr("vGuest Switches"));
|
||||
break;
|
||||
|
||||
case RDMatrix::VguestTypeNone:
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
|
Reference in New Issue
Block a user