fixed sorting and filtering

This commit is contained in:
csoler 2019-08-12 12:49:04 +02:00
parent 0f4db73b0f
commit e1556e4fd5
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 73 additions and 60 deletions

View File

@ -370,8 +370,11 @@ QVariant RsFriendListModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole: return displayRole(entry,index.column()) ; case Qt::DisplayRole: return displayRole(entry,index.column()) ;
case Qt::FontRole: return fontRole(entry,index.column()) ; case Qt::FontRole: return fontRole(entry,index.column()) ;
case Qt::TextColorRole: return textColorRole(entry,index.column()) ; case Qt::TextColorRole: return textColorRole(entry,index.column()) ;
case FilterRole: return filterRole(entry,index.column()) ; case FilterRole: return filterRole(entry,index.column()) ;
case SortRole: return sortRole(entry,index.column()) ; case SortRole: return sortRole(entry,index.column()) ;
case OnlineRole: return onlineRole(entry,index.column()) ;
default: default:
return QVariant(); return QVariant();
} }
@ -388,27 +391,7 @@ QVariant RsFriendListModel::textColorRole(const EntryIndex& fmpe,int column) con
{ {
case ENTRY_TYPE_GROUP: return QVariant(QBrush(mTextColorGroup)); case ENTRY_TYPE_GROUP: return QVariant(QBrush(mTextColorGroup));
case ENTRY_TYPE_PROFILE: case ENTRY_TYPE_PROFILE:
{ case ENTRY_TYPE_NODE: return QVariant(QBrush(mTextColorStatus[ onlineRole(fmpe,column).toBool() ?RS_STATUS_ONLINE:RS_STATUS_OFFLINE]));
const HierarchicalProfileInformation *prof = getProfileInfo(fmpe);
if(!prof)
return QVariant();
StatusInfo info;
for(uint32_t i=0;i<prof->child_node_indices.size();++i)
{
RsPeerId id = mLocations[prof->child_node_indices[i]].node_info.id;
if(rsStatus->getStatus(mLocations[prof->child_node_indices[i]].node_info.id,info) && info.status == RS_STATUS_ONLINE)
return QVariant(QBrush(mTextColorStatus[info.status]));
}
return QVariant();
}
break;
case ENTRY_TYPE_NODE: return QVariant(QBrush(mTextColorStatus[getPeerOnlineStatus(fmpe)?RS_STATUS_ONLINE:RS_STATUS_OFFLINE]));
default: default:
return QVariant(); return QVariant();
} }
@ -427,7 +410,7 @@ bool RsFriendListModel::passesFilter(const EntryIndex& e,int column) const
QString s ; QString s ;
bool passes_strings = true ; bool passes_strings = true ;
if(!mFilterStrings.empty()) if(e.type == ENTRY_TYPE_PROFILE && !mFilterStrings.empty())
{ {
switch(mFilterType) switch(mFilterType)
{ {
@ -435,7 +418,6 @@ bool RsFriendListModel::passesFilter(const EntryIndex& e,int column) const
break; break;
case FILTER_TYPE_NAME: s = displayRole(e,COLUMN_THREAD_NAME).toString(); case FILTER_TYPE_NAME: s = displayRole(e,COLUMN_THREAD_NAME).toString();
//case FILTER_TYPE_NAME: s = sortRole(fmpe,COLUMN_THREAD_AUTHOR).toString();
if(s.isNull()) if(s.isNull())
passes_strings = false; passes_strings = false;
break; break;
@ -561,13 +543,26 @@ QVariant RsFriendListModel::sortRole(const EntryIndex& entry,int column) const
} }
} }
QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const QVariant RsFriendListModel::onlineRole(const EntryIndex& e, int col) const
{ {
std::cerr << " font role " << e.type << ", (" << (int)e.group_index << ","<< (int)e.profile_index << ","<< (int)e.node_index << ") col="<< col<<": " << std::endl;
switch(e.type) switch(e.type)
{ {
default:
case ENTRY_TYPE_GROUP: case ENTRY_TYPE_GROUP:
{
const HierarchicalGroupInformation& g(mGroups[e.group_index]);
for(uint32_t j=0;j<g.child_profile_indices.size();++j)
{
const HierarchicalProfileInformation& prof = mProfiles[g.child_profile_indices[j]];
for(uint32_t i=0;i<prof.child_node_indices.size();++i)
if(mLocations[prof.child_node_indices[i]].node_info.state & RS_PEER_STATE_CONNECTED)
return QVariant(true);
}
return QVariant(false);
}
case ENTRY_TYPE_PROFILE: case ENTRY_TYPE_PROFILE:
{ {
const HierarchicalProfileInformation *prof = getProfileInfo(e); const HierarchicalProfileInformation *prof = getProfileInfo(e);
@ -577,12 +572,7 @@ QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const
for(uint32_t i=0;i<prof->child_node_indices.size();++i) for(uint32_t i=0;i<prof->child_node_indices.size();++i)
if(mLocations[prof->child_node_indices[i]].node_info.state & RS_PEER_STATE_CONNECTED) if(mLocations[prof->child_node_indices[i]].node_info.state & RS_PEER_STATE_CONNECTED)
{ return QVariant(true);
QFont font ;
font.setBold(true);
return QVariant(font);
}
return QVariant(); return QVariant();
} }
@ -594,11 +584,25 @@ QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const
if(!node) if(!node)
return QVariant(); return QVariant();
return QVariant(bool(node->node_info.state & RS_PEER_STATE_CONNECTED));
}
}
QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const
{
std::cerr << " font role " << e.type << ", (" << (int)e.group_index << ","<< (int)e.profile_index << ","<< (int)e.node_index << ") col="<< col<<": " << std::endl;
bool b = onlineRole(e,col).toBool();
if(b && e.type == ENTRY_TYPE_NODE || e.type == ENTRY_TYPE_PROFILE)
{
QFont font ; QFont font ;
font.setBold(node->node_info.state & RS_PEER_STATE_CONNECTED); font.setBold(b);
return QVariant(font); return QVariant(font);
} }
else
return QVariant();
} }
QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const

