Merge pull request #2239 from PhenomRetroShare/Add_GxsGroupTreeColumnHeaderShow

Add GroupTreeWidget show header action.
This commit is contained in:
csoler 2021-01-23 13:40:29 +01:00 committed by GitHub
commit 93e725e8aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 252 additions and 233 deletions

View File

@ -35,13 +35,6 @@
#include <stdint.h> #include <stdint.h>
#define COLUMN_NAME 0
#define COLUMN_UNREAD 1
#define COLUMN_POPULARITY 2
#define COLUMN_LAST_POST 3
#define COLUMN_COUNT 4
#define COLUMN_DATA COLUMN_NAME
#define ROLE_ID Qt::UserRole #define ROLE_ID Qt::UserRole
#define ROLE_NAME Qt::UserRole + 1 #define ROLE_NAME Qt::UserRole + 1
#define ROLE_DESCRIPTION Qt::UserRole + 2 #define ROLE_DESCRIPTION Qt::UserRole + 2
@ -74,7 +67,7 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
actionSortByUnread = NULL; actionSortByUnread = NULL;
compareRole = new RSTreeWidgetItemCompareRole; compareRole = new RSTreeWidgetItemCompareRole;
compareRole->setRole(COLUMN_DATA, ROLE_NAME); compareRole->setRole(GTW_COLUMN_DATA, ROLE_NAME);
/* Connect signals */ /* Connect signals */
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged())); connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterChanged()));
@ -94,32 +87,41 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
ui->treeWidget->setItemDelegate(itemDelegate); ui->treeWidget->setItemDelegate(itemDelegate);
/* Initialize tree widget */ /* Initialize tree widget */
ui->treeWidget->setColumnCount(COLUMN_COUNT); ui->treeWidget->setColumnCount(GTW_COLUMN_COUNT);
ui->treeWidget->enableColumnCustomize(true); ui->treeWidget->enableColumnCustomize(true);
ui->treeWidget->setColumnCustomizable(COLUMN_NAME, false); ui->treeWidget->setColumnCustomizable(GTW_COLUMN_NAME, false);
int S = QFontMetricsF(font()).height() ; int S = QFontMetricsF(font()).height() ;
int W = QFontMetricsF(font()).width("999") ; int W = QFontMetricsF(font()).width("_") ;
int D = QFontMetricsF(font()).width("9999-99-99[]") ; int D = QFontMetricsF(font()).width("9999-99-99[]") ;
QTreeWidgetItem *headerItem = ui->treeWidget->headerItem();
headerItem->setText(GTW_COLUMN_NAME, tr("Name"));
headerItem->setText(GTW_COLUMN_UNREAD, tr("Unread"));
headerItem->setText(GTW_COLUMN_POSTS, tr("F Posts"));
headerItem->setText(GTW_COLUMN_POPULARITY, tr("Popularity"));
headerItem->setText(GTW_COLUMN_LAST_POST, tr("Last Post"));
headerItem->setToolTip(GTW_COLUMN_NAME, tr("Name"));
headerItem->setToolTip(GTW_COLUMN_UNREAD, tr("Number of Unread message"));
headerItem->setToolTip(GTW_COLUMN_POSTS, tr("Friend's Posts"));
headerItem->setToolTip(GTW_COLUMN_POPULARITY, tr("Popularity"));
headerItem->setToolTip(GTW_COLUMN_LAST_POST, tr("Last Post"));
/* Set header resize modes and initial section sizes */ /* Set header resize modes and initial section sizes */
QHeaderView *header = ui->treeWidget->header (); QHeaderView *header = ui->treeWidget->header ();
header->setStretchLastSection(false); header->setStretchLastSection(false);
QHeaderView_setSectionResizeModeColumn(header, COLUMN_NAME, QHeaderView::Stretch); QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_NAME, QHeaderView::Stretch);
header->resizeSection(COLUMN_NAME, 10*S) ; header->resizeSection(GTW_COLUMN_NAME, 10*W) ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_UNREAD, QHeaderView::Fixed); QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_UNREAD, QHeaderView::Interactive);
header->resizeSection(COLUMN_UNREAD, W+4) ; header->resizeSection(GTW_COLUMN_UNREAD, 3*W+4) ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_POPULARITY, QHeaderView::Fixed); QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_POSTS, QHeaderView::Interactive);
header->resizeSection(COLUMN_POPULARITY, 2*S) ; header->resizeSection(GTW_COLUMN_POSTS, 3*W+4) ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_LAST_POST, QHeaderView::Fixed); header->setSectionHidden(GTW_COLUMN_POSTS, true);
header->resizeSection(COLUMN_LAST_POST, D+4) ; QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_POPULARITY, QHeaderView::Interactive);
header->setSectionHidden(COLUMN_LAST_POST, true); header->resizeSection(GTW_COLUMN_POPULARITY, 3*W) ;
QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_LAST_POST, QHeaderView::Interactive);
QTreeWidgetItem *headerItem = ui->treeWidget->headerItem(); header->resizeSection(GTW_COLUMN_LAST_POST, D+4) ;
headerItem->setText(COLUMN_NAME, tr("Name")); header->setSectionHidden(GTW_COLUMN_LAST_POST, true);
headerItem->setText(COLUMN_UNREAD, tr("Unread"));
headerItem->setText(COLUMN_POPULARITY, tr("Popularity"));
headerItem->setText(COLUMN_LAST_POST, tr("Last Post"));
/* add filter actions */ /* add filter actions */
ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_NAME_INDEX , tr("Search Title")); ui->filterLineEdit->addFilter(QIcon(), tr("Title"), FILTER_NAME_INDEX , tr("Search Title"));
@ -179,15 +181,18 @@ void GroupTreeWidget::processSettings(bool load)
} }
const int SORTBY_NAME = 1; const int SORTBY_NAME = 1;
const int SORTBY_POPULRITY = 2; const int SORTBY_POPULARITY = 2;
const int SORTBY_LASTPOST = 3; const int SORTBY_LASTPOST = 3;
const int SORTBY_POSTS = 4; const int SORTBY_POSTS = 4;
const int SORTBY_UNREAD = 5; const int SORTBY_UNREAD = 5;
ui->treeWidget->setSettingsVersion(1);//Change it when modifing column properties
ui->treeWidget->processSettings(load); ui->treeWidget->processSettings(load);
if (load) { if (load) {
// load Settings // load Settings
bool showHeader = Settings->value("GroupShowHeader", false).toBool();
actionShowHeader->setChecked(showHeader);
// state of order // state of order
bool ascSort = Settings->value("GroupAscSort", true).toBool(); bool ascSort = Settings->value("GroupAscSort", true).toBool();
@ -202,7 +207,7 @@ void GroupTreeWidget::processSettings(bool load)
actionSortByName->setChecked(true); actionSortByName->setChecked(true);
} }
break; break;
case SORTBY_POPULRITY: case SORTBY_POPULARITY:
if (actionSortByPopularity) { if (actionSortByPopularity) {
actionSortByPopularity->setChecked(true); actionSortByPopularity->setChecked(true);
} }
@ -225,6 +230,7 @@ void GroupTreeWidget::processSettings(bool load)
} }
} else { } else {
// save Settings // save Settings
Settings->setValue("GroupShowHeader", !(actionShowHeader && actionShowHeader->isChecked())); //False by default
// state of order // state of order
Settings->setValue("GroupAscSort", !(actionSortDescending && actionSortDescending->isChecked())); //True by default Settings->setValue("GroupAscSort", !(actionSortDescending && actionSortDescending->isChecked())); //True by default
@ -234,7 +240,7 @@ void GroupTreeWidget::processSettings(bool load)
if (actionSortByName && actionSortByName->isChecked()) { if (actionSortByName && actionSortByName->isChecked()) {
sortby = SORTBY_NAME; sortby = SORTBY_NAME;
} else if (actionSortByPopularity && actionSortByPopularity->isChecked()) { } else if (actionSortByPopularity && actionSortByPopularity->isChecked()) {
sortby = SORTBY_POPULRITY; sortby = SORTBY_POPULARITY;
} else if (actionSortByLastPost && actionSortByLastPost->isChecked()) { } else if (actionSortByLastPost && actionSortByLastPost->isChecked()) {
sortby = SORTBY_LASTPOST; sortby = SORTBY_LASTPOST;
} else if (actionSortByPosts && actionSortByPosts->isChecked()) { } else if (actionSortByPosts && actionSortByPosts->isChecked()) {
@ -251,6 +257,10 @@ void GroupTreeWidget::initDisplayMenu(QToolButton *toolButton)
displayMenu = new QMenu(); displayMenu = new QMenu();
QActionGroup *actionGroupAsc = new QActionGroup(displayMenu); QActionGroup *actionGroupAsc = new QActionGroup(displayMenu);
actionShowHeader = displayMenu->addAction(tr("Show Header"));
connect(actionShowHeader, SIGNAL(toggled(bool)), this, SLOT(showHeader(bool)));
actionShowHeader->setCheckable(true);
actionSortDescending = displayMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/images/sort_decrease.png"), tr("Sort Descending Order"), this, SLOT(sort())); actionSortDescending = displayMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/images/sort_decrease.png"), tr("Sort Descending Order"), this, SLOT(sort()));
actionSortDescending->setCheckable(true); actionSortDescending->setCheckable(true);
actionSortDescending->setActionGroup(actionGroupAsc); actionSortDescending->setActionGroup(actionGroupAsc);
@ -275,7 +285,7 @@ void GroupTreeWidget::initDisplayMenu(QToolButton *toolButton)
actionSortByLastPost->setCheckable(true); actionSortByLastPost->setCheckable(true);
actionSortByLastPost->setActionGroup(actionGroup); actionSortByLastPost->setActionGroup(actionGroup);
actionSortByPosts = displayMenu->addAction(QIcon(), tr("Sort by Number of Posts"), this, SLOT(sort())); actionSortByPosts = displayMenu->addAction(QIcon(), tr("Sort by Number of Friend's Posts"), this, SLOT(sort()));
actionSortByPosts->setCheckable(true); actionSortByPosts->setCheckable(true);
actionSortByPosts->setActionGroup(actionGroup); actionSortByPosts->setActionGroup(actionGroup);
@ -293,11 +303,11 @@ void GroupTreeWidget::updateColors()
while ((item = *itemIterator) != NULL) { while ((item = *itemIterator) != NULL) {
++itemIterator; ++itemIterator;
int color = item->data(COLUMN_DATA, ROLE_COLOR).toInt(); int color = item->data(GTW_COLUMN_DATA, ROLE_COLOR).toInt();
if (color >= 0) { if (color >= 0) {
item->setData(COLUMN_NAME, Qt::TextColorRole, mTextColor[color]); item->setData(GTW_COLUMN_NAME, Qt::TextColorRole, mTextColor[color]);
} else { } else {
item->setData(COLUMN_NAME, Qt::TextColorRole, QVariant()); item->setData(GTW_COLUMN_NAME, Qt::TextColorRole, QVariant());
} }
} }
@ -315,7 +325,7 @@ void GroupTreeWidget::currentItemChanged(QTreeWidgetItem *current, QTreeWidgetIt
QString id; QString id;
if (current) { if (current) {
id = current->data(COLUMN_DATA, ROLE_ID).toString(); id = current->data(GTW_COLUMN_DATA, ROLE_ID).toString();
} }
emit treeCurrentItemChanged(id); emit treeCurrentItemChanged(id);
@ -328,7 +338,7 @@ void GroupTreeWidget::itemActivated(QTreeWidgetItem *item, int column)
QString id; QString id;
if (item) { if (item) {
id = item->data(COLUMN_DATA, ROLE_ID).toString(); id = item->data(GTW_COLUMN_DATA, ROLE_ID).toString();
} }
emit treeItemActivated(id); emit treeItemActivated(id);
@ -343,18 +353,18 @@ QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIc
ui->treeWidget->style()->unpolish(ui->treeWidget); ui->treeWidget->style()->unpolish(ui->treeWidget);
ui->treeWidget->style()->polish(ui->treeWidget); ui->treeWidget->style()->polish(ui->treeWidget);
item->setText(COLUMN_NAME, name); item->setText(GTW_COLUMN_NAME, name);
item->setData(COLUMN_DATA, ROLE_NAME, name); item->setData(GTW_COLUMN_DATA, ROLE_NAME, name);
font = item->font(COLUMN_NAME); font = item->font(GTW_COLUMN_NAME);
font.setBold(true); font.setBold(true);
item->setFont(COLUMN_NAME, font); item->setFont(GTW_COLUMN_NAME, font);
item->setIcon(COLUMN_NAME, icon); item->setIcon(GTW_COLUMN_NAME, icon);
int S = QFontMetricsF(font).height(); int S = QFontMetricsF(font).height();
item->setSizeHint(COLUMN_NAME, QSize(S*1.9, S*1.9)); item->setSizeHint(GTW_COLUMN_NAME, QSize(S*1.9, S*1.9));
item->setData(COLUMN_NAME, Qt::TextColorRole, textColorCategory()); item->setData(GTW_COLUMN_NAME, Qt::TextColorRole, textColorCategory());
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_CATEGORY); item->setData(GTW_COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_CATEGORY);
item->setExpanded(expand); item->setExpanded(expand);
@ -370,8 +380,8 @@ QTreeWidgetItem *GroupTreeWidget::addSearchItem(const QString& search_string, ui
{ {
QTreeWidgetItem *item = addCategoryItem(search_string,icon,true); QTreeWidgetItem *item = addCategoryItem(search_string,icon,true);
item->setData(COLUMN_DATA,ROLE_SEARCH_STRING,search_string) ; item->setData(GTW_COLUMN_DATA,ROLE_SEARCH_STRING,search_string) ;
item->setData(COLUMN_DATA,ROLE_REQUEST_ID ,id) ; item->setData(GTW_COLUMN_DATA,ROLE_REQUEST_ID ,id) ;
return item; return item;
} }
@ -392,7 +402,7 @@ bool GroupTreeWidget::isSearchRequestResult(QPoint &point,QString& group_id,uint
if(parent == NULL) if(parent == NULL)
return false ; return false ;
search_req_id = parent->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt(); search_req_id = parent->data(GTW_COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
group_id = itemId(item) ; group_id = itemId(item) ;
return search_req_id > 0; return search_req_id > 0;
@ -405,7 +415,7 @@ bool GroupTreeWidget::isSearchRequestResultItem(QTreeWidgetItem *item,QString& g
if(parent == NULL) if(parent == NULL)
return false ; return false ;
search_req_id = parent->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt(); search_req_id = parent->data(GTW_COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
group_id = itemId(item) ; group_id = itemId(item) ;
return search_req_id > 0; return search_req_id > 0;
@ -417,7 +427,7 @@ bool GroupTreeWidget::isSearchRequestItem(QPoint &point,uint32_t& search_req_id)
if (item == NULL) if (item == NULL)
return false; return false;
search_req_id = item->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt(); search_req_id = item->data(GTW_COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
return search_req_id > 0; return search_req_id > 0;
} }
@ -428,7 +438,7 @@ QString GroupTreeWidget::itemId(QTreeWidgetItem *item)
return ""; return "";
} }
return item->data(COLUMN_DATA, ROLE_ID).toString(); return item->data(GTW_COLUMN_DATA, ROLE_ID).toString();
} }
QString GroupTreeWidget::itemIdAt(QPoint &point) QString GroupTreeWidget::itemIdAt(QPoint &point)
@ -438,7 +448,7 @@ QString GroupTreeWidget::itemIdAt(QPoint &point)
return ""; return "";
} }
return item->data(COLUMN_DATA, ROLE_ID).toString(); return item->data(GTW_COLUMN_DATA, ROLE_ID).toString();
} }
void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<GroupItemInfo> &itemList) void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<GroupItemInfo> &itemList)
@ -460,7 +470,7 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
int childCount = categoryItem->childCount(); int childCount = categoryItem->childCount();
for (int child = 0; child < childCount; ++child) { for (int child = 0; child < childCount; ++child) {
QTreeWidgetItem *childItem = categoryItem->child(child); QTreeWidgetItem *childItem = categoryItem->child(child);
if (childItem->data(COLUMN_DATA, ROLE_ID).toString() == itemInfo.id) { if (childItem->data(GTW_COLUMN_DATA, ROLE_ID).toString() == itemInfo.id) {
/* Found child */ /* Found child */
item = childItem; item = childItem;
break; break;
@ -469,45 +479,46 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
if (item == NULL) { if (item == NULL) {
item = new RSTreeWidgetItem(compareRole); item = new RSTreeWidgetItem(compareRole);
item->setData(COLUMN_DATA, ROLE_ID, itemInfo.id); item->setData(GTW_COLUMN_DATA, ROLE_ID, itemInfo.id);
categoryItem->addChild(item); categoryItem->addChild(item);
} }
item->setText(COLUMN_NAME, itemInfo.name); item->setText(GTW_COLUMN_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name); item->setData(GTW_COLUMN_DATA, ROLE_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description); item->setData(GTW_COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description);
// Add children for context strings. This happens in the search. // Add children for context strings. This happens in the search.
while(nullptr != item->takeChild(0)); while(nullptr != item->takeChild(0));
for(auto str:itemInfo.context_strings) for(auto& str:itemInfo.context_strings)
if(!str.empty()) if(!str.empty())
{ {
QTreeWidgetItem *it = new QTreeWidgetItem(QStringList(QString::fromUtf8(str.c_str()))); QTreeWidgetItem *wit = new QTreeWidgetItem(QStringList(QString::fromUtf8(str.c_str())));
it->setData(COLUMN_DATA,ROLE_ID,itemInfo.id); wit->setData(GTW_COLUMN_DATA,ROLE_ID,itemInfo.id);
item->addChild(it); item->addChild(wit);
} }
/* Set last post */ /* Set last post */
qlonglong lastPost = itemInfo.lastpost.toTime_t(); qlonglong lastPost = itemInfo.lastpost.toTime_t();
item->setData(COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting item->setData(GTW_COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting
if(itemInfo.lastpost == QDateTime::fromTime_t(0)) if(itemInfo.lastpost == QDateTime::fromTime_t(0))
item->setText(COLUMN_LAST_POST, tr("Never")); item->setText(GTW_COLUMN_LAST_POST, tr("Never"));
else else
item->setText(COLUMN_LAST_POST, itemInfo.lastpost.toString(Qt::ISODate).replace("T"," ")); item->setText(GTW_COLUMN_LAST_POST, itemInfo.lastpost.toString(Qt::ISODate).replace("T"," "));
/* Set visible posts */ /* Set visible posts */
item->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting item->setText(GTW_COLUMN_POSTS, QString::number(itemInfo.max_visible_posts));
item->setData(GTW_COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting
/* Set icon */ /* Set icon */
item->setIcon(COLUMN_NAME, itemInfo.icon); item->setIcon(GTW_COLUMN_NAME, itemInfo.icon);
/* Set popularity */ /* Set popularity */
QString tooltip = PopularityDefs::tooltip(itemInfo.popularity); QString tooltip = PopularityDefs::tooltip(itemInfo.popularity);
item->setIcon(COLUMN_POPULARITY, PopularityDefs::icon(itemInfo.popularity)); item->setIcon(GTW_COLUMN_POPULARITY, PopularityDefs::icon(itemInfo.popularity));
item->setData(COLUMN_DATA, ROLE_POPULARITY, -itemInfo.popularity); // negative for correct sorting item->setData(GTW_COLUMN_DATA, ROLE_POPULARITY, -itemInfo.popularity); // negative for correct sorting
/* Set tooltip */ /* Set tooltip */
if (itemInfo.adminKey) if (itemInfo.adminKey)
@ -530,26 +541,27 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
desc.replace("\t"," "); desc.replace("\t"," ");
if(itemInfo.description.length() > 30) if(itemInfo.description.length() > 30)
desc += "..."; desc += "";
tooltip += "\n" + tr("Description") + ": " + desc; tooltip += "\n" + tr("Description") + ": " + desc;
tooltip += "\n" + tr("Id") + ": " + itemInfo.id; tooltip += "\n" + tr("Id") + ": " + itemInfo.id;
item->setToolTip(COLUMN_NAME, tooltip); item->setToolTip(GTW_COLUMN_NAME, tooltip);
item->setToolTip(COLUMN_UNREAD, tooltip); item->setToolTip(GTW_COLUMN_UNREAD, tooltip);
item->setToolTip(COLUMN_POPULARITY, tooltip); item->setToolTip(GTW_COLUMN_POSTS, tooltip);
item->setToolTip(GTW_COLUMN_POPULARITY, tooltip);
item->setData(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS, itemInfo.subscribeFlags); item->setData(GTW_COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS, itemInfo.subscribeFlags);
/* Set color */ /* Set color */
if (itemInfo.publishKey) { if (itemInfo.publishKey) {
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_PRIVATEKEY); item->setData(GTW_COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_PRIVATEKEY);
item->setData(COLUMN_NAME, Qt::ForegroundRole, QBrush(textColorPrivateKey())); item->setData(GTW_COLUMN_NAME, Qt::ForegroundRole, QBrush(textColorPrivateKey()));
} else { } else {
// Let StyleSheet color // Let StyleSheet color
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_STANDARD); item->setData(GTW_COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_STANDARD);
item->setData(COLUMN_NAME, Qt::BackgroundRole, QVariant()); item->setData(GTW_COLUMN_NAME, Qt::BackgroundRole, QVariant());
} }
/* Calculate score */ /* Calculate score */
@ -560,7 +572,7 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
int child = 0; int child = 0;
int childCount = categoryItem->childCount(); int childCount = categoryItem->childCount();
while (child < childCount) { while (child < childCount) {
QString id = categoryItem->child(child)->data(COLUMN_DATA, ROLE_ID).toString(); QString id = categoryItem->child(child)->data(GTW_COLUMN_DATA, ROLE_ID).toString();
for (it = itemList.begin(); it != itemList.end(); ++it) { for (it = itemList.begin(); it != itemList.end(); ++it) {
if (it->id == id) { if (it->id == id) {
@ -585,18 +597,18 @@ void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount)
return; return;
} }
QFont font = item->font(COLUMN_NAME); QFont font = item->font(GTW_COLUMN_NAME);
if (unreadCount) { if (unreadCount) {
item->setData(COLUMN_DATA, ROLE_UNREAD, unreadCount); item->setData(GTW_COLUMN_DATA, ROLE_UNREAD, unreadCount);
item->setText(COLUMN_UNREAD, QString::number(unreadCount)); item->setText(GTW_COLUMN_UNREAD, QString::number(unreadCount));
font.setBold(true); font.setBold(true);
} else { } else {
item->setText(COLUMN_UNREAD, ""); item->setText(GTW_COLUMN_UNREAD, "");
font.setBold(false); font.setBold(false);
} }
item->setFont(COLUMN_NAME, font); item->setFont(GTW_COLUMN_NAME, font);
} }
QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id) QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id)
@ -614,7 +626,7 @@ QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id)
if (item->parent() == NULL) { if (item->parent() == NULL) {
continue; continue;
} }
if (item->data(COLUMN_DATA, ROLE_ID).toString() == id) { if (item->data(GTW_COLUMN_DATA, ROLE_ID).toString() == id) {
return item; return item;
} }
} }
@ -642,7 +654,7 @@ bool GroupTreeWidget::setWaiting(const QString &id, bool wait)
return false; return false;
} }
item->setData(COLUMN_NAME, Qt::StatusTipRole, wait ? "waiting" : ""); item->setData(GTW_COLUMN_NAME, Qt::StatusTipRole, wait ? "waiting" : "");
return true; return true;
} }
@ -651,14 +663,14 @@ RSTreeWidget *GroupTreeWidget::treeWidget()
return ui->treeWidget; return ui->treeWidget;
} }
bool GroupTreeWidget::getGroupName(QString id, QString& name) bool GroupTreeWidget::getGroupName(const QString& id, QString& name)
{ {
QTreeWidgetItem *item = getItemFromId(id); QTreeWidgetItem *item = getItemFromId(id);
if (item == NULL) { if (item == NULL) {
return false; return false;
} }
name = item->data(COLUMN_DATA, ROLE_NAME).toString(); name = item->data(GTW_COLUMN_DATA, ROLE_NAME).toString();
return true; return true;
} }
@ -670,7 +682,7 @@ int GroupTreeWidget::subscribeFlags(const QString &id)
return 0; return 0;
} }
return item->data(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS).toInt(); return item->data(GTW_COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS).toInt();
} }
void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filterText) void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filterText)
@ -686,10 +698,10 @@ void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filte
switch (ui->filterLineEdit->currentFilter()) { switch (ui->filterLineEdit->currentFilter()) {
case FILTER_NAME_INDEX: case FILTER_NAME_INDEX:
scoreString = item->data(COLUMN_DATA, ROLE_NAME).toString(); scoreString = item->data(GTW_COLUMN_DATA, ROLE_NAME).toString();
break; break;
case FILTER_DESC_INDEX: case FILTER_DESC_INDEX:
scoreString = item->data(COLUMN_DATA, ROLE_DESCRIPTION).toString(); scoreString = item->data(GTW_COLUMN_DATA, ROLE_DESCRIPTION).toString();
break; break;
} }
@ -702,7 +714,7 @@ void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filte
} }
} }
item->setData(COLUMN_DATA, ROLE_SEARCH_SCORE, -score); // negative for correct sorting item->setData(GTW_COLUMN_DATA, ROLE_SEARCH_SCORE, -score); // negative for correct sorting
return; return;
} }
@ -713,7 +725,7 @@ void GroupTreeWidget::calculateScore(QTreeWidgetItem *item, const QString &filte
while ((tmpItem = *itemIterator) != NULL) { while ((tmpItem = *itemIterator) != NULL) {
++itemIterator; ++itemIterator;
if (tmpItem->data(COLUMN_DATA, ROLE_ID).toString().isEmpty()) { if (tmpItem->data(GTW_COLUMN_DATA, ROLE_ID).toString().isEmpty()) {
continue; continue;
} }
@ -734,26 +746,26 @@ void GroupTreeWidget::resort(QTreeWidgetItem *categoryItem)
Qt::SortOrder order = (actionSortAscending == NULL || actionSortAscending->isChecked()) ? Qt::AscendingOrder : Qt::DescendingOrder; Qt::SortOrder order = (actionSortAscending == NULL || actionSortAscending->isChecked()) ? Qt::AscendingOrder : Qt::DescendingOrder;
if (ui->filterLineEdit->text().isEmpty() == false) { if (ui->filterLineEdit->text().isEmpty() == false) {
compareRole->setRole(COLUMN_DATA, ROLE_SEARCH_SCORE); compareRole->setRole(GTW_COLUMN_DATA, ROLE_SEARCH_SCORE);
compareRole->addRole(COLUMN_DATA, ROLE_LASTPOST); compareRole->addRole(GTW_COLUMN_DATA, ROLE_LASTPOST);
} else if (actionSortByName && actionSortByName->isChecked()) { } else if (actionSortByName && actionSortByName->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_NAME); compareRole->setRole(GTW_COLUMN_DATA, ROLE_NAME);
} else if (actionSortByPopularity && actionSortByPopularity->isChecked()) { } else if (actionSortByPopularity && actionSortByPopularity->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_POPULARITY); compareRole->setRole(GTW_COLUMN_DATA, ROLE_POPULARITY);
} else if (actionSortByLastPost && actionSortByLastPost->isChecked()) { } else if (actionSortByLastPost && actionSortByLastPost->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_LASTPOST); compareRole->setRole(GTW_COLUMN_DATA, ROLE_LASTPOST);
} else if (actionSortByPosts && actionSortByPosts->isChecked()) { } else if (actionSortByPosts && actionSortByPosts->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_POSTS); compareRole->setRole(GTW_COLUMN_DATA, ROLE_POSTS);
} else if (actionSortByUnread && actionSortByUnread->isChecked()) { } else if (actionSortByUnread && actionSortByUnread->isChecked()) {
compareRole->setRole(COLUMN_DATA, ROLE_UNREAD); compareRole->setRole(GTW_COLUMN_DATA, ROLE_UNREAD);
} }
if (categoryItem) { if (categoryItem) {
categoryItem->sortChildren(COLUMN_DATA, order); categoryItem->sortChildren(GTW_COLUMN_DATA, order);
} else { } else {
int count = ui->treeWidget->topLevelItemCount(); int count = ui->treeWidget->topLevelItemCount();
for (int child = 0; child < count; ++child) { for (int child = 0; child < count; ++child) {
ui->treeWidget->topLevelItem(child)->sortChildren(COLUMN_DATA, order); ui->treeWidget->topLevelItem(child)->sortChildren(GTW_COLUMN_DATA, order);
} }
} }
} }
@ -765,6 +777,11 @@ void GroupTreeWidget::distantSearch()
ui->distantSearchLineEdit->clear(); ui->distantSearchLineEdit->clear();
} }
void GroupTreeWidget::showHeader(bool toShow)
{
ui->treeWidget->header()->setVisible(toShow);
}
void GroupTreeWidget::sort() void GroupTreeWidget::sort()
{ {
resort(NULL); resort(NULL);

View File

@ -36,6 +36,14 @@ class RSTreeWidget;
#define GROUPTREEWIDGET_COLOR_PRIVATEKEY 1 #define GROUPTREEWIDGET_COLOR_PRIVATEKEY 1
#define GROUPTREEWIDGET_COLOR_COUNT 2 #define GROUPTREEWIDGET_COLOR_COUNT 2
#define GTW_COLUMN_NAME 0
#define GTW_COLUMN_UNREAD 1
#define GTW_COLUMN_POSTS 2
#define GTW_COLUMN_POPULARITY 3
#define GTW_COLUMN_LAST_POST 4
#define GTW_COLUMN_COUNT 5
#define GTW_COLUMN_DATA GTW_COLUMN_NAME
namespace Ui { namespace Ui {
class GroupTreeWidget; class GroupTreeWidget;
} }
@ -112,7 +120,7 @@ public:
void setTextColorCategory(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_CATEGORY] = color; } void setTextColorCategory(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_CATEGORY] = color; }
void setTextColorPrivateKey(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_PRIVATEKEY] = color; } void setTextColorPrivateKey(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_PRIVATEKEY] = color; }
bool getGroupName(QString id, QString& name); bool getGroupName(const QString& id, QString& name);
int subscribeFlags(const QString &id); int subscribeFlags(const QString &id);
@ -132,6 +140,7 @@ private slots:
void filterChanged(); void filterChanged();
void distantSearch(); void distantSearch();
void showHeader(bool toShow);
void sort(); void sort();
private: private:
@ -143,6 +152,7 @@ private:
private: private:
QMenu *displayMenu; QMenu *displayMenu;
QAction *actionShowHeader;
QAction *actionSortAscending; QAction *actionSortAscending;
QAction *actionSortDescending; QAction *actionSortDescending;
QAction *actionSortByName; QAction *actionSortByName;

