using GxsIdRSTreeWidgetItem to display circle members

This commit is contained in:
csoler 2020-02-11 22:14:55 +01:00
parent 4c54d9d633
commit dc0b8c491c
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
5 changed files with 51 additions and 32 deletions

View file

@ -37,6 +37,7 @@
#include "gui/common/UIStateHelper.h" #include "gui/common/UIStateHelper.h"
#include "gui/common/UserNotify.h" #include "gui/common/UserNotify.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "gui/gxs/GxsIdTreeWidgetItem.h"
//#include "gui/gxs/RsGxsUpdateBroadcastBase.h" //#include "gui/gxs/RsGxsUpdateBroadcastBase.h"
#include "gui/msgs/MessageComposer.h" #include "gui/msgs/MessageComposer.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
@ -767,13 +768,13 @@ void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
#ifdef ID_DEBUG #ifdef ID_DEBUG
std::cerr << "invited: " << invited << ", subscription: " << subscrb ; std::cerr << "invited: " << invited << ", subscription: " << subscrb ;
#endif #endif
QTreeWidgetItem *subitem = NULL ; GxsIdRSTreeWidgetItem *subitem = NULL ;
// see if the item already exists // see if the item already exists
for(uint32_t k=0; k < (uint32_t)item->childCount(); ++k) for(uint32_t k=0; k < (uint32_t)item->childCount(); ++k)
if(item->child(k)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString().toStdString() == it->first.toStdString()) if(item->child(k)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString().toStdString() == it->first.toStdString())
{ {
subitem = item->child(k); subitem = dynamic_cast<GxsIdRSTreeWidgetItem*>(item->child(k));
#ifdef ID_DEBUG #ifdef ID_DEBUG
std::cerr << " found existing sub item." << std::endl; std::cerr << " found existing sub item." << std::endl;
#endif #endif
@ -802,20 +803,22 @@ void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
#ifdef ID_DEBUG #ifdef ID_DEBUG
std::cerr << " no existing sub item. Creating new one." << std::endl; std::cerr << " no existing sub item. Creating new one." << std::endl;
#endif #endif
subitem = new QTreeWidgetItem(item); subitem = new GxsIdRSTreeWidgetItem(NULL,GxsIdDetails::ICON_TYPE_AVATAR,false);
subitem->setId(it->first,CIRCLEGROUP_CIRCLE_COL_GROUPNAME,true);
RsIdentityDetails idd ; RsIdentityDetails idd ;
bool has_id = rsIdentity->getIdDetails(it->first,idd) ; bool has_id = rsIdentity->getIdDetails(it->first,idd) ;
QPixmap pixmap ; // QPixmap pixmap ;
if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap,GxsIdDetails::SMALL)) // if(idd.mAvatar.mSize == 0 || !GxsIdDetails::loadPixmapFromData(idd.mAvatar.mData, idd.mAvatar.mSize, pixmap,GxsIdDetails::SMALL))
pixmap = GxsIdDetails::makeDefaultIcon(it->first,GxsIdDetails::SMALL) ; // pixmap = GxsIdDetails::makeDefaultIcon(it->first,GxsIdDetails::SMALL) ;
if(has_id) // if(has_id)
subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(idd.mNickname.c_str())) ; // subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, QString::fromUtf8(idd.mNickname.c_str())) ;
else // else
subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, tr("Unknown ID:")+QString::fromStdString(it->first.toStdString())) ; // subitem->setText(CIRCLEGROUP_CIRCLE_COL_GROUPNAME, tr("Unknown ID:")+QString::fromStdString(it->first.toStdString())) ;
QString tooltip ; QString tooltip ;
tooltip += tr("Identity ID: ")+QString::fromStdString(it->first.toStdString()) ; tooltip += tr("Identity ID: ")+QString::fromStdString(it->first.toStdString()) ;
@ -836,7 +839,7 @@ void IdDialog::loadCircles(const std::list<RsGroupMetaData>& groupInfo)
subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(it->second)) ; subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPFLAGS, Qt::UserRole, QVariant(it->second)) ;
subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPID, Qt::UserRole, QString::fromStdString(it->first.toStdString())) ; subitem->setData(CIRCLEGROUP_CIRCLE_COL_GROUPID, Qt::UserRole, QString::fromStdString(it->first.toStdString())) ;
subitem->setIcon(RSID_COL_NICKNAME, QIcon(pixmap)); //subitem->setIcon(RSID_COL_NICKNAME, QIcon(pixmap));
item->addChild(subitem) ; item->addChild(subitem) ;
} }
@ -1565,7 +1568,9 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item,
return false; return false;
if (!item) if (!item)
{
item = new TreeWidgetItem(); item = new TreeWidgetItem();
}
item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE)); item->setText(RSID_COL_NICKNAME, QString::fromUtf8(data.mMeta.mGroupName.c_str()).left(RSID_MAXIMUM_NICKNAME_SIZE));
@ -1747,6 +1752,10 @@ void IdDialog::loadIdentities(const std::map<RsGxsGroupId,RsGxsIdGroup>& ids_set
else else
allItem->addChild(item); allItem->addChild(item);
} }
GxsIdLabel *label = new GxsIdLabel();
label->setId(RsGxsId(data.mMeta.mGroupId)) ;
ui->treeWidget_membership->setItemWidget(item,0,label) ;
} }
/* count items */ /* count items */

