2021-09-21 Fred Gleason <fredg@paravelsystems.com>

* Enabled column sorting in the Library List in rdlibrary(1).
	* Enabled column sorting in the 'Select Cart' dialog.
	* Enabled column sorting in the 'Select Cut' dialog.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2021-09-21 11:17:26 -04:00
parent f6d0e37b42
commit acd80bcd65
7 changed files with 74 additions and 4 deletions

View File

@@ -22446,3 +22446,7 @@
* Fixed a regression in rdairplay(1) that caused the Stop Counter * Fixed a regression in rdairplay(1) that caused the Stop Counter
to display incorrect Time Remaining values when the system's to display incorrect Time Remaining values when the system's
Time Format was set to 'Twelve Hour'. Time Format was set to 'Twelve Hour'.
2021-09-21 Fred Gleason <fredg@paravelsystems.com>
* Enabled column sorting in the Library List in rdlibrary(1).
* Enabled column sorting in the 'Select Cart' dialog.
* Enabled column sorting in the 'Select Cut' dialog.

View File

@@ -91,6 +91,8 @@ RDCartDialog::RDCartDialog(QString *filter,QString *group,QString *schedcode,
cart_cart_model->setPalette(palette()); cart_cart_model->setPalette(palette());
cart_cart_view->setModel(cart_cart_model); cart_cart_view->setModel(cart_cart_model);
cart_cart_filter->setModel(cart_cart_model); cart_cart_filter->setModel(cart_cart_model);
cart_cart_view->setSortingEnabled(true);
cart_cart_view->sortByColumn(0,Qt::AscendingOrder);
connect(cart_cart_model,SIGNAL(modelReset()),this,SLOT(modelResetData())); connect(cart_cart_model,SIGNAL(modelReset()),this,SLOT(modelResetData()));
connect(cart_cart_view,SIGNAL(doubleClicked(const QModelIndex &)), connect(cart_cart_view,SIGNAL(doubleClicked(const QModelIndex &)),
this,SLOT(cartDoubleClickedData(const QModelIndex &))); this,SLOT(cartDoubleClickedData(const QModelIndex &)));

View File

@@ -244,7 +244,7 @@ QString RDCartFilter::filterSql(const QStringList &and_fields) const
RDEscapeString(d_codes_box->currentText())+"') "; RDEscapeString(d_codes_box->currentText())+"') ";
} }
sql+="order by `CART`.`NUMBER` "; // sql+="order by `CART`.`NUMBER` ";
return sql; return sql;
} }

View File

