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::FontRole: return fontRole(entry,index.column()) ;
case Qt::TextColorRole: return textColorRole(entry,index.column()) ;
case FilterRole: return filterRole(entry,index.column()) ;
case SortRole: return sortRole(entry,index.column()) ;
case OnlineRole: return onlineRole(entry,index.column()) ;
default:
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_PROFILE:
{
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]));
case ENTRY_TYPE_NODE: return QVariant(QBrush(mTextColorStatus[ onlineRole(fmpe,column).toBool() ?RS_STATUS_ONLINE:RS_STATUS_OFFLINE]));
default:
return QVariant();
}
@ -427,7 +410,7 @@ bool RsFriendListModel::passesFilter(const EntryIndex& e,int column) const
QString s ;
bool passes_strings = true ;
if(!mFilterStrings.empty())
if(e.type == ENTRY_TYPE_PROFILE && !mFilterStrings.empty())
{
switch(mFilterType)
{
@ -435,7 +418,6 @@ bool RsFriendListModel::passesFilter(const EntryIndex& e,int column) const
break;
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())
passes_strings = false;
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)
{
default:
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:
{
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)
if(mLocations[prof->child_node_indices[i]].node_info.state & RS_PEER_STATE_CONNECTED)
{
QFont font ;
font.setBold(true);
return QVariant(font);
}
return QVariant(true);
return QVariant();
}
@ -594,11 +584,25 @@ QVariant RsFriendListModel::fontRole(const EntryIndex& e, int col) const
if(!node)
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 ;
font.setBold(node->node_info.state & RS_PEER_STATE_CONNECTED);
font.setBold(b);
return QVariant(font);
}
else
return QVariant();
}
QVariant RsFriendListModel::displayRole(const EntryIndex& e, int col) const

View File

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

View File

@ -110,7 +110,10 @@ Q_DECLARE_METATYPE(ElidedLabel*)
class FriendListSortFilterProxyModel: public QSortFilterProxyModel
{
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
{
@ -119,6 +122,9 @@ public:
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 ;
}
@ -130,11 +136,15 @@ public:
void setSortingEnabled(bool b) { m_sortingEnabled = b ; }
void setSortByState(bool b) { m_sortByState = b ; }
void setHideOfflineNodes(bool b) { m_hideOfflineNodes = b ; }
bool hideOfflineNodes() const { return m_hideOfflineNodes ; }
private:
const QHeaderView *m_header ;
bool m_sortingEnabled;
bool m_sortByState;
bool m_hideOfflineNodes;
};
NewFriendList::NewFriendList(QWidget *parent) :
@ -142,7 +152,6 @@ NewFriendList::NewFriendList(QWidget *parent) :
ui(new Ui::NewFriendList()),
// mCompareRole(new RSTreeWidgetItemCompareRole),
mShowState(false),
mHideUnconnected(false),
groupsHasChanged(false)
{
ui->setupUi(this);
@ -253,7 +262,7 @@ void NewFriendList::headerContextMenuRequested(QPoint p)
displayMenu.addAction(ui->actionExportFriendlist);
displayMenu.addAction(ui->actionImportFriendlist);
ui->actionHideOfflineFriends->setChecked(mHideUnconnected);
ui->actionHideOfflineFriends->setChecked(mProxyModel->hideOfflineNodes());
ui->actionShowState->setChecked(mShowState);
ui->actionShowGroups->setChecked(mModel->getDisplayGroups());
@ -311,7 +320,7 @@ void NewFriendList::processSettings(bool load)
// restoreState would corrupt the internal sectionCount
// states
setHideUnconnected(Settings->value("hideUnconnected", mHideUnconnected).toBool());
setHideUnconnected(Settings->value("hideUnconnected", mProxyModel->hideOfflineNodes()).toBool());
setShowState(Settings->value("showState", mShowState).toBool());
setShowGroups(Settings->value("showGroups", mModel->getDisplayGroups()).toBool());
@ -339,7 +348,7 @@ void NewFriendList::processSettings(bool load)
// save settings
// states
Settings->setValue("hideUnconnected", mHideUnconnected);
Settings->setValue("hideUnconnected", mProxyModel->hideOfflineNodes());
Settings->setValue("showState", mShowState);
Settings->setValue("showGroups", mModel->getDisplayGroups());
@ -1385,9 +1394,8 @@ bool NewFriendList::getOrCreateGroup(const std::string& name, uint flag, RsNodeG
void NewFriendList::setHideUnconnected(bool hidden)
{
if (mHideUnconnected != hidden) {
mHideUnconnected = hidden;
}
mProxyModel->setHideOfflineNodes(hidden);
mProxyModel->setFilterRegExp(QRegExp(QString(RsFriendListModel::FilterString))) ;// triggers a re-display.
}
void NewFriendList::setColumnVisible(int col,bool visible)
@ -1436,15 +1444,21 @@ void NewFriendList::setShowGroups(bool show)
*/
void NewFriendList::filterItems(const QString &text)
{
int filterColumn = ui->filterLineEdit->currentFilter();
mFilterText = text;
QStringList lst = text.split(' ',QString::SkipEmptyParts);
int filterColumn = ui->filterLineEdit->currentFilter();
if(filterColumn == 0)
mModel->setFilter(RsFriendListModel::FILTER_TYPE_NAME,lst);
else if(filterColumn==1)
else //if(filterColumn==1)
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
bool mShowState;
bool mHideUnconnected;
QString mFilterText;
bool groupsHasChanged;
std::set<RsNodeGroupId> openGroups;