2022-12-08 Fred Gleason <fredg@paravelsystems.com>

* Implemented column sorting for item lists in rdcastmanager(1).

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2022-12-08 15:43:08 -05:00
parent 8beb1f875a
commit fa73bdbdd0
4 changed files with 36 additions and 3 deletions

View File

@ -23781,3 +23781,5 @@
2022-12-08 Fred Gleason <fredg@paravelsystems.com> 2022-12-08 Fred Gleason <fredg@paravelsystems.com>
* Fixed a bug in rdcastmanager(1) that could cause a segfault when * Fixed a bug in rdcastmanager(1) that could cause a segfault when
uploading a new item. uploading a new item.
2022-12-08 Fred Gleason <fredg@paravelsystems.com>
* Implemented column sorting for item lists in rdcastmanager(1).

View File

@ -2,7 +2,7 @@
// //
// Data model for Rivendell podcast episodes // Data model for Rivendell podcast episodes
// //
// (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
@ -30,6 +30,8 @@ RDPodcastListModel::RDPodcastListModel(unsigned feed_id,QObject *parent)
d_feed_id=feed_id; d_feed_id=feed_id;
d_font_metrics=NULL; d_font_metrics=NULL;
d_bold_font_metrics=NULL; d_bold_font_metrics=NULL;
d_sort_column=0;
d_sort_order=Qt::AscendingOrder;
// //
// Column Attributes // Column Attributes
@ -40,30 +42,39 @@ RDPodcastListModel::RDPodcastListModel(unsigned feed_id,QObject *parent)
d_headers.push_back(tr("Title")); // 00 d_headers.push_back(tr("Title")); // 00
d_alignments.push_back(left); d_alignments.push_back(left);
d_column_fields.push_back("`PODCASTS`.`ITEM_TITLE`");
d_headers.push_back(tr("Status")); // 01 d_headers.push_back(tr("Status")); // 01
d_alignments.push_back(center); d_alignments.push_back(center);
d_column_fields.push_back("`PODCASTS`.`STATUS`");
d_headers.push_back(tr("Start")); // 02 d_headers.push_back(tr("Start")); // 02
d_alignments.push_back(left); d_alignments.push_back(left);
d_column_fields.push_back("`PODCASTS`.`EFFECTIVE_DATETIME`");
d_headers.push_back(tr("Expiration")); // 03 d_headers.push_back(tr("Expiration")); // 03
d_alignments.push_back(left); d_alignments.push_back(left);
d_column_fields.push_back("`PODCASTS`.`EXPIRATION_DATETIME`");
d_headers.push_back(tr("Length")); // 04 d_headers.push_back(tr("Length")); // 04
d_alignments.push_back(right); d_alignments.push_back(right);
d_column_fields.push_back("`PODCASTS`.`AUDIO_LENGTH`");
d_headers.push_back(tr("Feed")); // 05 d_headers.push_back(tr("Feed")); // 05
d_alignments.push_back(center); d_alignments.push_back(center);
d_column_fields.push_back("`FEEDS`.`KEY_NAME`");
d_headers.push_back(tr("Category")); // 06 d_headers.push_back(tr("Category")); // 06
d_alignments.push_back(left); d_alignments.push_back(left);
d_column_fields.push_back("`FEEDS`.`CHANNEL_CATEGORY`");
d_headers.push_back(tr("Posted By")); // 07 d_headers.push_back(tr("Posted By")); // 07
d_alignments.push_back(left); d_alignments.push_back(left);
d_column_fields.push_back("`PODCASTS`.`ORIGIN_LOGIN_NAME`");
d_headers.push_back(tr("SHA1")); // 08 d_headers.push_back(tr("SHA1")); // 08
d_alignments.push_back(left); d_alignments.push_back(left);
d_column_fields.push_back("`PODCASTS`.`SHA1_HASH`");
updateModel(); updateModel();
} }
@ -177,6 +188,16 @@ QVariant RDPodcastListModel::data(const QModelIndex &index,int role) const
} }
void RDPodcastListModel::sort(int col,Qt::SortOrder order)
{
if((col!=d_sort_column)||(order!=d_sort_order)) {
d_sort_column=col;
d_sort_order=order;
updateModel();
}
}
unsigned RDPodcastListModel::castId(const QModelIndex &row) const unsigned RDPodcastListModel::castId(const QModelIndex &row) const
{ {
return d_cast_ids.at(row.row()); return d_cast_ids.at(row.row());
@ -304,7 +325,11 @@ void RDPodcastListModel::updateModel()
"where "+ "where "+
QString::asprintf("`PODCASTS`.`FEED_ID`=%u ",d_feed_id)+ QString::asprintf("`PODCASTS`.`FEED_ID`=%u ",d_feed_id)+
d_filter_sql+ d_filter_sql+
" order by `PODCASTS`.`ORIGIN_DATETIME` desc"; " order by "+d_column_fields.at(d_sort_column)+" ";
if(d_sort_order==Qt::DescendingOrder) {
sql+="desc ";
}
beginResetModel(); beginResetModel();
d_cast_ids.clear(); d_cast_ids.clear();
d_texts.clear(); d_texts.clear();

View File

@ -2,7 +2,7 @@
// //
// Data model for Rivendell podcast episodes // Data model for Rivendell podcast episodes
// //
// (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
@ -44,6 +44,7 @@ class RDPodcastListModel : 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);
unsigned castId(const QModelIndex &row) const; unsigned castId(const QModelIndex &row) const;
QModelIndex addCast(unsigned cast_id); QModelIndex addCast(unsigned cast_id);
void removeCast(const QModelIndex &row); void removeCast(const QModelIndex &row);
@ -75,6 +76,9 @@ class RDPodcastListModel : public QAbstractTableModel
QList<QList<QVariant> > d_icons; QList<QList<QVariant> > d_icons;
unsigned d_feed_id; unsigned d_feed_id;
QString d_filter_sql; QString d_filter_sql;
QStringList d_column_fields;
int d_sort_column;
Qt::SortOrder d_sort_order;
}; };

View File

@ -81,6 +81,8 @@ ListCasts::ListCasts(unsigned feed_id,QWidget *parent)
list_casts_label->setFont(bigLabelFont()); list_casts_label->setFont(bigLabelFont());
list_casts_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter); list_casts_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
list_casts_view=new RDTableView(this); list_casts_view=new RDTableView(this);
list_casts_view->setSortingEnabled(true);
list_casts_view->sortByColumn(2,Qt::DescendingOrder);
list_casts_model=new RDPodcastListModel(feed_id,this); list_casts_model=new RDPodcastListModel(feed_id,this);
list_casts_model->setFont(font()); list_casts_model->setFont(font());
list_casts_model->setPalette(palette()); list_casts_model->setPalette(palette());