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

* Added notification support to the 'RDLibraryModel' class.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2022-12-01 16:44:32 -05:00
parent 90987c3374
commit a157602e10
3 changed files with 89 additions and 37 deletions

View File

@ -23735,3 +23735,5 @@
2022-12-01 Fred Gleason <fredg@paravelsystems.com> 2022-12-01 Fred Gleason <fredg@paravelsystems.com>
* Modifed the 'Edit Audio' dialog in rdlibrary(1) so the waveform * Modifed the 'Edit Audio' dialog in rdlibrary(1) so the waveform
display is initially fully scrolled to the left. display is initially fully scrolled to the left.
2022-12-01 Fred Gleason <fredg@paravelsystems.com>
* Added notification support to the 'RDLibraryModel' class.

View File

@ -133,6 +133,9 @@ RDLibraryModel::RDLibraryModel(QObject *parent)
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`"); d_order_columns.push_back("`CART`.`OWNER`");
connect(rda->ripc(),SIGNAL(notificationReceived(RDNotification *)),
this,SLOT(processNotification(RDNotification *)));
} }
@ -417,6 +420,10 @@ QString RDLibraryModel::cartOwnedBy(const QModelIndex &index)
QModelIndex RDLibraryModel::addCart(unsigned cartnum) QModelIndex RDLibraryModel::addCart(unsigned cartnum)
{ {
if(d_cart_numbers.contains(cartnum)) {
return refreshCart(cartnum);
}
else {
// //
// Find the insertion offset // Find the insertion offset
// //
@ -456,6 +463,7 @@ QModelIndex RDLibraryModel::addCart(unsigned cartnum)
emit rowCountChanged(d_texts.size()); emit rowCountChanged(d_texts.size());
return createIndex(offset,0,(quintptr)0); return createIndex(offset,0,(quintptr)0);
}
} }
@ -509,7 +517,7 @@ void RDLibraryModel::refreshRow(const QModelIndex &index)
} }
void RDLibraryModel::refreshCart(unsigned cartnum) QModelIndex RDLibraryModel::refreshCart(unsigned cartnum)
{ {
QString cartnum_str=QString::asprintf("%06u",cartnum); QString cartnum_str=QString::asprintf("%06u",cartnum);
for(int i=0;i<d_texts.size();i++) { for(int i=0;i<d_texts.size();i++) {
@ -517,8 +525,10 @@ void RDLibraryModel::refreshCart(unsigned cartnum)
updateCartLine(i); updateCartLine(i);
emit dataChanged(createIndex(i,0,(quintptr)0), emit dataChanged(createIndex(i,0,(quintptr)0),
createIndex(i,columnCount(),(quintptr)0)); createIndex(i,columnCount(),(quintptr)0));
return createIndex(i,0);
} }
} }
return QModelIndex();
} }
@ -561,6 +571,43 @@ void RDLibraryModel::setFilterSql(const QString &sql,int cart_limit)
} }
void RDLibraryModel::processNotification(RDNotification *notify)
{
QString sql;
RDSqlQuery *q=NULL;
if(notify->type()==RDNotification::CartType) {
switch(notify->action()) {
case RDNotification::AddAction:
sql=QString("select ")+
"`NUMBER` "+ // 00
"from `CART` "+
d_filter_sql+
QString::asprintf(" && `CART`.`NUMBER`=%u",notify->id().toUInt());
q=new RDSqlQuery(sql);
if(q->first()) {
addCart(notify->id().toUInt());
}
delete q;
break;
case RDNotification::ModifyAction:
refreshCart(notify->id().toUInt());
break;
case RDNotification::DeleteAction:
removeCart(notify->id().toUInt());
break;
case RDNotification::NoAction:
case RDNotification::LastAction:
break;
}
}
}
void RDLibraryModel::updateModel(const QString &filter_sql) void RDLibraryModel::updateModel(const QString &filter_sql)
{ {
if(!d_filter_set) { if(!d_filter_set) {

View File

@ -64,7 +64,7 @@ class RDLibraryModel : public QAbstractItemModel
void removeCart(const QModelIndex &index); void removeCart(const QModelIndex &index);
void removeCart(unsigned cartnum); void removeCart(unsigned cartnum);
void refreshRow(const QModelIndex &index); void refreshRow(const QModelIndex &index);
void refreshCart(unsigned cartnum); QModelIndex refreshCart(unsigned cartnum);
bool showNotes() const; bool showNotes() const;
int cartLimit() const; int cartLimit() const;
@ -75,6 +75,9 @@ class RDLibraryModel : public QAbstractItemModel
void setShowNotes(int state); void setShowNotes(int state);
void setFilterSql(const QString &sql,int cart_limit); void setFilterSql(const QString &sql,int cart_limit);
private slots:
void processNotification(RDNotification *notify);
protected: protected:
void updateModel(const QString &filter_sql); void updateModel(const QString &filter_sql);
void updateCartLine(int cartline); void updateCartLine(int cartline);