changed filtering model to a hand-made solution

This commit is contained in:
csoler 2020-06-10 22:04:34 +02:00
parent 85ce2c0f33
commit 8c3c973d02
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
4 changed files with 117 additions and 76 deletions

View file

@ -240,39 +240,39 @@ QSize ChannelPostFilesDelegate::sizeHint(const QStyleOptionViewItem& option, con
}
}
class RsGxsChannelPostFilesProxyModel: public QSortFilterProxyModel
{
public:
RsGxsChannelPostFilesProxyModel(QObject *parent = NULL): QSortFilterProxyModel(parent) {}
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override
{
return left.data(RsGxsChannelPostFilesModel::SortRole) < right.data(RsGxsChannelPostFilesModel::SortRole) ;
}
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override
{
if(filter_list.empty())
return true;
QString name = sourceModel()->data(sourceModel()->index(source_row,RsGxsChannelPostFilesModel::COLUMN_FILES_NAME,source_parent)).toString();
for(auto& s:filter_list)
if(!name.contains(s,Qt::CaseInsensitive))
return false;
return true;
}
void setFilterList(const QStringList& str)
{
filter_list = str;
invalidateFilter();
}
private:
QStringList filter_list;
};
// class RsGxsChannelPostFilesProxyModel: public QSortFilterProxyModel
// {
// public:
// RsGxsChannelPostFilesProxyModel(QObject *parent = NULL): QSortFilterProxyModel(parent) {}
//
// bool lessThan(const QModelIndex& left, const QModelIndex& right) const override
// {
// return left.data(RsGxsChannelPostFilesModel::SortRole) < right.data(RsGxsChannelPostFilesModel::SortRole) ;
// }
//
// bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override
// {
// if(filter_list.empty())
// return true;
//
// QString name = sourceModel()->data(sourceModel()->index(source_row,RsGxsChannelPostFilesModel::COLUMN_FILES_NAME,source_parent)).toString();
//
// for(auto& s:filter_list)
// if(!name.contains(s,Qt::CaseInsensitive))
// return false;
//
// return true;
// }
//
// void setFilterList(const QStringList& str)
// {
// filter_list = str;
// invalidateFilter();
// }
//
// private:
// QStringList filter_list;
// };
/** Constructor */
GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupId &channelId, QWidget *parent) :
@ -285,24 +285,25 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
ui->postsTree->setModel(mChannelPostsModel = new RsGxsChannelPostsModel());
ui->postsTree->setItemDelegate(new ChannelPostDelegate());
mChannelPostFilesModel = new RsGxsChannelPostFilesModel(this);
mChannelPostFilesProxyModel = new RsGxsChannelPostFilesProxyModel(this);
mChannelPostFilesProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
mChannelPostFilesProxyModel->setSourceModel(mChannelPostFilesModel);
mChannelPostFilesProxyModel->setDynamicSortFilter(true);
ui->channelPostFiles_TV->setModel(mChannelPostFilesProxyModel);
ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel(this));
ui->channelPostFiles_TV->setItemDelegate(new ChannelPostFilesDelegate());
ui->channelPostFiles_TV->setPlaceholderText(tr("Post files"));
ui->channelPostFiles_TV->setPlaceholderText(tr("No files in this post, or no post selected"));
ui->channelPostFiles_TV->setSortingEnabled(true);
ui->channelPostFiles_TV->sortByColumn(0, Qt::AscendingOrder);
ui->channelFiles_TV->setPlaceholderText(tr("No files in the channel, or no channel selected"));
// mChannelPostFilesProxyModel = new RsGxsChannelPostFilesProxyModel(this);
// mChannelPostFilesProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
// mChannelPostFilesProxyModel->setSourceModel(mChannelPostFilesModel);
// mChannelPostFilesProxyModel->setDynamicSortFilter(true);
ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel());
ui->channelFiles_TV->setItemDelegate(new ChannelPostFilesDelegate());
ui->channelFiles_TV->setPlaceholderText(tr("No files in the channel, or no channel selected"));
ui->channelFiles_TV->setSortingEnabled(true);
ui->channelFiles_TV->sortByColumn(0, Qt::AscendingOrder);
//connect(ui->channelPostFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder)));
connect(ui->channelPostFiles_TV->header(),SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(sortColumn(int,Qt::SortOrder)));
connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails()));
connect(mChannelPostsModel,SIGNAL(channelLoaded()),this,SLOT(updateChannelFiles()));
@ -364,11 +365,11 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
}, mEventHandlerId, RsEventType::GXS_CHANNELS );
}
void GxsChannelPostsWidgetWithModel::sortColumn(int col,Qt::SortOrder so)
{
std::cerr << "Sorting!!"<< std::endl;
mChannelPostFilesProxyModel->sort(col,so);
}
//void GxsChannelPostsWidgetWithModel::sortColumn(int col,Qt::SortOrder so)
//{
// std::cerr << "Sorting!!"<< std::endl;
// mChannelPostFilesProxyModel->sort(col,so);
//}
void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s)
{
@ -469,7 +470,7 @@ void GxsChannelPostsWidgetWithModel::updateChannelFiles()
ui->channelFiles_TV->resizeColumnToContents(RsGxsChannelPostFilesModel::COLUMN_FILES_SIZE);
ui->channelFiles_TV->setAutoSelect(true);
mChannelPostFilesProxyModel->sort(0, Qt::AscendingOrder);
//mChannelPostFilesProxyModel->sort(0, Qt::AscendingOrder);
}
void GxsChannelPostsWidgetWithModel::updateGroupData()
@ -786,10 +787,10 @@ void GxsChannelPostsWidgetWithModel::filterChanged(QString s)
QStringList ql = s.split(' ',QString::SkipEmptyParts);
uint32_t count;
mChannelPostsModel->setFilter(ql,count);
mChannelFilesModel->setFilter(ql,count);
mChannelPostFilesProxyModel->setFilterKeyColumn(RsGxsChannelPostFilesModel::COLUMN_FILES_NAME);
mChannelPostFilesProxyModel->setFilterList(ql);
mChannelPostFilesProxyModel->setFilterRegExp(s) ;// triggers a re-display. s is actually not used.
//mChannelPostFilesProxyModel->setFilterKeyColumn(RsGxsChannelPostFilesModel::COLUMN_FILES_NAME);
//mChannelPostFilesProxyModel->setFilterRegExp(s) ;// triggers a re-display. s is actually not used.
}
#ifdef TODO