Removed the dummy buttons & added sorting the comments treewidget via combobox

This commit is contained in:
defnax 2019-03-26 18:35:10 +01:00
parent 1f6589e68e
commit b658839214
7 changed files with 99 additions and 44 deletions

View File

@ -49,6 +49,15 @@ GxsCommentDialog::GxsCommentDialog(QWidget *parent, RsTokenService *token_servic
connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refresh())); connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refresh()));
connect(ui->idChooser, SIGNAL(currentIndexChanged( int )), this, SLOT(voterSelectionChanged( int ))); connect(ui->idChooser, SIGNAL(currentIndexChanged( int )), this, SLOT(voterSelectionChanged( int )));
connect(ui->idChooser, SIGNAL(idsLoaded()), this, SLOT(idChooserReady())); connect(ui->idChooser, SIGNAL(idsLoaded()), this, SLOT(idChooserReady()));
connect(ui->sortBox, SIGNAL(currentIndexChanged(int)), this, SLOT(sortComments(int)));
// default sort method "HOT".
ui->treeWidget->sortByColumn(4, Qt::DescendingOrder);
int S = QFontMetricsF(font()).height() ;
ui->sortBox->setIconSize(QSize(S*1.5,S*1.5));
} }
GxsCommentDialog::~GxsCommentDialog() GxsCommentDialog::~GxsCommentDialog()
@ -141,3 +150,22 @@ void GxsCommentDialog::setCommentHeader(QWidget *header)
ui->notesBrowser->setPlainText(QString::fromStdString(mCurrentPost.mNotes)); ui->notesBrowser->setPlainText(QString::fromStdString(mCurrentPost.mNotes));
#endif #endif
} }
void GxsCommentDialog::sortComments(int i)
{
switch(i)
{
default:
case 0:
ui->treeWidget->sortByColumn(4, Qt::DescendingOrder);
break;
case 1:
ui->treeWidget->sortByColumn(2, Qt::DescendingOrder);
break;
case 2:
ui->treeWidget->sortByColumn(3, Qt::DescendingOrder);
break;
}
}

View File

@ -45,6 +45,7 @@ private slots:
void refresh(); void refresh();
void idChooserReady(); void idChooserReady();
void voterSelectionChanged( int index ); void voterSelectionChanged( int index );
void sortComments(int);
private: private:
RsGxsGroupId mGrpId; RsGxsGroupId mGrpId;

View File