View file

@ -22,20 +22,22 @@
#include "GxsIdDetails.h" #include "GxsIdDetails.h"
/** Constructor */ /** Constructor */
GxsIdLabel::GxsIdLabel(QWidget *parent) GxsIdLabel::GxsIdLabel(bool show_tooltip,QWidget *parent)
: QLabel(parent) : QLabel(parent),mShowTooltip(show_tooltip)
{ {
} }
static void fillLabelCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/) static void fillLabelCallback(GxsIdDetailsType type, const RsIdentityDetails &details, QObject *object, const QVariant &/*data*/)
{ {
QLabel *label = dynamic_cast<QLabel*>(object); GxsIdLabel *label = dynamic_cast<GxsIdLabel*>(object);
if (!label) { if (!label) {
return; return;
} }
label->setText(GxsIdDetails::getNameForType(type, details)); label->setText(GxsIdDetails::getNameForType(type, details));
if(label->showTooltip())
{
QString toolTip; QString toolTip;
switch (type) { switch (type) {
@ -51,6 +53,7 @@ static void fillLabelCallback(GxsIdDetailsType type, const RsIdentityDetails &de
} }
label->setToolTip(toolTip); label->setToolTip(toolTip);
}
} }
void GxsIdLabel::setId(const RsGxsId &id) void GxsIdLabel::setId(const RsGxsId &id)

View file

@ -29,13 +29,16 @@ class GxsIdLabel : public QLabel
Q_OBJECT Q_OBJECT
public: public:
GxsIdLabel(QWidget *parent = NULL); GxsIdLabel(bool show_tooltip=true,QWidget *parent = NULL);
void setId(const RsGxsId &id); void setId(const RsGxsId &id);
bool getId(RsGxsId &id); bool getId(RsGxsId &id);
bool showTooltip() const { return mShowTooltip; }
private: private:
RsGxsId mId; RsGxsId mId;
bool mShowTooltip;
}; };
#endif #endif

View file

@ -26,8 +26,8 @@
#define BANNED_IMAGE ":/icons/yellow_biohazard64.png" #define BANNED_IMAGE ":/icons/yellow_biohazard64.png"
/** Constructor */ /** Constructor */
GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,QTreeWidget *parent) GxsIdRSTreeWidgetItem::GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,bool auto_tooltip,QTreeWidget *parent)
: QObject(NULL), RSTreeWidgetItem(compareRole, parent), mColumn(0), mIconTypeMask(icon_mask) : QObject(NULL), RSTreeWidgetItem(compareRole, parent), mColumn(0), mIconTypeMask(icon_mask),mAutoTooltip(auto_tooltip)
{ {
init(); init();
} }
@ -72,6 +72,8 @@ static void fillGxsIdRSTreeWidgetItemCallback(GxsIdDetailsType type, const RsIde
} }
int column = item->idColumn(); int column = item->idColumn();
if(item->autoTooltip())
item->setToolTip(column, GxsIdDetails::getComment(details)); item->setToolTip(column, GxsIdDetails::getComment(details));
item->setText(column, GxsIdDetails::getNameForType(type, details)); item->setText(column, GxsIdDetails::getNameForType(type, details));

View file

@ -41,7 +41,7 @@ class GxsIdRSTreeWidgetItem : public QObject, public RSTreeWidgetItem
Q_OBJECT Q_OBJECT
public: public:
GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,QTreeWidget *parent = NULL); GxsIdRSTreeWidgetItem(const RSTreeWidgetItemCompareRole *compareRole, uint32_t icon_mask,bool auto_tooltip=true,QTreeWidget *parent = NULL);
void setId(const RsGxsId &id, int column, bool retryWhenFailed); void setId(const RsGxsId &id, int column, bool retryWhenFailed);
bool getId(RsGxsId &id); bool getId(RsGxsId &id);
@ -57,6 +57,7 @@ public:
void setBannedState(bool b) { mBannedState = b; } // does not actually change the state, but used instead by callbacks to leave a trace void setBannedState(bool b) { mBannedState = b; } // does not actually change the state, but used instead by callbacks to leave a trace
void updateBannedState() ; // checks reputation, and update is needed void updateBannedState() ; // checks reputation, and update is needed
bool autoTooltip() const { return mAutoTooltip; }
private slots: private slots:
void startProcess(); void startProcess();
@ -68,6 +69,7 @@ private:
bool mIdFound; bool mIdFound;
bool mBannedState ; bool mBannedState ;
bool mRetryWhenFailed; bool mRetryWhenFailed;
bool mAutoTooltip;
RsReputationLevel mReputationLevel; RsReputationLevel mReputationLevel;
uint32_t mIconTypeMask; uint32_t mIconTypeMask;
RsGxsImage mAvatar; RsGxsImage mAvatar;