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

* Updated 'RDCartDialog' to eliminate superfluous SQL filter updates.
	* Updated 'RDCutDialog' to eliminate superfluous SQL filter updates.
	* Updated rdlibrary(1) to eliminate superfluous SQL filter updates.
	* Updated rdlogedit(1) to eliminate superfluous SQL filter updates.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason
2022-02-28 13:25:41 -05:00
parent c8eb9be8f0
commit 37f9559c37
25 changed files with 315 additions and 244 deletions

View File

@@ -86,13 +86,13 @@ RDCartDialog::RDCartDialog(QString *filter,QString *group,QString *schedcode,
// Cart List
//
cart_cart_view=new RDTableView(this);
cart_cart_view->setSortingEnabled(true);
cart_cart_view->sortByColumn(0,Qt::AscendingOrder);
cart_cart_model=new RDLibraryModel(this);
cart_cart_model->setFont(font());
cart_cart_model->setPalette(palette());
cart_cart_view->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_view,SIGNAL(doubleClicked(const QModelIndex &)),
this,SLOT(cartDoubleClickedData(const QModelIndex &)));

View File

@@ -2,7 +2,7 @@
//
// Filter widget for picking Rivendell carts.
//
// (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
// it under the terms of the GNU General Public License version 2 as
@@ -337,8 +337,6 @@ void RDCartFilter::setShowCartType(RDCart::Type type)
d_showmacro_label->hide();
}
d_show_cart_type=type;
emit filterChanged(filterSql(),cartLimit());
}
}
@@ -353,7 +351,6 @@ void RDCartFilter::setShowTrackCarts(bool state)
{
if(state!=d_show_track_carts) {
d_show_track_carts=state;
emit filterChanged(filterSql(),cartLimit());
}
}
@@ -384,7 +381,6 @@ void RDCartFilter::setService(const QString &svc)
if(!d_service.isEmpty()) {
LoadServiceGroups();
}
emit filterChanged(filterSql(),cartLimit());
}
}
@@ -456,7 +452,7 @@ void RDCartFilter::changeUser()
delete q;
d_search_button->setDisabled(true);
emit filterChanged(filterSql(),cartLimit());
UpdateModel();
}
@@ -486,7 +482,7 @@ void RDCartFilter::searchClickedData()
else {
d_clear_button->setEnabled(true);
}
emit filterChanged(filterSql(),cartLimit());
UpdateModel();
}
@@ -683,6 +679,13 @@ QString RDCartFilter::typeFilter(bool incl_audio,bool incl_macro,
}
void RDCartFilter::showEvent(QShowEvent *e)
{
UpdateModel();
QWidget::showEvent(e);
}
void RDCartFilter::LoadUserGroups()
{
QString sql;
@@ -726,3 +729,14 @@ void RDCartFilter::LoadServiceGroups()
}
delete q;
}
void RDCartFilter::UpdateModel()
{
if(isVisible()&&
((filterSql()!=d_model_filter_sql)||(cartLimit()!=d_model_cart_limit))) {
d_model_filter_sql=filterSql();
d_model_cart_limit=cartLimit();
emit filterChanged(d_model_filter_sql,d_model_cart_limit);
}
}

View File

@@ -88,10 +88,12 @@ class RDCartFilter : public RDWidget
protected:
void resizeEvent(QResizeEvent *e);
void showEvent(QShowEvent *e);
private:
void LoadUserGroups();
void LoadServiceGroups();
void UpdateModel();
RDLibraryModel *d_cart_model;
RDGroupListModel *d_group_model;
QLineEdit *d_filter_edit;
@@ -124,6 +126,9 @@ class RDCartFilter : public RDWidget
QString d_default_group;
bool d_user_is_admin;
QString d_service;
QString d_model_filter_sql;
int d_model_cart_limit;
};

View File

