2022-03-02 Fred Gleason <fredg@paravelsystems.com>

* Implemented sorting of the group list in the 'Rivendell Group
	List' dialog in rdadmin(1).

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2022-03-02 15:08:44 -05:00
parent bd2fee5e7b
commit bcb22cc706
4 changed files with 37 additions and 3 deletions

View File

@ -22927,3 +22927,6 @@
2022-03-02 Fred Gleason <fredg@paravelsystems.com> 2022-03-02 Fred Gleason <fredg@paravelsystems.com>
* Fixed a regression in 'RDLogFilter' that caused a SQL error to be * Fixed a regression in 'RDLogFilter' that caused a SQL error to be
generated filtering for 'recent' logs. generated filtering for 'recent' logs.
2022-03-02 Fred Gleason <fredg@paravelsystems.com>
* Implemented sorting of the group list in the 'Rivendell Group
List' dialog in rdadmin(1).

View File

@ -2,7 +2,7 @@
// //
// Data model for Rivendell groups // Data model for Rivendell groups
// //
// (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2021-2022 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -29,6 +29,16 @@ RDGroupListModel::RDGroupListModel(bool show_all,bool user_is_admin,
d_show_all=show_all; d_show_all=show_all;
d_user_is_admin=user_is_admin; d_user_is_admin=user_is_admin;
d_service_names.push_back(tr("ALL")); d_service_names.push_back(tr("ALL"));
d_sort_column=0;
d_sort_order=Qt::AscendingOrder;
d_column_fields.push_back("`NAME`");
d_column_fields.push_back("`DESCRIPTION`");
d_column_fields.push_back("`DEFAULT_LOW_CART`");
d_column_fields.push_back("`DEFAULT_HIGH_CART`");
d_column_fields.push_back("`ENFORCE_CART_RANGE`");
d_column_fields.push_back("`NOTIFY_EMAIL_ADDRESS`");
d_column_fields.push_back("`REPORT_TFC`");
d_column_fields.push_back("`REPORT_MUS`");
// //
// Column Attributes // Column Attributes
@ -159,6 +169,16 @@ QVariant RDGroupListModel::data(const QModelIndex &index,int role) const
} }
void RDGroupListModel::sort(int col,Qt::SortOrder order)
{
if((col!=d_sort_column)||(order!=d_sort_order)) {
d_sort_column=col;
d_sort_order=order;
updateModel();
}
}
QModelIndex RDGroupListModel::indexOf(const QString &grpname) const QModelIndex RDGroupListModel::indexOf(const QString &grpname) const
{ {
int row=d_visible_groups.indexOf(grpname); int row=d_visible_groups.indexOf(grpname);
@ -328,7 +348,7 @@ void RDGroupListModel::updateModel()
RDSqlQuery *q=NULL; RDSqlQuery *q=NULL;
QString sql=sqlFields()+filterSql(); QString sql=sqlFields()+filterSql();
sql+="order by `NAME` "; // sql+="order by `NAME` ";
beginResetModel(); beginResetModel();
d_texts.clear(); d_texts.clear();
d_colors.clear(); d_colors.clear();
@ -445,6 +465,11 @@ QString RDGroupListModel::filterSql() const
sql=sql.left(sql.length()-2); sql=sql.left(sql.length()-2);
sql+=") "; sql+=") ";
sql+="order by "+d_column_fields.at(d_sort_column)+" ";
if(d_sort_order==Qt::DescendingOrder) {
sql+="desc ";
}
return sql; return sql;
} }

View File

@ -2,7 +2,7 @@
// //
// Data model for Rivendell groups // Data model for Rivendell groups
// //
// (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com> // (C) Copyright 2021-2022 Fred Gleason <fredg@paravelsystems.com>
// //
// This program is free software; you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License version 2 as
@ -43,6 +43,7 @@ class RDGroupListModel : public QAbstractTableModel
QVariant headerData(int section,Qt::Orientation orient, QVariant headerData(int section,Qt::Orientation orient,
int role=Qt::DisplayRole) const; int role=Qt::DisplayRole) const;
QVariant data(const QModelIndex &index,int role=Qt::DisplayRole) const; QVariant data(const QModelIndex &index,int role=Qt::DisplayRole) const;
void sort(int col,Qt::SortOrder order=Qt::AscendingOrder);
QModelIndex indexOf(const QString &grpname) const; QModelIndex indexOf(const QString &grpname) const;
QString groupName(const QModelIndex &row) const; QString groupName(const QModelIndex &row) const;
QStringList allGroupNames() const; QStringList allGroupNames() const;
@ -76,6 +77,9 @@ class RDGroupListModel : public QAbstractTableModel
bool d_show_all; bool d_show_all;
bool d_user_is_admin; bool d_user_is_admin;
QStringList d_visible_groups; QStringList d_visible_groups;
QStringList d_column_fields;
int d_sort_column;
Qt::SortOrder d_sort_order;
}; };

View File

@ -96,6 +96,8 @@ ListGroups::ListGroups(QWidget *parent)
// Group List // Group List
// //
list_groups_view=new RDTableView(this); list_groups_view=new RDTableView(this);
list_groups_view->setSortingEnabled(true);
list_groups_view->sortByColumn(0,Qt::AscendingOrder);
list_groups_model=new RDGroupListModel(false,true,this); list_groups_model=new RDGroupListModel(false,true,this);
list_groups_model->setFont(defaultFont()); list_groups_model->setFont(defaultFont());
list_groups_model->setPalette(palette()); list_groups_model->setPalette(palette());