View File

@ -324,7 +324,7 @@ void GxsGroupFrameDialog::updateSearchResults(const TurtleRequestId& sid)
for(auto it3(group_infos.begin());it3!=group_infos.end();++it3) for(auto it3(group_infos.begin());it3!=group_infos.end();++it3)
{ {
std::cerr << " adding group " << it3->first << " " << it3->second.mGroupId << " \"" << it3->second.mGroupName << "\"" << std::endl; std::cerr << " adding group " << it3->first << " " << it3->second.mGroupId << " \"" << it3->second.mGroupName << "\"" << std::endl;
for(auto s:it3->second.mSearchContexts) for(auto& s:it3->second.mSearchContexts)
std::cerr << " Context string \"" << s << "\"" << std::endl; std::cerr << " Context string \"" << s << "\"" << std::endl;
GroupItemInfo i; GroupItemInfo i;
@ -408,37 +408,29 @@ uint32_t GxsGroupFrameDialog::checkDelay(uint32_t time_in_secs)
} }
void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point) void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
{
// First separately handle the case of search top level items
TurtleRequestId search_request_id = 0 ;
if(ui->groupTreeWidget->isSearchRequestItem(point,search_request_id))
{ {
QMenu contextMnu(this); QMenu contextMnu(this);
// First separately handle the case of search top level items
TurtleRequestId search_request_id = 0 ;
QString group_id_s;
if(ui->groupTreeWidget->isSearchRequestItem(point,search_request_id))
{
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DELETE), tr("Remove this search"), this, SLOT(removeCurrentSearch()))->setData(search_request_id); contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DELETE), tr("Remove this search"), this, SLOT(removeCurrentSearch()))->setData(search_request_id);
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DELETE), tr("Remove all searches"), this, SLOT(removeAllSearches())); contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_DELETE), tr("Remove all searches"), this, SLOT(removeAllSearches()));
contextMnu.exec(QCursor::pos());
return ;
} }
// Then check whether we have a searched item, or a normal group // Then check whether we have a searched item, or a normal group
else if(ui->groupTreeWidget->isSearchRequestResult(point,group_id_s,search_request_id))
QString group_id_s ;
if(ui->groupTreeWidget->isSearchRequestResult(point,group_id_s,search_request_id))
{ {
QMenu contextMnu(this);
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_RETRIEVE), tr("Request data"), this, SLOT(distantRequestGroupData()))->setData(group_id_s); contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_RETRIEVE), tr("Request data"), this, SLOT(distantRequestGroupData()))->setData(group_id_s);
contextMnu.exec(QCursor::pos());
return ;
} }
else // Group Id
{
QString id = ui->groupTreeWidget->itemIdAt(point); QString id = ui->groupTreeWidget->itemIdAt(point);
if (id.isEmpty()) return; if (!id.isEmpty())
{
mGroupId = RsGxsGroupId(id.toStdString()); mGroupId = RsGxsGroupId(id.toStdString());
int subscribeFlags = ui->groupTreeWidget->subscribeFlags(QString::fromStdString(mGroupId.toStdString())); int subscribeFlags = ui->groupTreeWidget->subscribeFlags(QString::fromStdString(mGroupId.toStdString()));
@ -446,7 +438,6 @@ void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
bool isPublisher = IS_GROUP_PUBLISHER(subscribeFlags); bool isPublisher = IS_GROUP_PUBLISHER(subscribeFlags);
bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags); bool isSubscribed = IS_GROUP_SUBSCRIBED(subscribeFlags);
QMenu contextMnu(this);
QAction *action; QAction *action;
action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_TABNEW), tr("Open in new tab"), this, SLOT(openInNewTab())); action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_TABNEW), tr("Open in new tab"), this, SLOT(openInNewTab()));
@ -523,7 +514,8 @@ void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
contextMnu.addSeparator(); contextMnu.addSeparator();
contextMnu.addActions(actions); contextMnu.addActions(actions);
} }
}
}
//Add Standard Menu //Add Standard Menu
ui->groupTreeWidget->treeWidget()->createStandardContextMenu(&contextMnu); ui->groupTreeWidget->treeWidget()->createStandardContextMenu(&contextMnu);
@ -731,7 +723,7 @@ void GxsGroupFrameDialog::loadComment(const RsGxsGroupId &grpId, const QVector<R
if (title.length() > MAX_COMMENT_TITLE) if (title.length() > MAX_COMMENT_TITLE)
{ {
comments.truncate(MAX_COMMENT_TITLE - 3); comments.truncate(MAX_COMMENT_TITLE - 3);
comments += "..."; comments += "";
} }
commentDialog = new GxsCommentDialog(this,RsGxsId(), mInterface->getTokenService(), commentService); commentDialog = new GxsCommentDialog(this,RsGxsId(), mInterface->getTokenService(), commentService);
@ -1025,13 +1017,13 @@ void GxsGroupFrameDialog::insertGroupsData(const std::list<RsGxsGenericGroupData
/* now we can add them in as a tree! */ /* now we can add them in as a tree! */
ui->groupTreeWidget->fillGroupItems(mYourGroups, adminList); ui->groupTreeWidget->fillGroupItems(mYourGroups, adminList);
mYourGroups->setText(2, QString::number(mYourGroups->childCount())); mYourGroups->setText(GTW_COLUMN_POPULARITY, QString::number(mYourGroups->childCount()));
ui->groupTreeWidget->fillGroupItems(mSubscribedGroups, subList); ui->groupTreeWidget->fillGroupItems(mSubscribedGroups, subList);
mSubscribedGroups->setText(2, QString::number(mSubscribedGroups->childCount())); // 1 COLUMN_UNREAD 2 COLUMN_POPULARITY mSubscribedGroups->setText(GTW_COLUMN_POPULARITY, QString::number(mSubscribedGroups->childCount())); // 1 COLUMN_UNREAD 2 COLUMN_POPULARITY
ui->groupTreeWidget->fillGroupItems(mPopularGroups, popList); ui->groupTreeWidget->fillGroupItems(mPopularGroups, popList);
mPopularGroups->setText(2, QString::number(mPopularGroups->childCount())); mPopularGroups->setText(GTW_COLUMN_POPULARITY, QString::number(mPopularGroups->childCount()));
ui->groupTreeWidget->fillGroupItems(mOtherGroups, otherList); ui->groupTreeWidget->fillGroupItems(mOtherGroups, otherList);
mOtherGroups->setText(2, QString::number(mOtherGroups->childCount())); mOtherGroups->setText(GTW_COLUMN_POPULARITY, QString::number(mOtherGroups->childCount()));
mInFill = false; mInFill = false;
@ -1190,7 +1182,7 @@ void GxsGroupFrameDialog::getServiceStatistics(GxsServiceStatistic& stats) const
{ {
stats = GxsServiceStatistic(); // clears everything stats = GxsServiceStatistic(); // clears everything
for(auto it: mCachedGroupStats) for(auto& it: mCachedGroupStats)
{ {
const GxsGroupStatistic& s(it.second); const GxsGroupStatistic& s(it.second);