fixed display of author in new ForumModel

This commit is contained in:
csoler 2018-11-24 16:11:40 +01:00
parent 52a5aeb1f8
commit c2686d1a94
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 89 additions and 25 deletions

View File

@ -5,6 +5,7 @@
#include "util/qtthreadsutils.h" #include "util/qtthreadsutils.h"
#include "util/DateTime.h" #include "util/DateTime.h"
#include "GxsForumModel.h" #include "GxsForumModel.h"
#include "retroshare/rsgxsflags.h"
#include "retroshare/rsgxsforums.h" #include "retroshare/rsgxsforums.h"
//#define DEBUG_FORUMMODEL //#define DEBUG_FORUMMODEL
@ -14,11 +15,9 @@
#define COLUMN_THREAD_DATE 2 #define COLUMN_THREAD_DATE 2
#define COLUMN_THREAD_DISTRIBUTION 3 #define COLUMN_THREAD_DISTRIBUTION 3
#define COLUMN_THREAD_AUTHOR 4 #define COLUMN_THREAD_AUTHOR 4
#define COLUMN_THREAD_SIGNED 5 #define COLUMN_THREAD_CONTENT 5
#define COLUMN_THREAD_CONTENT 6 #define COLUMN_THREAD_MSGID 6
#define COLUMN_THREAD_COUNT 7 #define COLUMN_THREAD_NB_COLUMNS 7
#define COLUMN_THREAD_MSGID 8
#define COLUMN_THREAD_NB_COLUMNS 9
#define COLUMN_THREAD_DATA 0 // column for storing the userdata like parentid #define COLUMN_THREAD_DATA 0 // column for storing the userdata like parentid
@ -252,6 +251,7 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const
switch(role) switch(role)
{ {
case Qt::SizeHintRole: return sizeHintRole(index.column()) ; case Qt::SizeHintRole: return sizeHintRole(index.column()) ;
case Qt::FontRole:
case Qt::TextAlignmentRole: case Qt::TextAlignmentRole:
case Qt::TextColorRole: case Qt::TextColorRole:
case Qt::WhatsThisRole: case Qt::WhatsThisRole:
@ -285,6 +285,14 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const
const ForumModelPostEntry& fmpe(mPosts[entry]); const ForumModelPostEntry& fmpe(mPosts[entry]);
if(role == Qt::FontRole)
{
QFont font ;
font.setBold(IS_MSG_UNREAD(fmpe.mMsgStatus));
return QVariant(font);
}
#ifdef DEBUG_FORUMMODEL #ifdef DEBUG_FORUMMODEL
std::cerr << " [ok]" << std::endl; std::cerr << " [ok]" << std::endl;
#endif #endif
@ -294,6 +302,7 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole: return displayRole (fmpe,index.column()) ; case Qt::DisplayRole: return displayRole (fmpe,index.column()) ;
case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ; case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ;
case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ; case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ;
case Qt::UserRole: return userRole (fmpe,index.column()) ;
case ThreadPinnedRole: return pinnedRole (fmpe,index.column()) ; case ThreadPinnedRole: return pinnedRole (fmpe,index.column()) ;
case MissingRole: return missingRole (fmpe,index.column()) ; case MissingRole: return missingRole (fmpe,index.column()) ;
@ -308,7 +317,7 @@ QVariant RsGxsForumModel::statusRole(const ForumModelPostEntry& fmpe,int column)
if(column != COLUMN_THREAD_DATA) if(column != COLUMN_THREAD_DATA)
return QVariant(); return QVariant();
return QVariant(fmpe.mStatus); return QVariant(fmpe.mMsgStatus);
} }
QVariant RsGxsForumModel::missingRole(const ForumModelPostEntry& fmpe,int column) const QVariant RsGxsForumModel::missingRole(const ForumModelPostEntry& fmpe,int column) const
@ -390,7 +399,7 @@ QVariant RsGxsForumModel::displayRole(const ForumModelPostEntry& fmpe,int col) c
else else
return QVariant(QString::fromUtf8(fmpe.mTitle.c_str())); return QVariant(QString::fromUtf8(fmpe.mTitle.c_str()));
//case COLUMN_THREAD_READ_STATUS:return QVariant(fmpe.mMsgStatus); case COLUMN_THREAD_READ:return QVariant();
case COLUMN_THREAD_DATE: { case COLUMN_THREAD_DATE: {
QDateTime qtime; QDateTime qtime;
qtime.setTime_t(fmpe.mPublishTs); qtime.setTime_t(fmpe.mPublishTs);
@ -398,8 +407,9 @@ QVariant RsGxsForumModel::displayRole(const ForumModelPostEntry& fmpe,int col) c
return QVariant(DateTime::formatDateTime(qtime)); return QVariant(DateTime::formatDateTime(qtime));
} }
case COLUMN_THREAD_AUTHOR: return QVariant(QString::fromStdString(fmpe.mAuthorId.toStdString())); case COLUMN_THREAD_DISTRIBUTION:
case COLUMN_THREAD_MSGID: return QVariant(QString::fromStdString(fmpe.mMsgId.toStdString())); case COLUMN_THREAD_AUTHOR: return QVariant();
case COLUMN_THREAD_MSGID: return QVariant();
#ifdef TODO #ifdef TODO
if (filterColumn == COLUMN_THREAD_CONTENT) { if (filterColumn == COLUMN_THREAD_CONTENT) {
// need content for filter // need content for filter
@ -416,6 +426,17 @@ QVariant RsGxsForumModel::displayRole(const ForumModelPostEntry& fmpe,int col) c
return QVariant("[ERROR]"); return QVariant("[ERROR]");
} }
QVariant RsGxsForumModel::userRole(const ForumModelPostEntry& fmpe,int col) const
{
switch(col)
{
case COLUMN_THREAD_AUTHOR: return QVariant(QString::fromStdString(fmpe.mAuthorId.toStdString()));
case COLUMN_THREAD_MSGID: return QVariant(QString::fromStdString(fmpe.mMsgId.toStdString()));
default:
return QVariant();
}
}
QVariant RsGxsForumModel::decorationRole(const ForumModelPostEntry& fmpe,int col) const QVariant RsGxsForumModel::decorationRole(const ForumModelPostEntry& fmpe,int col) const
{ {
if(col == COLUMN_THREAD_DISTRIBUTION) if(col == COLUMN_THREAD_DISTRIBUTION)
@ -534,7 +555,7 @@ void RsGxsForumModel::convertMsgToPostEntry(const RsGxsForumGroup& mForumGroup,c
fentry.mMsgId = msg.mMeta.mMsgId; fentry.mMsgId = msg.mMeta.mMsgId;
fentry.mPublishTs = msg.mMeta.mPublishTs; fentry.mPublishTs = msg.mMeta.mPublishTs;
fentry.mPostFlags = 0; fentry.mPostFlags = 0;
fentry.mStatus = msg.mMeta.mMsgStatus; fentry.mMsgStatus = msg.mMeta.mMsgStatus;
if(mForumGroup.mPinnedPosts.ids.find(msg.mMeta.mMsgId) != mForumGroup.mPinnedPosts.ids.end()) if(mForumGroup.mPinnedPosts.ids.find(msg.mMeta.mMsgId) != mForumGroup.mPinnedPosts.ids.end())
fentry.mPostFlags |= ForumModelPostEntry::FLAG_POST_IS_PINNED; fentry.mPostFlags |= ForumModelPostEntry::FLAG_POST_IS_PINNED;

View File

@ -27,7 +27,7 @@ typedef uint32_t ForumModelIndex;
struct ForumModelPostEntry struct ForumModelPostEntry
{ {
ForumModelPostEntry() : mPublishTs(0),mPostFlags(0),mReputationWarningLevel(0),mStatus(0),prow(0) {} ForumModelPostEntry() : mPublishTs(0),mPostFlags(0),mReputationWarningLevel(0),mMsgStatus(0),prow(0) {}
enum { // flags for display of posts enum { // flags for display of posts
FLAG_POST_IS_PINNED = 0x0001, FLAG_POST_IS_PINNED = 0x0001,
@ -41,7 +41,7 @@ struct ForumModelPostEntry
uint32_t mPublishTs; uint32_t mPublishTs;
uint32_t mPostFlags; uint32_t mPostFlags;
int mReputationWarningLevel; int mReputationWarningLevel;
int mStatus; int mMsgStatus;
std::vector<ForumModelIndex> mChildren; std::vector<ForumModelIndex> mChildren;
ForumModelIndex mParent; ForumModelIndex mParent;
@ -82,11 +82,13 @@ public:
QVariant displayRole (const ForumModelPostEntry& fmpe, int col) const; QVariant displayRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant decorationRole(const ForumModelPostEntry& fmpe, int col) const; QVariant decorationRole(const ForumModelPostEntry& fmpe, int col) const;
QVariant toolTipRole (const ForumModelPostEntry& fmpe, int col) const; QVariant toolTipRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant userRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant pinnedRole (const ForumModelPostEntry& fmpe, int col) const; QVariant pinnedRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant missingRole (const ForumModelPostEntry& fmpe, int col) const; QVariant missingRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant statusRole (const ForumModelPostEntry& fmpe, int col) const; QVariant statusRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const; QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant sortRole (const ForumModelPostEntry& fmpe, int col) const; QVariant sortRole (const ForumModelPostEntry& fmpe, int col) const;
QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const;
/*! /*!
* \brief debug_dump * \brief debug_dump

View File

@ -80,16 +80,16 @@
#define VIEW_FLAT 2 #define VIEW_FLAT 2
/* Thread constants */ /* Thread constants */
// We need consts for that!! Defined in multiple places.
#define COLUMN_THREAD_TITLE 0 #define COLUMN_THREAD_TITLE 0
#define COLUMN_THREAD_READ 1 #define COLUMN_THREAD_READ 1
#define COLUMN_THREAD_DATE 2 #define COLUMN_THREAD_DATE 2
#define COLUMN_THREAD_DISTRIBUTION 3 #define COLUMN_THREAD_DISTRIBUTION 3
#define COLUMN_THREAD_AUTHOR 4 #define COLUMN_THREAD_AUTHOR 4
#define COLUMN_THREAD_SIGNED 5 #define COLUMN_THREAD_CONTENT 5
#define COLUMN_THREAD_CONTENT 6 #define COLUMN_THREAD_MSGID 6
#define COLUMN_THREAD_COUNT 7 #define COLUMN_THREAD_NB_COLUMNS 7
#define COLUMN_THREAD_MSGID 8
#define COLUMN_THREAD_NB_COLUMNS 9
#define COLUMN_THREAD_DATA 0 // column for storing the userdata like parentid #define COLUMN_THREAD_DATA 0 // column for storing the userdata like parentid
@ -154,7 +154,36 @@ class AuthorItemDelegate: public QStyledItemDelegate
public: public:
AuthorItemDelegate() {} AuthorItemDelegate() {}
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex& index) const QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
{
QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index);
// disable default icon
opt.icon = QIcon();
const QRect r = option.rect;
RsGxsId id(index.data(Qt::UserRole).toString().toStdString());
QString str;
QList<QIcon> icons;
QString comment;
QFontMetricsF fm(option.font);
float f = fm.height();
QIcon icon ;
if(!GxsIdDetails::MakeIdDesc(id, true, str, icons, comment,GxsIdDetails::ICON_TYPE_AVATAR))
icon = GxsIdDetails::getLoadingIcon(id);
else
icon = *icons.begin();
QPixmap pix = icon.pixmap(r.size());
return QSize(pix.width() + fm.width(str),fm.height());
}
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex& index) const override
{ {
if(!index.isValid()) if(!index.isValid())
{ {
@ -172,11 +201,14 @@ public:
const QRect r = option.rect; const QRect r = option.rect;
RsGxsId id(index.data(Qt::DisplayRole).toString().toStdString()); RsGxsId id(index.data(Qt::UserRole).toString().toStdString());
QString str; QString str;
QList<QIcon> icons; QList<QIcon> icons;
QString comment; QString comment;
QFontMetricsF fm(painter->font());
float f = fm.height();
QIcon icon ; QIcon icon ;
if(!GxsIdDetails::MakeIdDesc(id, true, str, icons, comment,GxsIdDetails::ICON_TYPE_AVATAR)) if(!GxsIdDetails::MakeIdDesc(id, true, str, icons, comment,GxsIdDetails::ICON_TYPE_AVATAR))
@ -189,6 +221,7 @@ public:
// draw pixmap at center of item // draw pixmap at center of item
const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2); const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2);
painter->drawPixmap(r.topLeft() + p, pix); painter->drawPixmap(r.topLeft() + p, pix);
painter->drawText(r.topLeft() + p + QPoint(pix.width()+f/2.0,f*0.8), str);
} }
}; };
@ -565,10 +598,18 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
if (mFillThread) { if (mFillThread) {
return; return;
} }
#ifdef TODO
QMenu contextMnu(this); QMenu contextMnu(this);
QList<QTreeWidgetItem*> selectedItems = ui->threadTreeWidget->selectedItems(); QModelIndexList selectedIndexes = ui->threadTreeWidget->selectionModel()->selectedIndexes();
if(selectedIndexes.size() != 1)
return;
QModelIndex index = *selectedIndexes.begin();
RsGxsMessageId mid(mThreadModel->data(index.sibling(index.row(),COLUMN_THREAD_MSGID),Qt::UserRole).toString().toStdString());
std::cerr << "Clicked on msg " << mid << std::endl;
#ifdef TODO
QAction *editAct = new QAction(QIcon(IMAGE_MESSAGEEDIT), tr("Edit"), &contextMnu); QAction *editAct = new QAction(QIcon(IMAGE_MESSAGEEDIT), tr("Edit"), &contextMnu);
connect(editAct, SIGNAL(triggered()), this, SLOT(editforummessage())); connect(editAct, SIGNAL(triggered()), this, SLOT(editforummessage()));
@ -829,7 +870,7 @@ void GxsForumThreadWidget::changedThread(QModelIndex index)
return; return;
} }
mThreadId = mOrigThreadId = RsGxsMessageId(mThreadModel->data(index.sibling(index.row(),COLUMN_THREAD_MSGID),Qt::DisplayRole).toString().toStdString()); mThreadId = mOrigThreadId = RsGxsMessageId(mThreadModel->data(index.sibling(index.row(),COLUMN_THREAD_MSGID),Qt::UserRole).toString().toStdString());
std::cerr << "Switched to new thread ID " << mThreadId << std::endl; std::cerr << "Switched to new thread ID " << mThreadId << std::endl;
@ -867,7 +908,7 @@ void GxsForumThreadWidget::calculateIconsAndFonts(QTreeWidgetItem *item, bool &h
bool isNew = IS_MSG_NEW(status); bool isNew = IS_MSG_NEW(status);
bool unread = IS_MSG_UNREAD(status); bool unread = IS_MSG_UNREAD(status);
bool missing = item->data(COLUMN_THREAD_DATA, ROLE_THREAD_MISSING).toBool(); bool missing = item->data(COLUMN_THREAD_DATA, ROLE_THREAD_MISSING).toBool();
RsGxsMessageId msgId(item->data(COLUMN_THREAD_MSGID,Qt::DisplayRole).toString().toStdString()); RsGxsMessageId msgId(item->data(COLUMN_THREAD_MSGID,Qt::UserRole).toString().toStdString());
// set icon // set icon
if (missing) { if (missing) {
@ -899,7 +940,7 @@ void GxsForumThreadWidget::calculateIconsAndFonts(QTreeWidgetItem *item, bool &h
bool is_pinned = mForumGroup.mPinnedPosts.ids.find(msgId) != mForumGroup.mPinnedPosts.ids.end(); bool is_pinned = mForumGroup.mPinnedPosts.ids.find(msgId) != mForumGroup.mPinnedPosts.ids.end();
// set font // set font
for (int i = 0; i < COLUMN_THREAD_COUNT; ++i) { for (int i = 0; i < COLUMN_THREAD_NB_COLUMNS; ++i) {
QFont qf = item->font(i); QFont qf = item->font(i);
if (!IS_GROUP_SUBSCRIBED(mSubscribeFlags)) { if (!IS_GROUP_SUBSCRIBED(mSubscribeFlags)) {
@ -1452,7 +1493,7 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum
item->setText(COLUMN_THREAD_CONTENT, doc.toPlainText().replace(QString("\n"), QString(" "))); item->setText(COLUMN_THREAD_CONTENT, doc.toPlainText().replace(QString("\n"), QString(" ")));
} }
item->setData(COLUMN_THREAD_MSGID,Qt::DisplayRole, QString::fromStdString(msg.mMeta.mMsgId.toStdString())); item->setData(COLUMN_THREAD_MSGID,Qt::UserRole, QString::fromStdString(msg.mMeta.mMsgId.toStdString()));
//#TODO //#TODO
#if 0 #if 0
if (IS_GROUP_SUBSCRIBED(subscribeFlags) && !(msginfo.mMsgFlags & RS_DISTRIB_MISSING_MSG)) { if (IS_GROUP_SUBSCRIBED(subscribeFlags) && !(msginfo.mMsgFlags & RS_DISTRIB_MISSING_MSG)) {