@@ -2,7 +2,7 @@
//
// A widget to select a Rivendell Cut.
//
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-2022 Fred Gleason <fredg@paravelsystems.com>
//
// 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
@@ -147,9 +147,6 @@ RDCutDialog::RDCutDialog(QString *filter,QString *group,QString *schedcode,
cart_cancel_button->setFont(buttonFont());
connect(cart_cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
cart_cart_model->
setFilterSql(cart_cart_filter->filterSql(),cart_cart_filter->cartLimit());
//
// Fix the Window Size
//

View File

@@ -22,6 +22,7 @@
#include "rdconf.h"
#include "rdescape_string.h"
#include "rdlibrarymodel.h"
#include "rdtimeprobe.h"
RDLibraryModel::RDLibraryModel(QObject *parent)
: QAbstractItemModel(parent)
@@ -35,6 +36,7 @@ RDLibraryModel::RDLibraryModel(QObject *parent)
d_sort_order=Qt::AscendingOrder;
d_sort_clauses[Qt::AscendingOrder]="asc";
d_sort_clauses[Qt::DescendingOrder]="desc";
d_filter_set=false;
//
// Column Attributes
@@ -317,7 +319,9 @@ void RDLibraryModel::sort(int col,Qt::SortOrder order)
{
d_sort_column=col;
d_sort_order=order;
setFilterSql(d_filter_sql,d_cart_limit);
if(d_filter_set) {
setFilterSql(d_filter_sql,d_cart_limit);
}
/*
printf("RDLibraryModel::sort():\n");
printf(" d_filter_sql: %s\n",d_filter_sql.toUtf8().constData());
@@ -546,6 +550,8 @@ void RDLibraryModel::setFilterSql(const QString &sql,int cart_limit)
d_sort_clauses.value(d_sort_order);
}
fsql+=", `CUTS`.`PLAY_ORDER` asc ";
d_filter_set=true;
printf("***** FILTER SQL SET *****\n");
updateModel(fsql);
}
@@ -553,6 +559,14 @@ void RDLibraryModel::setFilterSql(const QString &sql,int cart_limit)
void RDLibraryModel::updateModel(const QString &filter_sql)
{
if(!d_filter_set) {
return;
}
printf("%p - filter_sql: %s\n",this,filter_sql.toUtf8().constData());
RDTimeProbe *probe=new RDTimeProbe();
probe->printWaypoint("updateModel - 1");
QString sql;
RDSqlQuery *q=NULL;
@@ -568,6 +582,8 @@ void RDLibraryModel::updateModel(const QString &filter_sql)
QList<QList<QVariant> > list_list;
list_list.push_back(list);
probe->printWaypoint("updateModel - 2");
//
// Reload the color table
//
@@ -582,6 +598,8 @@ void RDLibraryModel::updateModel(const QString &filter_sql)
}
delete q;
probe->printWaypoint("updateModel - 3");
sql=sqlFields()+
filter_sql;
beginResetModel();
@@ -595,6 +613,10 @@ void RDLibraryModel::updateModel(const QString &filter_sql)
d_icons.clear();
unsigned prev_cartnum=0;
int carts_loaded=0;
probe->printWaypoint("updateModel - 4");
// printf("RDLibraryModel::updateModel() SQL: %s\n",sql.toUtf8().constData());
q=new RDSqlQuery(sql);
while(q->next()&&(carts_loaded<d_cart_limit)) {
if(q->value(0).toUInt()!=prev_cartnum) {
@@ -610,10 +632,21 @@ void RDLibraryModel::updateModel(const QString &filter_sql)
prev_cartnum=q->value(0).toUInt();
carts_loaded++;
}
// printf("carts_loaded: %d\n",carts_loaded);
}
delete q;
delete q;
probe->printWaypoint("updateModel - 5");
endResetModel();
probe->printWaypoint("updateModel - 6");
emit rowCountChanged(d_texts.size());
probe->printWaypoint("updateModel - 7");
delete probe;
}

View File

@@ -106,6 +106,7 @@ class RDLibraryModel : public QAbstractItemModel
QList<unsigned> d_cart_numbers;
QList<RDCart::Type> d_cart_types;
QMap<QString,QVariant> d_group_colors;
bool d_filter_set;
};