diff --git a/ChangeLog b/ChangeLog index 8888c9a3..37dea3bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22927,3 +22927,6 @@ 2022-03-02 Fred Gleason * Fixed a regression in 'RDLogFilter' that caused a SQL error to be generated filtering for 'recent' logs. +2022-03-02 Fred Gleason + * Implemented sorting of the group list in the 'Rivendell Group + List' dialog in rdadmin(1). diff --git a/lib/rdgrouplistmodel.cpp b/lib/rdgrouplistmodel.cpp index 72718572..f6897cec 100644 --- a/lib/rdgrouplistmodel.cpp +++ b/lib/rdgrouplistmodel.cpp @@ -2,7 +2,7 @@ // // Data model for Rivendell groups // -// (C) Copyright 2021 Fred Gleason +// (C) Copyright 2021-2022 Fred Gleason // // 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,6 +29,16 @@ RDGroupListModel::RDGroupListModel(bool show_all,bool user_is_admin, d_show_all=show_all; d_user_is_admin=user_is_admin; 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 @@ -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 { int row=d_visible_groups.indexOf(grpname); @@ -328,7 +348,7 @@ void RDGroupListModel::updateModel() RDSqlQuery *q=NULL; QString sql=sqlFields()+filterSql(); - sql+="order by `NAME` "; + // sql+="order by `NAME` "; beginResetModel(); d_texts.clear(); d_colors.clear(); @@ -445,6 +465,11 @@ QString RDGroupListModel::filterSql() const sql=sql.left(sql.length()-2); sql+=") "; + sql+="order by "+d_column_fields.at(d_sort_column)+" "; + if(d_sort_order==Qt::DescendingOrder) { + sql+="desc "; + } + return sql; } diff --git a/lib/rdgrouplistmodel.h b/lib/rdgrouplistmodel.h index 164bd82b..8486fd96 100644 --- a/lib/rdgrouplistmodel.h +++ b/lib/rdgrouplistmodel.h @@ -2,7 +2,7 @@ // // Data model for Rivendell groups // -// (C) Copyright 2021 Fred Gleason +// (C) Copyright 2021-2022 Fred Gleason // // 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 @@ -43,6 +43,7 @@ class RDGroupListModel : public QAbstractTableModel QVariant headerData(int section,Qt::Orientation orient, 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; QString groupName(const QModelIndex &row) const; QStringList allGroupNames() const; @@ -76,6 +77,9 @@ class RDGroupListModel : public QAbstractTableModel bool d_show_all; bool d_user_is_admin; QStringList d_visible_groups; + QStringList d_column_fields; + int d_sort_column; + Qt::SortOrder d_sort_order; }; diff --git a/rdadmin/list_groups.cpp b/rdadmin/list_groups.cpp index 36e858ac..dbd9c5b1 100644 --- a/rdadmin/list_groups.cpp +++ b/rdadmin/list_groups.cpp @@ -96,6 +96,8 @@ ListGroups::ListGroups(QWidget *parent) // Group List // 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->setFont(defaultFont()); list_groups_model->setPalette(palette());