@@ -99,6 +99,8 @@ RDCutDialog::RDCutDialog(QString *filter,QString *group,QString *schedcode,
cart_cart_model->setPalette(palette()); cart_cart_model->setPalette(palette());
cart_cart_view->setModel(cart_cart_model); cart_cart_view->setModel(cart_cart_model);
cart_cart_filter->setModel(cart_cart_model); cart_cart_filter->setModel(cart_cart_model);
cart_cart_view->setSortingEnabled(true);
cart_cart_view->sortByColumn(0,Qt::AscendingOrder);
connect(cart_cart_model,SIGNAL(modelReset()),this,SLOT(modelResetData())); connect(cart_cart_model,SIGNAL(modelReset()),this,SLOT(modelResetData()));
connect(cart_cart_view,SIGNAL(doubleClicked(const QModelIndex &)), connect(cart_cart_view,SIGNAL(doubleClicked(const QModelIndex &)),
this,SLOT(cartDoubleClickedData(const QModelIndex &))); this,SLOT(cartDoubleClickedData(const QModelIndex &)));

View File

@@ -29,7 +29,12 @@ RDLibraryModel::RDLibraryModel(QObject *parent)
d_font_metrics=NULL; d_font_metrics=NULL;
d_bold_font_metrics=NULL; d_bold_font_metrics=NULL;
d_show_notes=false; d_show_notes=false;
d_filter_sql="";
d_cart_limit=RD_MAX_CART_NUMBER+1; // Effectively "unlimited" d_cart_limit=RD_MAX_CART_NUMBER+1; // Effectively "unlimited"
d_sort_column=0;
d_sort_order=Qt::AscendingOrder;
d_sort_clauses[Qt::AscendingOrder]="asc";
d_sort_clauses[Qt::DescendingOrder]="desc";
// //
// Column Attributes // Column Attributes
@@ -40,66 +45,87 @@ RDLibraryModel::RDLibraryModel(QObject *parent)
d_headers.push_back(tr("Cart")); // 00 d_headers.push_back(tr("Cart")); // 00
d_alignments.push_back(center); d_alignments.push_back(center);
d_order_columns.push_back("`CART`.`NUMBER`");
d_headers.push_back(tr("Group")); // 01 d_headers.push_back(tr("Group")); // 01
d_alignments.push_back(center); d_alignments.push_back(center);
d_order_columns.push_back("`CART`.`GROUP_NAME`");
d_headers.push_back(tr("Length")); // 02 d_headers.push_back(tr("Length")); // 02
d_alignments.push_back(right); d_alignments.push_back(right);
d_order_columns.push_back("`CART`.`FORCED_LENGTH`");
d_headers.push_back(tr("Talk")); // 03 d_headers.push_back(tr("Talk")); // 03
d_alignments.push_back(right); d_alignments.push_back(right);
d_order_columns.push_back("`CART`.`MAXIMUM_TALK_LENGTH`");
d_headers.push_back(tr("Title")); // 04 d_headers.push_back(tr("Title")); // 04
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`TITLE`");
d_headers.push_back(tr("Artist")); // 05 d_headers.push_back(tr("Artist")); // 05
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`ARTIST`");
d_headers.push_back(tr("Start")); // 06 d_headers.push_back(tr("Start")); // 06
d_alignments.push_back(center); d_alignments.push_back(center);
d_order_columns.push_back("`CART`.`START_DATETIME`");
d_headers.push_back(tr("End")); // 07 d_headers.push_back(tr("End")); // 07
d_alignments.push_back(center); d_alignments.push_back(center);
d_order_columns.push_back("`CART`.`END_DATETIME`");
d_headers.push_back(tr("Album")); // 08 d_headers.push_back(tr("Album")); // 08
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`ALBUM`");
d_headers.push_back(tr("Label")); // 09 d_headers.push_back(tr("Label")); // 09
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`LABEL`");
d_headers.push_back(tr("Composer")); // 10 d_headers.push_back(tr("Composer")); // 10
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`COMPOSER`");
d_headers.push_back(tr("Conductor")); // 11 d_headers.push_back(tr("Conductor")); // 11
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`CONDUCTOR`");
d_headers.push_back(tr("Publisher")); // 12 d_headers.push_back(tr("Publisher")); // 12
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`PUBLISHER`");
d_headers.push_back(tr("Client")); // 13 d_headers.push_back(tr("Client")); // 13
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`CLIENT`");
d_headers.push_back(tr("Agency")); // 14 d_headers.push_back(tr("Agency")); // 14
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`AGENCY`");
d_headers.push_back(tr("User Defined")); // 15 d_headers.push_back(tr("User Defined")); // 15
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`USER_DEFINED`");
d_headers.push_back(tr("Cuts")); // 16 d_headers.push_back(tr("Cuts")); // 16
d_alignments.push_back(right); d_alignments.push_back(right);
d_order_columns.push_back("`CART`.`CUT_QUANTITY`");
d_headers.push_back(tr("Last Cut Played")); // 17 d_headers.push_back(tr("Last Cut Played")); // 17
d_alignments.push_back(right); d_alignments.push_back(right);
d_order_columns.push_back("`CART`.`LAST_CUT_PLAYED`");
d_headers.push_back(tr("Enforce Length")); // 18 d_headers.push_back(tr("Enforce Length")); // 18
d_alignments.push_back(center); d_alignments.push_back(center);
d_order_columns.push_back("`CART`.`ENFORCE_LENGTH`");
d_headers.push_back(tr("Length Deviation")); // 19 d_headers.push_back(tr("Length Deviation")); // 19
d_alignments.push_back(center); d_alignments.push_back(center);
d_order_columns.push_back("`CART`.`LENGTH_DEVIATION`");
d_headers.push_back(tr("Owned By")); // 20 d_headers.push_back(tr("Owned By")); // 20
d_alignments.push_back(left); d_alignments.push_back(left);
d_order_columns.push_back("`CART`.`OWNER`");
} }
@@ -287,6 +313,20 @@ QVariant RDLibraryModel::data(const QModelIndex &index,int role) const
} }
void RDLibraryModel::sort(int col,Qt::SortOrder order)
{
d_sort_column=col;
d_sort_order=order;
setFilterSql(d_filter_sql,d_cart_limit);
/*
printf("RDLibraryModel::sort():\n");
printf(" d_filter_sql: %s\n",d_filter_sql.toUtf8().constData());
printf(" d_cart_limit: %d\n",d_cart_limit);
printf("\n");
*/
}
bool RDLibraryModel::isCart(const QModelIndex &index) const bool RDLibraryModel::isCart(const QModelIndex &index) const
{ {
return index.internalId()==0; return index.internalId()==0;
@@ -494,8 +534,20 @@ void RDLibraryModel::setShowNotes(int state)
void RDLibraryModel::setFilterSql(const QString &sql,int cart_limit) void RDLibraryModel::setFilterSql(const QString &sql,int cart_limit)
{ {
// printf("FILTER SQL: %s\n",sql.toUtf8().constData()); // printf("FILTER SQL: %s\n",sql.toUtf8().constData());
d_filter_sql=sql;
d_cart_limit=cart_limit; d_cart_limit=cart_limit;
updateModel(sql); QString fsql=sql;
if(d_sort_column<0) { // Use "natural" sort order
fsql+=" order by `CART`.`NUMBER` asc ";
}
else {
fsql+=" order by "+d_order_columns.at(d_sort_column)+" "+
d_sort_clauses.value(d_sort_order);
}
fsql+=", `CUTS`.`PLAY_ORDER` asc ";
updateModel(fsql);
} }
@@ -610,11 +662,14 @@ void RDLibraryModel::updateRow(int row,RDSqlQuery *q)
QString::asprintf("%06d",q->value(0).toUInt()); QString::asprintf("%06d",q->value(0).toUInt());
d_cart_numbers[row]=q->value(0).toUInt(); d_cart_numbers[row]=q->value(0).toUInt();
d_texts[row][1]=q->value(12); // Group d_texts[row][1]=q->value(12); // Group
d_texts[row][2]=RDGetTimeLength(q->value(1).toUInt()); // Total Length
if(q->value(16).toUInt()==1) { if(q->value(16).toUInt()==1) {
d_texts[row][2]=RDGetTimeLength(q->value(1).toUInt()); // Total Length
d_texts[row][3]= // Talk Length d_texts[row][3]= // Talk Length
RDGetTimeLength(q->value(28).toUInt()-q->value(27).toUInt()); RDGetTimeLength(q->value(28).toUInt()-q->value(27).toUInt());
} }
else {
d_texts[row][3]="0:00";
}
d_texts[row][4]=q->value(2); // Title d_texts[row][4]=q->value(2); // Title
d_texts[row][5]=q->value(3); // Artist d_texts[row][5]=q->value(3); // Artist

View File

@@ -51,6 +51,7 @@ class RDLibraryModel : public QAbstractItemModel
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);
bool isCart(const QModelIndex &index) const; bool isCart(const QModelIndex &index) const;
bool isCut(const QModelIndex &index) const; bool isCut(const QModelIndex &index) const;
unsigned cartNumber(const QModelIndex &index) const; unsigned cartNumber(const QModelIndex &index) const;
@@ -83,13 +84,18 @@ class RDLibraryModel : public QAbstractItemModel
private: private:
QByteArray DumpIndex(const QModelIndex &index,const QString &caption="") const; QByteArray DumpIndex(const QModelIndex &index,const QString &caption="") const;
bool d_show_notes; bool d_show_notes;
QString d_filter_sql;
int d_cart_limit; int d_cart_limit;
int d_sort_column;
Qt::SortOrder d_sort_order;
QPalette d_palette; QPalette d_palette;
QFont d_font; QFont d_font;
QFontMetrics *d_font_metrics; QFontMetrics *d_font_metrics;
QFont d_bold_font; QFont d_bold_font;
QFontMetrics *d_bold_font_metrics; QFontMetrics *d_bold_font_metrics;
QList<QVariant> d_headers; QList<QVariant> d_headers;
QStringList d_order_columns;
QMap<Qt::SortOrder,QString> d_sort_clauses;
QList<QList<QVariant> > d_texts; QList<QList<QVariant> > d_texts;
QList<QList<QVariant> > d_icons; QList<QList<QVariant> > d_icons;
QList<QVariant> d_notes; QList<QVariant> d_notes;

View File

@@ -153,13 +153,14 @@ MainWidget::MainWidget(RDConfig *c,QWidget *parent)
lib_cart_view=new LibraryView(this); lib_cart_view=new LibraryView(this);
lib_cart_view->setGeometry(100,0,430,sizeHint().height()); lib_cart_view->setGeometry(100,0,430,sizeHint().height());
lib_cart_view->setSelectionBehavior(QAbstractItemView::SelectRows); lib_cart_view->setSelectionBehavior(QAbstractItemView::SelectRows);
lib_cart_view->setSortingEnabled(false);
lib_cart_view->setWordWrap(false); lib_cart_view->setWordWrap(false);
lib_cart_model=new RDLibraryModel(this); lib_cart_model=new RDLibraryModel(this);
lib_cart_model->setFont(font()); lib_cart_model->setFont(font());
lib_cart_model->setPalette(palette()); lib_cart_model->setPalette(palette());
lib_cart_filter->setModel(lib_cart_model); lib_cart_filter->setModel(lib_cart_model);
lib_cart_view->setModel(lib_cart_model); lib_cart_view->setModel(lib_cart_model);
lib_cart_view->setSortingEnabled(true);
lib_cart_view->sortByColumn(0,Qt::AscendingOrder);
connect(lib_cart_view,SIGNAL(doubleClicked(const QModelIndex &)), connect(lib_cart_view,SIGNAL(doubleClicked(const QModelIndex &)),
this,SLOT(cartDoubleClickedData(const QModelIndex &))); this,SLOT(cartDoubleClickedData(const QModelIndex &)));
connect(lib_cart_filter,SIGNAL(dragEnabledChanged(bool)), connect(lib_cart_filter,SIGNAL(dragEnabledChanged(bool)),