mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-07-05 23:19:08 +02:00
2021-01-20 Fred Gleason <fredg@paravelsystems.com>
* Modified 'RDCartFilter' to use 'RDGroupListModel' for the 'Group' dropdown. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
parent
35d6d4ae8d
commit
6ffd94e8ee
@ -20837,3 +20837,6 @@
|
||||
* Added an 'RDGroupListModel' class.
|
||||
* Refactored the 'List Groups' dialog in rdadmin(1) to use the
|
||||
model-based API.
|
||||
2021-01-20 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Modified 'RDCartFilter' to use 'RDGroupListModel' for the
|
||||
'Group' dropdown.
|
||||
|
@ -32,9 +32,11 @@ RDCartFilter::RDCartFilter(bool show_drag_box,QWidget *parent)
|
||||
d_show_cart_type=RDCart::All;
|
||||
d_show_track_carts=true;
|
||||
d_user_is_admin=false;
|
||||
d_model=NULL;
|
||||
d_cart_model=NULL;
|
||||
d_show_drag_box=show_drag_box;
|
||||
|
||||
d_group_model=new RDGroupListModel(true,false,this);
|
||||
|
||||
//
|
||||
// Filter Phrase
|
||||
//
|
||||
@ -74,6 +76,7 @@ RDCartFilter::RDCartFilter(bool show_drag_box,QWidget *parent)
|
||||
// Group Filter
|
||||
//
|
||||
d_group_box=new QComboBox(this);
|
||||
d_group_box->setModel(d_group_model);
|
||||
d_group_label=new QLabel(d_group_box,tr("Group:"),this);
|
||||
d_group_label->setFont(labelFont());
|
||||
d_group_label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
|
||||
@ -180,6 +183,7 @@ RDCartFilter::RDCartFilter(bool show_drag_box,QWidget *parent)
|
||||
|
||||
RDCartFilter::~RDCartFilter()
|
||||
{
|
||||
delete d_group_model;
|
||||
}
|
||||
|
||||
|
||||
@ -404,7 +408,7 @@ void RDCartFilter::setService(const QString &svc)
|
||||
|
||||
RDLibraryModel *RDCartFilter::model() const
|
||||
{
|
||||
return d_model;
|
||||
return d_cart_model;
|
||||
}
|
||||
|
||||
|
||||
@ -443,7 +447,9 @@ void RDCartFilter::changeUser()
|
||||
RDSqlQuery *q;
|
||||
|
||||
if(d_service.isEmpty()) {
|
||||
LoadUserGroups();
|
||||
// LoadUserGroups();
|
||||
d_group_model->changeUser();
|
||||
d_group_box->setCurrentText(tr("ALL"));
|
||||
}
|
||||
|
||||
d_codes_box->clear();
|
||||
@ -455,6 +461,8 @@ void RDCartFilter::changeUser()
|
||||
}
|
||||
delete q;
|
||||
d_search_button->setDisabled(true);
|
||||
|
||||
emit filterChanged(filterSql());
|
||||
}
|
||||
|
||||
|
||||
@ -537,9 +545,9 @@ void RDCartFilter::resizeEvent(QResizeEvent *e)
|
||||
d_clear_button->setGeometry(e->size().width()-90,10,80,50);
|
||||
d_filter_label->setGeometry(10,10,55,20);
|
||||
d_group_label->setGeometry(10,40,55,20);
|
||||
d_group_box->setGeometry(70,40,100,20);
|
||||
d_codes_label->setGeometry(175,40,115,20);
|
||||
d_codes_box->setGeometry(295,40,100,20);
|
||||
d_group_box->setGeometry(70,38,140,24);
|
||||
d_codes_label->setGeometry(215,40,115,20);
|
||||
d_codes_box->setGeometry(335,38,120,24);
|
||||
d_matches_label->setGeometry(660,40,100,20);
|
||||
d_matches_edit->setGeometry(765,40,55,20);
|
||||
d_showmatches_label->setGeometry(760,66,200,20);
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
#include <rdgrouplistmodel.h>
|
||||
#include <rdlibrarymodel.h>
|
||||
#include <rdprofile.h>
|
||||
#include <rdwidget.h>
|
||||
@ -89,7 +90,8 @@ class RDCartFilter : public RDWidget
|
||||
private:
|
||||
void LoadUserGroups();
|
||||
void LoadServiceGroups();
|
||||
RDLibraryModel *d_model;
|
||||
RDLibraryModel *d_cart_model;
|
||||
RDGroupListModel *d_group_model;
|
||||
QLineEdit *d_filter_edit;
|
||||
QLabel *d_filter_label;
|
||||
QComboBox *d_group_box;
|
||||
|
@ -18,12 +18,16 @@
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include "rdapplication.h"
|
||||
#include "rdescape_string.h"
|
||||
#include "rdgrouplistmodel.h"
|
||||
|
||||
RDGroupListModel::RDGroupListModel(QObject *parent)
|
||||
RDGroupListModel::RDGroupListModel(bool show_all,bool user_is_admin,
|
||||
QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
{
|
||||
d_show_all=show_all;
|
||||
d_user_is_admin=user_is_admin;
|
||||
d_service_names.push_back(tr("ALL"));
|
||||
d_log_icons=new RDLogIcons();
|
||||
|
||||
@ -60,6 +64,10 @@ RDGroupListModel::RDGroupListModel(QObject *parent)
|
||||
|
||||
d_headers.push_back(tr("Now & Next"));
|
||||
d_alignments.push_back(center);
|
||||
|
||||
if(user_is_admin) {
|
||||
changeUser();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -256,31 +264,62 @@ void RDGroupListModel::refresh(const QString &grpname)
|
||||
}
|
||||
|
||||
|
||||
void RDGroupListModel::setFilterSql(const QString &sql)
|
||||
void RDGroupListModel::changeUser()
|
||||
{
|
||||
updateModel(sql);
|
||||
QString sql;
|
||||
RDSqlQuery *q=NULL;
|
||||
|
||||
d_visible_groups.clear();
|
||||
d_visible_groups.push_back(tr("ALL"));
|
||||
if(d_user_is_admin) {
|
||||
sql=QString("select ")+
|
||||
"NAME "+ // 00
|
||||
"from GROUPS "+
|
||||
"order by NAME";
|
||||
}
|
||||
else {
|
||||
sql=QString("select ")+
|
||||
"GROUP_NAME "+ // 00
|
||||
"from USER_PERMS where "+
|
||||
"USER_NAME=\""+RDEscapeString(rda->user()->name())+"\" "+
|
||||
"order by GROUP_NAME";
|
||||
}
|
||||
q=new RDSqlQuery(sql);
|
||||
while(q->next()) {
|
||||
d_visible_groups.push_back(q->value(0).toString());
|
||||
}
|
||||
delete q;
|
||||
|
||||
beginResetModel();
|
||||
updateModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
|
||||
void RDGroupListModel::updateModel(const QString &filter_sql)
|
||||
void RDGroupListModel::updateModel()
|
||||
{
|
||||
QList<QVariant> texts;
|
||||
QList<QVariant> icons;
|
||||
|
||||
RDSqlQuery *q=NULL;
|
||||
QString sql=sqlFields();
|
||||
if(!filter_sql.isEmpty()) {
|
||||
sql+="where "+
|
||||
filter_sql;
|
||||
}
|
||||
QString sql=sqlFields()+filterSql();
|
||||
sql+="order by NAME ";
|
||||
beginResetModel();
|
||||
d_texts.clear();
|
||||
d_colors.clear();
|
||||
d_icons.clear();
|
||||
|
||||
if(d_show_all) {
|
||||
d_texts.push_back(texts);
|
||||
d_texts.back().push_back(tr("ALL"));
|
||||
d_colors.push_back(QVariant());
|
||||
d_icons.push_back(icons);
|
||||
}
|
||||
|
||||
q=new RDSqlQuery(sql);
|
||||
while(q->next()) {
|
||||
QList<QVariant> texts;
|
||||
d_texts.push_back(texts);
|
||||
d_colors.push_back(QVariant());
|
||||
QList<QVariant> icons;
|
||||
d_icons.push_back(icons);
|
||||
updateRow(d_texts.size()-1,q);
|
||||
}
|
||||
@ -373,3 +412,18 @@ QString RDGroupListModel::sqlFields() const
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
||||
QString RDGroupListModel::filterSql() const
|
||||
{
|
||||
QString sql=QString(" where (");
|
||||
|
||||
for(int i=0;i<d_visible_groups.size();i++) {
|
||||
sql+=QString("(GROUPS.NAME=\"")+RDEscapeString(d_visible_groups.at(i))+"\")||";
|
||||
}
|
||||
sql=sql.left(sql.length()-2);
|
||||
sql+=") ";
|
||||
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ class RDGroupListModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RDGroupListModel(QObject *parent=0);
|
||||
RDGroupListModel(bool show_all,bool user_is_admin,QObject *parent=0);
|
||||
~RDGroupListModel();
|
||||
QPalette palette();
|
||||
void setPalette(const QPalette &pal);
|
||||
@ -53,13 +53,14 @@ class RDGroupListModel : public QAbstractTableModel
|
||||
void refresh(const QString &grpname);
|
||||
|
||||
public slots:
|
||||
void setFilterSql(const QString &sql);
|
||||
void changeUser();
|
||||
|
||||
protected:
|
||||
void updateModel(const QString &filter_sql);
|
||||
void updateModel();
|
||||
void updateRowLine(int line);
|
||||
void updateRow(int row,RDSqlQuery *q);
|
||||
QString sqlFields() const;
|
||||
virtual QString filterSql() const;
|
||||
|
||||
private:
|
||||
QPalette d_palette;
|
||||
@ -72,6 +73,9 @@ class RDGroupListModel : public QAbstractTableModel
|
||||
QList<QVariant> d_icons;
|
||||
QList<QVariant> d_colors;
|
||||
RDLogIcons *d_log_icons;
|
||||
bool d_show_all;
|
||||
bool d_user_is_admin;
|
||||
QStringList d_visible_groups;
|
||||
};
|
||||
|
||||
|
||||
|
@ -103,7 +103,7 @@ ListGroups::ListGroups(QWidget *parent)
|
||||
list_groups_view->setShowGrid(false);
|
||||
list_groups_view->setSortingEnabled(false);
|
||||
list_groups_view->setWordWrap(false);
|
||||
list_groups_model=new RDGroupListModel(this);
|
||||
list_groups_model=new RDGroupListModel(false,true,this);
|
||||
list_groups_model->setFont(defaultFont());
|
||||
list_groups_model->setPalette(palette());
|
||||
list_groups_view->setModel(list_groups_model);
|
||||
@ -111,38 +111,6 @@ ListGroups::ListGroups(QWidget *parent)
|
||||
connect(list_groups_view,SIGNAL(doubleClicked(const QModelIndex &)),
|
||||
this,SLOT(doubleClickedData(const QModelIndex &)));
|
||||
connect(list_groups_model,SIGNAL(modelReset()),this,SLOT(modelResetData()));
|
||||
|
||||
list_groups_model->setFilterSql(QString());
|
||||
|
||||
/*
|
||||
list_groups_view=new RDListView(this);
|
||||
list_groups_view->setAllColumnsShowFocus(true);
|
||||
list_groups_view->addColumn(tr("Name"));
|
||||
list_groups_view->addColumn(tr("Description"));
|
||||
list_groups_view->addColumn(tr("Start Cart"));
|
||||
list_groups_view->setColumnAlignment(2,Qt::AlignCenter);
|
||||
list_groups_view->addColumn(tr("End Cart"));
|
||||
list_groups_view->setColumnAlignment(3,Qt::AlignHCenter);
|
||||
list_groups_view->addColumn(tr("Enforce Range"));
|
||||
list_groups_view->setColumnAlignment(4,Qt::AlignHCenter);
|
||||
list_groups_view->addColumn(tr("Default Type"));
|
||||
list_groups_view->setColumnAlignment(5,Qt::AlignHCenter);
|
||||
list_groups_view->addColumn(tr("Traffic Report"));
|
||||
list_groups_view->setColumnAlignment(6,Qt::AlignHCenter);
|
||||
list_groups_view->addColumn(tr("Music Report"));
|
||||
list_groups_view->setColumnAlignment(7,Qt::AlignHCenter);
|
||||
list_groups_view->addColumn(tr("Now & Next"));
|
||||
list_groups_view->setColumnAlignment(8,Qt::AlignHCenter);
|
||||
QLabel *list_box_label=new QLabel(list_groups_view,tr("&Groups:"),this);
|
||||
list_box_label->setFont(labelFont());
|
||||
list_box_label->setGeometry(14,11,85,19);
|
||||
connect(list_groups_view,
|
||||
SIGNAL(doubleClicked(Q3ListViewItem *,const QPoint &,int)),
|
||||
this,
|
||||
SLOT(doubleClickedData(Q3ListViewItem *,const QPoint &,int)));
|
||||
*/
|
||||
|
||||
// RefreshList();
|
||||
}
|
||||
|
||||
|
||||
@ -430,95 +398,3 @@ void ListGroups::resizeEvent(QResizeEvent *e)
|
||||
list_close_button->setGeometry(size().width()-90,size().height()-60,80,50);
|
||||
list_groups_view->setGeometry(10,30,size().width()-120,size().height()-40);
|
||||
}
|
||||
|
||||
|
||||
void ListGroups::RefreshList()
|
||||
{
|
||||
/*
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
RDListViewItem *item;
|
||||
|
||||
list_groups_view->clear();
|
||||
sql=QString("select ")+
|
||||
"NAME,"+ // 00
|
||||
"DESCRIPTION,"+ // 01
|
||||
"DEFAULT_LOW_CART,"+ // 02
|
||||
"DEFAULT_HIGH_CART,"+ // 03
|
||||
"ENFORCE_CART_RANGE,"+ // 04
|
||||
"DEFAULT_CART_TYPE,"+ // 05
|
||||
"REPORT_TFC,"+ // 06
|
||||
"REPORT_MUS,"+ // 07
|
||||
"ENABLE_NOW_NEXT,"+ // 08
|
||||
"COLOR "+ // 09
|
||||
"from GROUPS";
|
||||
q=new RDSqlQuery(sql);
|
||||
while (q->next()) {
|
||||
item=new RDListViewItem(list_groups_view);
|
||||
WriteItem(item,q);
|
||||
}
|
||||
delete q;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void ListGroups::RefreshItem(RDListViewItem *item)
|
||||
{
|
||||
/*
|
||||
QString sql;
|
||||
RDSqlQuery *q;
|
||||
|
||||
sql=QString("select ")+
|
||||
"NAME,"+ // 00
|
||||
"DESCRIPTION,"+ // 01
|
||||
"DEFAULT_LOW_CART,"+ // 02
|
||||
"DEFAULT_HIGH_CART,"+ // 03
|
||||
"ENFORCE_CART_RANGE,"+ // 04
|
||||
"DEFAULT_CART_TYPE,"+ // 05
|
||||
"REPORT_TFC,"+ // 06
|
||||
"REPORT_MUS,"+ // 07
|
||||
"ENABLE_NOW_NEXT,"+ // 08
|
||||
"COLOR "+ // 09
|
||||
"from GROUPS where "+
|
||||
"NAME=\""+RDEscapeString(item->text(0))+"\"";
|
||||
q=new RDSqlQuery(sql);
|
||||
if(q->next()) {
|
||||
WriteItem(item,q);
|
||||
}
|
||||
delete q;
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
void ListGroups::WriteItem(RDListViewItem *item,RDSqlQuery *q)
|
||||
{
|
||||
item->setText(0,q->value(0).toString());
|
||||
item->setTextColor(0,q->value(9).toString(),QFont::Bold);
|
||||
item->setText(1,q->value(1).toString());
|
||||
if(q->value(2).toUInt()>0) {
|
||||
item->setText(2,QString().sprintf("%06u",q->value(2).toUInt()));
|
||||
item->setText(3,QString().sprintf("%06u",q->value(3).toUInt()));
|
||||
}
|
||||
else {
|
||||
item->setText(2,"[none]");
|
||||
item->setText(3,"[none]");
|
||||
}
|
||||
item->setText(4,q->value(4).toString());
|
||||
switch((RDCart::Type)q->value(5).toUInt()) {
|
||||
case RDCart::Audio:
|
||||
item->setText(5,"Audio");
|
||||
break;
|
||||
|
||||
case RDCart::Macro:
|
||||
item->setText(5,"Macro");
|
||||
break;
|
||||
|
||||
default:
|
||||
item->setText(5,"[none]");
|
||||
break;
|
||||
}
|
||||
item->setText(6,q->value(6).toString());
|
||||
item->setText(7,q->value(7).toString());
|
||||
item->setText(8,q->value(8).toString());
|
||||
}
|
||||
*/
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <rddb.h>
|
||||
#include <rddialog.h>
|
||||
#include <rdgrouplistmodel.h>
|
||||
//#include <rdlistviewitem.h>
|
||||
|
||||
class ListGroups : public RDDialog
|
||||
{
|
||||
@ -53,10 +52,6 @@ class ListGroups : public RDDialog
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
|
||||
private:
|
||||
void RefreshList();
|
||||
void RefreshItem(RDListViewItem *item);
|
||||
// void WriteItem(RDListViewItem *item,RDSqlQuery *q);
|
||||
// RDListView *list_groups_view;
|
||||
QTableView *list_groups_view;
|
||||
RDGroupListModel *list_groups_model;
|
||||
QPushButton *list_add_button;
|
||||
@ -68,6 +63,4 @@ class ListGroups : public RDDialog
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // LIST_GROUPS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user