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_UNREAD 1
#define COLUMN_POPULARITY 2
#define COLUMN_COUNT 3
#define COLUMN_LAST_POST 3
#define COLUMN_COUNT 4
#define COLUMN_DATA COLUMN_NAME
#define ROLE_ID Qt::UserRole
@ -100,9 +101,12 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
/* Initialize tree widget */
ui->treeWidget->setColumnCount(COLUMN_COUNT);
ui->treeWidget->enableColumnCustomize(true);
ui->treeWidget->setColumnCustomizable(COLUMN_NAME, false);
int S = QFontMetricsF(font()).height() ;
int W = QFontMetricsF(font()).width("999") ;
int D = QFontMetricsF(font()).width("9999-99-99[]") ;
/* Set header resize modes and initial section sizes */
QHeaderView *header = ui->treeWidget->header ();
@ -113,6 +117,15 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
header->resizeSection(COLUMN_UNREAD, W+4) ;
QHeaderView_setSectionResizeModeColumn(header, COLUMN_POPULARITY, QHeaderView::Fixed);
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 */
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);
}
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;
}
@ -204,16 +218,18 @@ void GroupTreeWidget::processSettings(RshareSettings *settings, bool load)
const int SORTBY_POSTS = 4;
const int SORTBY_UNREAD = 5;
ui->treeWidget->processSettings(load);
if (load) {
// load settings
// load Settings
// state of order
bool ascSort = settings->value("GroupAscSort", true).toBool();
bool ascSort = Settings->value("GroupAscSort", true).toBool();
actionSortAscending->setChecked(ascSort);
actionSortDescending->setChecked(!ascSort);
// state of sort
int sortby = settings->value("GroupSortBy").toInt();
int sortby = Settings->value("GroupSortBy").toInt();
switch (sortby) {
case SORTBY_NAME:
if (actionSortByName) {
@ -242,10 +258,10 @@ void GroupTreeWidget::processSettings(RshareSettings *settings, bool load)
break;
}
} else {
// save settings
// save Settings
// state of order
settings->setValue("GroupAscSort", !(actionSortDescending && actionSortDescending->isChecked())); //True by default
Settings->setValue("GroupAscSort", !(actionSortDescending && actionSortDescending->isChecked())); //True by default
// state of sort
int sortby = SORTBY_NAME;
@ -260,7 +276,7 @@ void GroupTreeWidget::processSettings(RshareSettings *settings, bool load)
} else if (actionSortByUnread && actionSortByUnread->isChecked()) {
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 */
qlonglong lastPost = itemInfo.lastpost.toTime_t();
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 */
item->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting