From 4b94b2ec4a1cb175d341120cb90abcb7608b252a Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 29 Jun 2017 21:12:02 +0200 Subject: [PATCH] improved display of GxsTrans statistics --- .../gui/statistics/GxsTransportStatistics.cpp | 42 +++++++++++++++---- .../gui/statistics/GxsTransportStatistics.h | 4 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp index 9d1811d8d..972dbd415 100644 --- a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp +++ b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.cpp @@ -60,6 +60,7 @@ #define COL_GROUP_SIZE_MSGS 2 #define COL_GROUP_SUBSCRIBED 3 #define COL_GROUP_POPULARITY 4 +#define COL_GROUP_UNIQUE_ID 5 static const int PARTIAL_VIEW_SIZE = 9 ; static const int MAX_TUNNEL_REQUESTS_DISPLAY = 10 ; @@ -70,7 +71,7 @@ static const int GXSTRANS_STATISTICS_DELAY_BETWEEN_GROUP_REQ = 30 ; // never req #define GXSTRANS_GROUP_STAT 0x03 #define GXSTRANS_MSG_META 0x04 -#define DEBUG_GXSTRANS_STATS 1 +//#define DEBUG_GXSTRANS_STATS 1 GxsTransportStatistics::GxsTransportStatistics(QWidget *parent) : RsGxsUpdateBroadcastPage(rsGxsTrans,parent) @@ -143,8 +144,9 @@ void GxsTransportStatistics::CustomPopupMenu( QPoint ) void GxsTransportStatistics::updateDisplay(bool) { time_t now = time(NULL) ; - +#ifdef DEBUG_GXSTRANS_STATS std::cerr << "GxsTransportStatistics::updateDisplay()" << std::endl; +#endif requestGroupMeta(); mLastGroupReqTS = now ; @@ -195,7 +197,6 @@ void GxsTransportStatistics::updateContent() rsGxsTrans->getStatistics(transinfo) ; - // clear treeWidget->clear(); @@ -242,34 +243,57 @@ void GxsTransportStatistics::updateContent() if(groupTreeWidget->isItemExpanded(groupTreeWidget->topLevelItem(i))) openned_groups.insert(RsGxsGroupId(groupTreeWidget->topLevelItem(i)->data(COL_GROUP_GRP_ID,Qt::DisplayRole).toString().toStdString())) ; - groupTreeWidget->clear(); + groupTreeWidget->clear(); for(std::map::const_iterator it(mGroupStats.begin());it!=mGroupStats.end();++it) { const RsGxsTransGroupStatistics& stat(it->second) ; + QTreeWidgetItem *item ; + + { + QString unique_id = QString::fromStdString(stat.mGrpId.toStdString()); + + QList iteml = groupTreeWidget->findItems(unique_id,Qt::MatchExactly,COL_GROUP_UNIQUE_ID) ; + + if(iteml.empty()) + item = new QTreeWidgetItem; + else + item = *iteml.begin(); + } - QTreeWidgetItem *item = new QTreeWidgetItem(); groupTreeWidget->addTopLevelItem(item); groupTreeWidget->setItemExpanded(item,openned_groups.find(it->first) != openned_groups.end()); QString msg_time_string = (stat.last_publish_TS>0)?QString(" (Last msg: %1)").arg(QDateTime::fromTime_t(stat.last_publish_TS).toString()):"" ; + item->setData(COL_GROUP_UNIQUE_ID, Qt::DisplayRole, QString::fromStdString(stat.mGrpId.toStdString())) ; item->setData(COL_GROUP_NUM_MSGS, Qt::DisplayRole, QString::number(stat.mNumMsgs) + msg_time_string) ; item->setData(COL_GROUP_GRP_ID, Qt::DisplayRole, QString::fromStdString(stat.mGrpId.toStdString())) ; item->setData(COL_GROUP_SIZE_MSGS, Qt::DisplayRole, QString::number(stat.mTotalSizeOfMsgs)) ; item->setData(COL_GROUP_SUBSCRIBED,Qt::DisplayRole, stat.subscribed?tr("Yes"):tr("No")) ; item->setData(COL_GROUP_POPULARITY,Qt::DisplayRole, QString::number(stat.popularity)) ; - for(uint32_t i=0;isecond.messages_metas.size();++i) + for(std::map::const_iterator msgIt(stat.messages_metas.begin());msgIt!=stat.messages_metas.end();++msgIt) { - QTreeWidgetItem *sitem = new QTreeWidgetItem(item) ; + const RsMsgMetaData& meta(msgIt->second); - const RsMsgMetaData& meta(it->second.messages_metas[i]) ; + QTreeWidgetItem *sitem ; + { + QString unique_id = QString::fromStdString(meta.mMsgId.toStdString()); + + QList iteml = groupTreeWidget->findItems(unique_id,Qt::MatchExactly,COL_GROUP_UNIQUE_ID) ; + + if(iteml.empty()) + sitem = new QTreeWidgetItem(item) ; + else + sitem = *iteml.begin(); + } GxsIdLabel *label = new GxsIdLabel(); label->setId(meta.mAuthorId) ; groupTreeWidget->setItemWidget(sitem,COL_GROUP_GRP_ID,label) ; + sitem->setData(COL_GROUP_UNIQUE_ID, Qt::DisplayRole,QString::fromStdString(meta.mMsgId.toStdString())); sitem->setData(COL_GROUP_NUM_MSGS,Qt::DisplayRole, QDateTime::fromTime_t(meta.mPublishTs).toString()); } } @@ -367,7 +391,9 @@ void GxsTransportStatistics::loadGroupStat(const uint32_t &token) GxsGroupStatistic stats; rsGxsTrans->getGroupStatistic(token, stats); +#ifdef DEBUG_GXSTRANS_STATS std::cerr << "Loading group stats: " << stats.mGrpId << ", num msgs=" << stats.mNumMsgs << ", total size=" << stats.mTotalSizeOfMsgs << std::endl; +#endif dynamic_cast(mGroupStats[stats.mGrpId]) = stats ; } diff --git a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.h b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.h index 3f3b4f2e2..75a93a7a6 100644 --- a/retroshare-gui/src/gui/statistics/GxsTransportStatistics.h +++ b/retroshare-gui/src/gui/statistics/GxsTransportStatistics.h @@ -47,7 +47,7 @@ public: void addMessageMeta(const RsMsgMetaData& meta) { - messages_metas.push_back(meta) ; + messages_metas[meta.mMsgId] = meta ; last_publish_TS = std::max(last_publish_TS,meta.mPublishTs) ; } @@ -56,7 +56,7 @@ public: time_t last_publish_TS; - std::vector messages_metas ; + std::map messages_metas ; }; class GxsTransportStatistics: public RsGxsUpdateBroadcastPage, public TokenResponse, public Ui::GxsTransportStatistics