@ -13,8 +13,8 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="GxsCommentDialogVLayout"> <layout class="QGridLayout" name="GxsCommentDialogGLayout">
<item> <item row="0" column="0">
<widget class="QFrame" name="postFrame"> <widget class="QFrame" name="postFrame">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@ -24,59 +24,63 @@
</property> </property>
<layout class="QVBoxLayout" name="postFrameVLayout"> <layout class="QVBoxLayout" name="postFrameVLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>9</number> <number>1</number>
</property> </property>
<property name="topMargin"> <property name="topMargin">
<number>1</number> <number>1</number>
</property> </property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin"> <property name="bottomMargin">
<number>1</number> <number>1</number>
</property> </property>
</layout> </layout>
</widget> </widget>
</item> </item>
<item> <item row="1" column="0">
<layout class="QHBoxLayout" name="toolBarHLayout"> <layout class="QHBoxLayout" name="toolBarHLayout">
<item> <item>
<widget class="QPushButton" name="hotSortButton"> <widget class="QComboBox" name="sortBox">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-family:'-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:14px; color:#24292e; background-color:#ffffff;&quot;&gt;sort by&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<item>
<property name="text"> <property name="text">
<string>Hot</string> <string>Hot</string>
</property> </property>
<property name="checkable"> <property name="icon">
<bool>true</bool> <iconset resource="../icons.qrc">
<normaloff>:/icons/png/flame.png</normaloff>:/icons/png/flame.png</iconset>
</property> </property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="newSortButton">
<property name="text"> <property name="text">
<string>New</string> <string>New</string>
</property> </property>
<property name="checkable"> <property name="icon">
<bool>true</bool> <iconset resource="../icons.qrc">
<normaloff>:/icons/png/new.png</normaloff>:/icons/png/new.png</iconset>
</property> </property>
<property name="autoExclusive">
<bool>true</bool>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="topSortButton">
<property name="text"> <property name="text">
<string>Top</string> <string>Top</string>
</property> </property>
<property name="checkable"> <property name="icon">
<bool>true</bool> <iconset resource="../icons.qrc">
</property> <normaloff>:/icons/png/top.png</normaloff>:/icons/png/top.png</iconset>
<property name="checked">
<bool>false</bool>
</property>
<property name="autoExclusive">
<bool>true</bool>
</property> </property>
</item>
</widget> </widget>
</item> </item>
<item> <item>
@ -111,8 +115,11 @@
</item> </item>
</layout> </layout>
</item> </item>
<item> <item row="2" column="0">
<widget class="GxsCommentTreeWidget" name="treeWidget"> <widget class="GxsCommentTreeWidget" name="treeWidget">
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column> <column>
<property name="text"> <property name="text">
<string>Comment</string> <string>Comment</string>
@ -164,6 +171,8 @@
<header>gui/gxs/GxsCommentTreeWidget.h</header> <header>gui/gxs/GxsCommentTreeWidget.h</header>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources/> <resources>
<include location="../icons.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -31,6 +31,7 @@
#include "gui/gxs/GxsCommentTreeWidget.h" #include "gui/gxs/GxsCommentTreeWidget.h"
#include "gui/gxs/GxsCreateCommentDialog.h" #include "gui/gxs/GxsCreateCommentDialog.h"
#include "gui/gxs/GxsIdTreeWidgetItem.h" #include "gui/gxs/GxsIdTreeWidgetItem.h"
#include "gui/common/RSTreeWidgetItem.h"
#include <iostream> #include <iostream>
@ -45,6 +46,7 @@
#define PCITEM_COLUMN_PARENTID 8 #define PCITEM_COLUMN_PARENTID 8
#define PCITEM_COLUMN_AUTHORID 9 #define PCITEM_COLUMN_AUTHORID 9
#define ROLE_SORT Qt::UserRole + 1
#define GXSCOMMENTS_LOADTHREAD 1 #define GXSCOMMENTS_LOADTHREAD 1
@ -140,6 +142,9 @@ GxsCommentTreeWidget::GxsCommentTreeWidget(QWidget *parent)
setItemDelegateForColumn(PCITEM_COLUMN_COMMENT,new MultiLinesCommentDelegate(QFontMetricsF(font()))) ; setItemDelegateForColumn(PCITEM_COLUMN_COMMENT,new MultiLinesCommentDelegate(QFontMetricsF(font()))) ;
commentsRole = new RSTreeWidgetItemCompareRole;
commentsRole->setRole(PCITEM_COLUMN_DATE, ROLE_SORT);
// QFont font = QFont("ARIAL", 10); // QFont font = QFont("ARIAL", 10);
// font.setBold(true); // font.setBold(true);
@ -537,6 +542,8 @@ void GxsCommentTreeWidget::service_loadThread(const uint32_t &token)
text = qtime.toString("yyyy-MM-dd hh:mm:ss") ; text = qtime.toString("yyyy-MM-dd hh:mm:ss") ;
item->setText(PCITEM_COLUMN_DATE, text) ; item->setText(PCITEM_COLUMN_DATE, text) ;
item->setToolTip(PCITEM_COLUMN_DATE, text) ; item->setToolTip(PCITEM_COLUMN_DATE, text) ;
item->setData(PCITEM_COLUMN_DATE, ROLE_SORT, comment.mMeta.mPublishTs);
} }
text = QString::fromUtf8(comment.mComment.c_str()); text = QString::fromUtf8(comment.mComment.c_str());

View File

@ -27,6 +27,8 @@
#include <retroshare/rsgxscommon.h> #include <retroshare/rsgxscommon.h>
#include <retroshare/rsidentity.h> #include <retroshare/rsidentity.h>
class RSTreeWidgetItemCompareRole;
class GxsCommentTreeWidget : public QTreeWidget, public TokenResponse class GxsCommentTreeWidget : public QTreeWidget, public TokenResponse
{ {
Q_OBJECT Q_OBJECT
@ -97,6 +99,8 @@ protected:
std::map<RsGxsMessageId, QTreeWidgetItem *> mLoadingMap; std::map<RsGxsMessageId, QTreeWidgetItem *> mLoadingMap;
std::multimap<RsGxsMessageId, QTreeWidgetItem *> mPendingInsertMap; std::multimap<RsGxsMessageId, QTreeWidgetItem *> mPendingInsertMap;
RSTreeWidgetItemCompareRole *commentsRole;
TokenQueue *mTokenQueue; TokenQueue *mTokenQueue;
RsTokenService *mRsTokenService; RsTokenService *mRsTokenService;
RsGxsCommentService *mCommentService; RsGxsCommentService *mCommentService;

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>600</width> <width>600</width>
<height>736</height> <height>633</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">

View File

@ -915,3 +915,9 @@ PostedItem QToolButton#commentButton, QPushButton#shareButton, QToolButton#notes
color: #878a8c; color: #878a8c;
font-weight: bold; font-weight: bold;
} }
GxsCommentDialog QComboBox#sortBox {
font: bold;
font-size: 12px;
color: #0099cc;
}