mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-26 07:16:11 -05:00
added sorting and filtering for files using a QPSortFilterProxyModel but it doesnt work yet
This commit is contained in:
parent
32050af8da
commit
c9019a7e99
@ -384,14 +384,6 @@ QVariant RsGxsForumModel::statusRole(const ForumModelPostEntry& fmpe,int column)
|
|||||||
return QVariant(fmpe.mMsgStatus);
|
return QVariant(fmpe.mMsgStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RsGxsForumModel::filterRole(const ForumModelPostEntry& fmpe,int /*column*/) const
|
|
||||||
{
|
|
||||||
if(!mFilteringEnabled || (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_CHILDREN_PASSES_FILTER))
|
|
||||||
return QVariant(FilterString);
|
|
||||||
|
|
||||||
return QVariant(QString());
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t RsGxsForumModel::recursUpdateFilterStatus(ForumModelIndex i,int column,const QStringList& strings)
|
uint32_t RsGxsForumModel::recursUpdateFilterStatus(ForumModelIndex i,int column,const QStringList& strings)
|
||||||
{
|
{
|
||||||
QString s ;
|
QString s ;
|
||||||
@ -609,8 +601,6 @@ QVariant RsGxsChannelPostFilesModel::displayRole(const RsGxsFile& fmpe,int col)
|
|||||||
return QVariant(tr("[Unknown]"));
|
return QVariant(tr("[Unknown]"));
|
||||||
}
|
}
|
||||||
case COLUMN_THREAD_MSGID: return QVariant();
|
case COLUMN_THREAD_MSGID: return QVariant();
|
||||||
#endif
|
|
||||||
#ifdef TODO
|
|
||||||
if (filterColumn == COLUMN_THREAD_CONTENT) {
|
if (filterColumn == COLUMN_THREAD_CONTENT) {
|
||||||
// need content for filter
|
// need content for filter
|
||||||
QTextDocument doc;
|
QTextDocument doc;
|
||||||
|
@ -105,6 +105,7 @@ public:
|
|||||||
QVariant toolTipRole (const RsGxsFile& fmpe, int col) const;
|
QVariant toolTipRole (const RsGxsFile& fmpe, int col) const;
|
||||||
QVariant userRole (const RsGxsFile& fmpe, int col) const;
|
QVariant userRole (const RsGxsFile& fmpe, int col) const;
|
||||||
QVariant sortRole (const RsGxsFile& fmpe, int col) const;
|
QVariant sortRole (const RsGxsFile& fmpe, int col) const;
|
||||||
|
QVariant filterRole (const RsGxsFile& fmpe, int col) const;
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
QVariant decorationRole(const ForumModelPostEntry& fmpe, int col) const;
|
QVariant decorationRole(const ForumModelPostEntry& fmpe, int col) const;
|
||||||
QVariant pinnedRole (const ForumModelPostEntry& fmpe, int col) const;
|
QVariant pinnedRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||||
@ -112,7 +113,6 @@ public:
|
|||||||
QVariant statusRole (const ForumModelPostEntry& fmpe, int col) const;
|
QVariant statusRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||||
QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const;
|
QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||||
QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const;
|
QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||||
QVariant filterRole (const ForumModelPostEntry& fmpe, int col) const;
|
|
||||||
QVariant textColorRole (const ForumModelPostEntry& fmpe, int col) const;
|
QVariant textColorRole (const ForumModelPostEntry& fmpe, int col) const;
|
||||||
QVariant backgroundRole(const ForumModelPostEntry& fmpe, int col) const;
|
QVariant backgroundRole(const ForumModelPostEntry& fmpe, int col) const;
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,8 +40,6 @@ Q_DECLARE_METATYPE(RsGxsChannelPost)
|
|||||||
|
|
||||||
std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
|
std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
|
||||||
|
|
||||||
const QString RsGxsChannelPostsModel::FilterString("filtered");
|
|
||||||
|
|
||||||
RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent)
|
RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent)
|
||||||
: QAbstractItemModel(parent), mTreeMode(TREE_MODE_PLAIN), mColumns(6)
|
: QAbstractItemModel(parent), mTreeMode(TREE_MODE_PLAIN), mColumns(6)
|
||||||
{
|
{
|
||||||
|
@ -101,8 +101,6 @@ public:
|
|||||||
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
|
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
|
||||||
QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const;
|
QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const;
|
||||||
|
|
||||||
static const QString FilterString ;
|
|
||||||
|
|
||||||
std::vector<std::pair<time_t,RsGxsMessageId> > getPostVersions(const RsGxsMessageId& mid) const;
|
std::vector<std::pair<time_t,RsGxsMessageId> > getPostVersions(const RsGxsMessageId& mid) const;
|
||||||
|
|
||||||
// This method will asynchroneously update the data
|
// This method will asynchroneously update the data
|
||||||
|
@ -240,6 +240,40 @@ 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;
|
||||||
|
};
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupId &channelId, QWidget *parent) :
|
GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupId &channelId, QWidget *parent) :
|
||||||
GxsMessageFrameWidget(rsGxsChannels, parent),
|
GxsMessageFrameWidget(rsGxsChannels, parent),
|
||||||
@ -251,14 +285,24 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
|
|||||||
ui->postsTree->setModel(mChannelPostsModel = new RsGxsChannelPostsModel());
|
ui->postsTree->setModel(mChannelPostsModel = new RsGxsChannelPostsModel());
|
||||||
ui->postsTree->setItemDelegate(new ChannelPostDelegate());
|
ui->postsTree->setItemDelegate(new ChannelPostDelegate());
|
||||||
|
|
||||||
ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel());
|
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->setItemDelegate(new ChannelPostFilesDelegate());
|
ui->channelPostFiles_TV->setItemDelegate(new ChannelPostFilesDelegate());
|
||||||
ui->channelPostFiles_TV->setPlaceholderText(tr("Post files"));
|
ui->channelPostFiles_TV->setPlaceholderText(tr("Post files"));
|
||||||
|
ui->channelPostFiles_TV->setSortingEnabled(true);
|
||||||
|
ui->channelPostFiles_TV->sortByColumn(0, Qt::AscendingOrder);
|
||||||
|
|
||||||
ui->channelFiles_TV->setPlaceholderText(tr("All files in the channel"));
|
ui->channelFiles_TV->setPlaceholderText(tr("All files in the channel"));
|
||||||
ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel());
|
ui->channelFiles_TV->setModel(mChannelFilesModel = new RsGxsChannelPostFilesModel());
|
||||||
ui->channelFiles_TV->setItemDelegate(new ChannelPostFilesDelegate());
|
ui->channelFiles_TV->setItemDelegate(new ChannelPostFilesDelegate());
|
||||||
|
|
||||||
|
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(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails()));
|
||||||
connect(mChannelPostsModel,SIGNAL(channelLoaded()),this,SLOT(updateChannelFiles()));
|
connect(mChannelPostsModel,SIGNAL(channelLoaded()),this,SLOT(updateChannelFiles()));
|
||||||
|
|
||||||
@ -277,6 +321,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
|
|||||||
ui->postButton->setText(tr("Add new post"));
|
ui->postButton->setText(tr("Add new post"));
|
||||||
|
|
||||||
/* add filter actions */
|
/* add filter actions */
|
||||||
|
ui->filterLineEdit->setPlaceholderText(tr("Search..."));
|
||||||
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
|
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged(QString)));
|
||||||
|
|
||||||
/* Initialize view button */
|
/* Initialize view button */
|
||||||
@ -335,6 +380,12 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
|
|||||||
connect(ui->postsTree,SIGNAL(sizeChanged(QSize)),this,SLOT(handlePostsTreeSizeChange(QSize)));
|
connect(ui->postsTree,SIGNAL(sizeChanged(QSize)),this,SLOT(handlePostsTreeSizeChange(QSize)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GxsChannelPostsWidgetWithModel::sortColumn(int col,Qt::SortOrder so)
|
||||||
|
{
|
||||||
|
std::cerr << "Sorting!!"<< std::endl;
|
||||||
|
mChannelPostFilesProxyModel->sort(col,so);
|
||||||
|
}
|
||||||
|
|
||||||
void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s)
|
void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s)
|
||||||
{
|
{
|
||||||
// adjustSize();
|
// adjustSize();
|
||||||
@ -749,6 +800,10 @@ void GxsChannelPostsWidgetWithModel::filterChanged(QString s)
|
|||||||
QStringList ql = s.split(' ',QString::SkipEmptyParts);
|
QStringList ql = s.split(' ',QString::SkipEmptyParts);
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
mChannelPostsModel->setFilter(ql,count);
|
mChannelPostsModel->setFilter(ql,count);
|
||||||
|
|
||||||
|
mChannelPostFilesProxyModel->setFilterKeyColumn(RsGxsChannelPostFilesModel::COLUMN_FILES_NAME);
|
||||||
|
mChannelPostFilesProxyModel->setFilterList(ql);
|
||||||
|
mChannelPostFilesProxyModel->setFilterRegExp(QRegExp()) ;// triggers a re-display.
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
|
@ -34,9 +34,11 @@ class GxsChannelPostsWidgetWithModel;
|
|||||||
|
|
||||||
class GxsChannelPostItem;
|
class GxsChannelPostItem;
|
||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
|
class QSortFilterProxyModel;
|
||||||
class FeedItem;
|
class FeedItem;
|
||||||
class RsGxsChannelPostsModel;
|
class RsGxsChannelPostsModel;
|
||||||
class RsGxsChannelPostFilesModel;
|
class RsGxsChannelPostFilesModel;
|
||||||
|
class RsGxsChannelPostFilesProxyModel;
|
||||||
|
|
||||||
class ChannelPostFilesDelegate: public QStyledItemDelegate
|
class ChannelPostFilesDelegate: public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
@ -137,6 +139,7 @@ private slots:
|
|||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
void handlePostsTreeSizeChange(QSize s);
|
void handlePostsTreeSizeChange(QSize s);
|
||||||
void updateChannelFiles();
|
void updateChannelFiles();
|
||||||
|
void sortColumn(int col,Qt::SortOrder so);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processSettings(bool load);
|
void processSettings(bool load);
|
||||||
@ -159,6 +162,7 @@ private:
|
|||||||
RsGxsChannelPostsModel *mChannelPostsModel;
|
RsGxsChannelPostsModel *mChannelPostsModel;
|
||||||
RsGxsChannelPostFilesModel *mChannelPostFilesModel;
|
RsGxsChannelPostFilesModel *mChannelPostFilesModel;
|
||||||
RsGxsChannelPostFilesModel *mChannelFilesModel;
|
RsGxsChannelPostFilesModel *mChannelFilesModel;
|
||||||
|
RsGxsChannelPostFilesProxyModel *mChannelPostFilesProxyModel ;
|
||||||
|
|
||||||
/* UI - from Designer */
|
/* UI - from Designer */
|
||||||
Ui::GxsChannelPostsWidgetWithModel *ui;
|
Ui::GxsChannelPostsWidgetWithModel *ui;
|
||||||
|
@ -161,7 +161,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="channel_TW">
|
<widget class="QTabWidget" name="channel_TW">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab_3">
|
<widget class="QWidget" name="tab_3">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user