View File

@ -72,9 +72,7 @@ public:
StatusRole = Qt::UserRole+2, StatusRole = Qt::UserRole+2,
UnreadRole = Qt::UserRole+3, UnreadRole = Qt::UserRole+3,
FilterRole = Qt::UserRole+4, FilterRole = Qt::UserRole+4,
MsgIdRole = Qt::UserRole+5, OnlineRole = Qt::UserRole+5
MsgFlagsRole = Qt::UserRole+6,
SrcIdRole = Qt::UserRole+7,
}; };
enum FilterType{ FILTER_TYPE_NONE = 0x00, enum FilterType{ FILTER_TYPE_NONE = 0x00,
@ -159,14 +157,14 @@ private:
QVariant displayRole (const EntryIndex &e, int col) const; QVariant displayRole (const EntryIndex &e, int col) const;
QVariant decorationRole(const EntryIndex& fmpe, int col) const; QVariant decorationRole(const EntryIndex& e, int col) const;
QVariant toolTipRole (const EntryIndex &fmpe, int col) const; QVariant toolTipRole (const EntryIndex& e, int col) const;
QVariant userRole (const EntryIndex& fmpe, int col) const; QVariant userRole (const EntryIndex& e, int col) const;
QVariant statusRole (const EntryIndex& fmpe, int col) const; QVariant statusRole (const EntryIndex& e, int col) const;
QVariant sortRole (const EntryIndex& fmpe, int col) const; QVariant sortRole (const EntryIndex& e, int col) const;
QVariant fontRole (const EntryIndex& fmpe, int col) const; QVariant fontRole (const EntryIndex& e, int col) const;
QVariant textColorRole (const EntryIndex& fmpe, int col) const; QVariant textColorRole (const EntryIndex& e, int col) const;
QVariant onlineRole (const EntryIndex& e, int col) const;
QVariant filterRole (const EntryIndex& e, int col) const; QVariant filterRole (const EntryIndex& e, int col) const;
/*! /*!

View File

@ -110,7 +110,10 @@ Q_DECLARE_METATYPE(ElidedLabel*)
class FriendListSortFilterProxyModel: public QSortFilterProxyModel class FriendListSortFilterProxyModel: public QSortFilterProxyModel
{ {
public: public:
FriendListSortFilterProxyModel(const QHeaderView *header,QObject *parent = NULL): QSortFilterProxyModel(parent),m_header(header) , m_sortingEnabled(false) {} FriendListSortFilterProxyModel(const QHeaderView *header,QObject *parent = NULL): QSortFilterProxyModel(parent),
m_header(header),
m_sortingEnabled(false),
m_hideOfflineNodes(false) {}
bool lessThan(const QModelIndex& left, const QModelIndex& right) const override bool lessThan(const QModelIndex& left, const QModelIndex& right) const override
{ {
@ -119,6 +122,9 @@ public:
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override
{ {
if(m_hideOfflineNodes && !sourceModel()->index(source_row,0,source_parent).data(RsFriendListModel::OnlineRole).toBool())
return false;
return sourceModel()->index(source_row,0,source_parent).data(RsFriendListModel::FilterRole).toString() == RsFriendListModel::FilterString ; return sourceModel()->index(source_row,0,source_parent).data(RsFriendListModel::FilterRole).toString() == RsFriendListModel::FilterString ;
} }
@ -130,11 +136,15 @@ public:
void setSortingEnabled(bool b) { m_sortingEnabled = b ; } void setSortingEnabled(bool b) { m_sortingEnabled = b ; }
void setSortByState(bool b) { m_sortByState = b ; } void setSortByState(bool b) { m_sortByState = b ; }
void setHideOfflineNodes(bool b) { m_hideOfflineNodes = b ; }
bool hideOfflineNodes() const { return m_hideOfflineNodes ; }
private: private:
const QHeaderView *m_header ; const QHeaderView *m_header ;
bool m_sortingEnabled; bool m_sortingEnabled;
bool m_sortByState; bool m_sortByState;
bool m_hideOfflineNodes;
}; };
NewFriendList::NewFriendList(QWidget *parent) : NewFriendList::NewFriendList(QWidget *parent) :
@ -142,7 +152,6 @@ NewFriendList::NewFriendList(QWidget *parent) :
ui(new Ui::NewFriendList()), ui(new Ui::NewFriendList()),
// mCompareRole(new RSTreeWidgetItemCompareRole), // mCompareRole(new RSTreeWidgetItemCompareRole),
mShowState(false), mShowState(false),
mHideUnconnected(false),
groupsHasChanged(false) groupsHasChanged(false)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -253,7 +262,7 @@ void NewFriendList::headerContextMenuRequested(QPoint p)
displayMenu.addAction(ui->actionExportFriendlist); displayMenu.addAction(ui->actionExportFriendlist);
displayMenu.addAction(ui->actionImportFriendlist); displayMenu.addAction(ui->actionImportFriendlist);
ui->actionHideOfflineFriends->setChecked(mHideUnconnected); ui->actionHideOfflineFriends->setChecked(mProxyModel->hideOfflineNodes());
ui->actionShowState->setChecked(mShowState); ui->actionShowState->setChecked(mShowState);
ui->actionShowGroups->setChecked(mModel->getDisplayGroups()); ui->actionShowGroups->setChecked(mModel->getDisplayGroups());
@ -311,7 +320,7 @@ void NewFriendList::processSettings(bool load)
// restoreState would corrupt the internal sectionCount // restoreState would corrupt the internal sectionCount
// states // states
setHideUnconnected(Settings->value("hideUnconnected", mHideUnconnected).toBool()); setHideUnconnected(Settings->value("hideUnconnected", mProxyModel->hideOfflineNodes()).toBool());
setShowState(Settings->value("showState", mShowState).toBool()); setShowState(Settings->value("showState", mShowState).toBool());
setShowGroups(Settings->value("showGroups", mModel->getDisplayGroups()).toBool()); setShowGroups(Settings->value("showGroups", mModel->getDisplayGroups()).toBool());
@ -339,7 +348,7 @@ void NewFriendList::processSettings(bool load)
// save settings // save settings
// states // states
Settings->setValue("hideUnconnected", mHideUnconnected); Settings->setValue("hideUnconnected", mProxyModel->hideOfflineNodes());
Settings->setValue("showState", mShowState); Settings->setValue("showState", mShowState);
Settings->setValue("showGroups", mModel->getDisplayGroups()); Settings->setValue("showGroups", mModel->getDisplayGroups());
@ -1385,9 +1394,8 @@ bool NewFriendList::getOrCreateGroup(const std::string& name, uint flag, RsNodeG
void NewFriendList::setHideUnconnected(bool hidden) void NewFriendList::setHideUnconnected(bool hidden)
{ {
if (mHideUnconnected != hidden) { mProxyModel->setHideOfflineNodes(hidden);
mHideUnconnected = hidden; mProxyModel->setFilterRegExp(QRegExp(QString(RsFriendListModel::FilterString))) ;// triggers a re-display.
}
} }
void NewFriendList::setColumnVisible(int col,bool visible) void NewFriendList::setColumnVisible(int col,bool visible)
@ -1436,15 +1444,21 @@ void NewFriendList::setShowGroups(bool show)
*/ */
void NewFriendList::filterItems(const QString &text) void NewFriendList::filterItems(const QString &text)
{ {
int filterColumn = ui->filterLineEdit->currentFilter();
mFilterText = text;
QStringList lst = text.split(' ',QString::SkipEmptyParts); QStringList lst = text.split(' ',QString::SkipEmptyParts);
int filterColumn = ui->filterLineEdit->currentFilter();
if(filterColumn == 0) if(filterColumn == 0)
mModel->setFilter(RsFriendListModel::FILTER_TYPE_NAME,lst); mModel->setFilter(RsFriendListModel::FILTER_TYPE_NAME,lst);
else if(filterColumn==1) else //if(filterColumn==1)
mModel->setFilter(RsFriendListModel::FILTER_TYPE_ID,lst); mModel->setFilter(RsFriendListModel::FILTER_TYPE_ID,lst);
// We do this in order to trigger a new filtering action in the proxy model.
mProxyModel->setFilterRegExp(QRegExp(QString(RsFriendListModel::FilterString))) ;
if(!lst.empty())
ui->peerTreeWidget->expandAll();
else
ui->peerTreeWidget->collapseAll();
} }
/** /**

View File

@ -109,9 +109,6 @@ private:
// Settings for peer list display // Settings for peer list display
bool mShowState; bool mShowState;
bool mHideUnconnected;
QString mFilterText;
bool groupsHasChanged; bool groupsHasChanged;
std::set<RsNodeGroupId> openGroups; std::set<RsNodeGroupId> openGroups;