diff --git a/ChangeLog b/ChangeLog index a3928605..ff0a25f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23681,3 +23681,6 @@ 2022-11-15 Fred Gleason * Added a check for conflicting events to the 'Edit Playout' dialog in rdcatch(1). +2022-11-15 David Klann + * Implemented sorting of the dropbox list in the 'Rivendell + Dropbox List' dialog in rdadmin(1). diff --git a/lib/rddropboxlistmodel.cpp b/lib/rddropboxlistmodel.cpp index 1fc0044c..8614725d 100644 --- a/lib/rddropboxlistmodel.cpp +++ b/lib/rddropboxlistmodel.cpp @@ -26,7 +26,20 @@ RDDropboxListModel::RDDropboxListModel(const QString &hostname,QObject *parent) : QAbstractTableModel(parent) { d_hostname=hostname; - + d_sort_column=0; + d_sort_order=Qt::AscendingOrder; + d_column_fields.push_back("`ID`"); + d_column_fields.push_back("`GROUP_NAME`"); + d_column_fields.push_back("`PATH`"); + d_column_fields.push_back("`NORMALIZATION_LEVEL`"); + d_column_fields.push_back("`AUTOTRIM_LEVEL`"); + d_column_fields.push_back("`TO_CART`"); + d_column_fields.push_back("`FORCE_TO_MONO`"); + d_column_fields.push_back("`USE_CARTCHUNK_ID`"); + d_column_fields.push_back("`DELETE_CUTS`"); + d_column_fields.push_back("`METADATA_PATTERN`"); + d_column_fields.push_back("`SET_USER_DEFINED`"); + // // Column Attributes // @@ -161,6 +174,16 @@ QVariant RDDropboxListModel::data(const QModelIndex &index,int role) const } +void RDDropboxListModel::sort(int col,Qt::SortOrder order) +{ + if((col!=d_sort_column)||(order!=d_sort_order)) { + d_sort_column=col; + d_sort_order=order; + updateModel(); + } +} + + int RDDropboxListModel::dropboxId(const QModelIndex &row) const { return d_box_ids.at(row.row()); @@ -251,8 +274,13 @@ void RDDropboxListModel::updateModel() QList texts; RDSqlQuery *q=NULL; QString sql=sqlFields()+ - "where `DROPBOXES`.`STATION_NAME`='"+RDEscapeString(d_hostname)+"' "+ - "order by `DROPBOXES`.`ID` "; + "where `DROPBOXES`.`STATION_NAME`='"+RDEscapeString(d_hostname)+"' "; //+ + // "order by `DROPBOXES`.`ID` "; + sql+="order by "+d_column_fields.at(d_sort_column)+" "; + if(d_sort_order==Qt::DescendingOrder) { + sql+="desc "; + } + beginResetModel(); d_box_ids.clear(); d_group_colors.clear(); diff --git a/lib/rddropboxlistmodel.h b/lib/rddropboxlistmodel.h index 2dc6cc2a..246b1373 100644 --- a/lib/rddropboxlistmodel.h +++ b/lib/rddropboxlistmodel.h @@ -43,6 +43,7 @@ class RDDropboxListModel : 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); int dropboxId(const QModelIndex &row) const; QModelIndex addDropbox(int box_id); void removeDropbox(const QModelIndex &row); @@ -67,6 +68,9 @@ class RDDropboxListModel : public QAbstractTableModel QList d_group_colors; QList d_box_ids; QString d_hostname; + QStringList d_column_fields; + int d_sort_column; + Qt::SortOrder d_sort_order; }; diff --git a/rdadmin/list_dropboxes.cpp b/rdadmin/list_dropboxes.cpp index cc5dd127..92ebb21d 100644 --- a/rdadmin/list_dropboxes.cpp +++ b/rdadmin/list_dropboxes.cpp @@ -84,6 +84,8 @@ ListDropboxes::ListDropboxes(const QString &stationname,QWidget *parent) // Dropbox List // list_dropboxes_view=new RDTableView(this); + list_dropboxes_view->setSortingEnabled(true); + list_dropboxes_view->sortByColumn(0,Qt::AscendingOrder); list_dropboxes_model=new RDDropboxListModel(stationname,this); list_dropboxes_model->setFont(defaultFont()); list_dropboxes_model->setPalette(palette());