Add Last Post Column in GroupTreeWidget.

Hidden by default.
A context menu is added.
This commit is contained in:
Phenom 2018-05-08 12:08:08 +02:00
parent 1352631807
commit 2ebacf36ed
3 changed files with 122 additions and 95 deletions

View file

@ -43,7 +43,8 @@
#define COLUMN_NAME 0 #define COLUMN_NAME 0
#define COLUMN_UNREAD 1 #define COLUMN_UNREAD 1
#define COLUMN_POPULARITY 2 #define COLUMN_POPULARITY 2
#define COLUMN_COUNT 3 #define COLUMN_LAST_POST 3
#define COLUMN_COUNT 4
#define COLUMN_DATA COLUMN_NAME #define COLUMN_DATA COLUMN_NAME
#define ROLE_ID Qt::UserRole #define ROLE_ID Qt::UserRole
@ -100,9 +101,12 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
/* Initialize tree widget */ /* Initialize tree widget */
ui->treeWidget->setColumnCount(COLUMN_COUNT); ui->treeWidget->setColumnCount(COLUMN_COUNT);
ui->treeWidget->enableColumnCustomize(true);
ui->treeWidget->setColumnCustomizable(COLUMN_NAME, false);
int S = QFontMetricsF(font()).height() ; int S = QFontMetricsF(font()).height() ;
int W = QFontMetricsF(font()).width("999") ; int W = QFontMetricsF(font()).width("999") ;
int D = QFontMetricsF(font()).width("9999-99-99[]") ;
/* 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 ();
@ -113,6 +117,15 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
header->resizeSection(COLUMN_UNREAD, W+4) ; header->resizeSection(COLUMN_UNREAD, W+4) ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_POPULARITY, QHeaderView::Fixed); QHeaderView_setSectionResizeModeColumn(header, COLUMN_POPULARITY, QHeaderView::Fixed);
header->resizeSection(COLUMN_POPULARITY, 2*S) ; header->resizeSection(COLUMN_POPULARITY, 2*S) ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_LAST_POST, QHeaderView::Fixed);
header->resizeSection(COLUMN_LAST_POST, D+4) ;
header->setSectionHidden(COLUMN_LAST_POST, true);
QTreeWidgetItem *headerItem = ui->treeWidget->headerItem();
headerItem->setText(COLUMN_NAME, tr("Name"));
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"));
@ -192,9 +205,10 @@ void GroupTreeWidget::addToolButton(QToolButton *toolButton)
ui->titleBarFrame->layout()->addWidget(toolButton); ui->titleBarFrame->layout()->addWidget(toolButton);
} }
void GroupTreeWidget::processSettings(RshareSettings *settings, bool load) // Load and save settings (group must be started from the caller)
void GroupTreeWidget::processSettings(bool load)
{ {
if (settings == NULL) { if (Settings == NULL) {
return; return;
} }
@ -204,16 +218,18 @@ void GroupTreeWidget::processSettings(RshareSettings *settings, bool load)
const int SORTBY_POSTS = 4; const int SORTBY_POSTS = 4;
const int SORTBY_UNREAD = 5; const int SORTBY_UNREAD = 5;
ui->treeWidget->processSettings(load);
if (load) { if (load) {
// load settings // load Settings
// state of order // state of order
bool ascSort = settings->value("GroupAscSort", true).toBool(); bool ascSort = Settings->value("GroupAscSort", true).toBool();
actionSortAscending->setChecked(ascSort); actionSortAscending->setChecked(ascSort);
actionSortDescending->setChecked(!ascSort); actionSortDescending->setChecked(!ascSort);
// state of sort // state of sort
int sortby = settings->value("GroupSortBy").toInt(); int sortby = Settings->value("GroupSortBy").toInt();
switch (sortby) { switch (sortby) {
case SORTBY_NAME: case SORTBY_NAME:
if (actionSortByName) { if (actionSortByName) {
@ -242,10 +258,10 @@ void GroupTreeWidget::processSettings(RshareSettings *settings, bool load)
break; break;
} }
} else { } else {
// save settings // save Settings
// state of order // state of order
settings->setValue("GroupAscSort", !(actionSortDescending && actionSortDescending->isChecked())); //True by default Settings->setValue("GroupAscSort", !(actionSortDescending && actionSortDescending->isChecked())); //True by default
// state of sort // state of sort
int sortby = SORTBY_NAME; int sortby = SORTBY_NAME;
@ -260,7 +276,7 @@ void GroupTreeWidget::processSettings(RshareSettings *settings, bool load)
} else if (actionSortByUnread && actionSortByUnread->isChecked()) { } else if (actionSortByUnread && actionSortByUnread->isChecked()) {
sortby = SORTBY_UNREAD; sortby = SORTBY_UNREAD;
} }
settings->setValue("GroupSortBy", sortby); Settings->setValue("GroupSortBy", sortby);
} }
} }
@ -453,6 +469,11 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
/* 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(COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting
if(itemInfo.lastpost == QDateTime::fromTime_t(0))
item->setText(COLUMN_LAST_POST, tr("Never"));
else
item->setText(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->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting

View file

@ -77,8 +77,8 @@ public:
// Add a tool button to the tool area // Add a tool button to the tool area
void addToolButton(QToolButton *toolButton); void addToolButton(QToolButton *toolButton);
// Load and save settings (group must be startet from the caller) // Load and save settings (group must be started from the caller)
void processSettings(RshareSettings *settings, bool load); void processSettings(bool load);
// Add a new category item // Add a new category item
QTreeWidgetItem *addCategoryItem(const QString &name, const QIcon &icon, bool expand); QTreeWidgetItem *addCategoryItem(const QString &name, const QIcon &icon, bool expand);

View file

@ -194,7 +194,7 @@ void GxsGroupFrameDialog::processSettings(bool load)
Settings->setValue("Splitter", ui->splitter->saveState()); Settings->setValue("Splitter", ui->splitter->saveState());
} }
ui->groupTreeWidget->processSettings(Settings, load); ui->groupTreeWidget->processSettings(load);
Settings->endGroup(); Settings->endGroup();
} }
@ -253,8 +253,11 @@ void GxsGroupFrameDialog::todo()
void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point) void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
{ {
QMenu contextMnu(this);
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()));
@ -263,7 +266,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;
@ -341,6 +343,10 @@ void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
contextMnu.addSeparator(); contextMnu.addSeparator();
contextMnu.addActions(actions); contextMnu.addActions(actions);
} }
}
//Add Standard Menu
ui->groupTreeWidget->treeWidget()->createStandardContextMenu(&contextMnu);
contextMnu.exec(QCursor::pos()); contextMnu.exec(QCursor::pos());
} }