Skip to content

Commit

Permalink
Added option: Restore default columns in the mail table.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulEU committed Mar 23, 2014
1 parent a882c43 commit 6745ea3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
52 changes: 42 additions & 10 deletions Mail/MailTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,44 @@ void MailTable::setupActions()
{
for (uint i = 0; i < MailboxModel::NumColumns; ++i)
{
// Do not let hide the column Subject
if (i != MailboxModel::Subject)
{
initializeAction ( static_cast<MailboxModel::Columns>(i) );
}
initializeAction ( static_cast<MailboxModel::Columns>(i) );
}

QAction* sep = new QAction(this);
sep->setSeparator(true);
QAction* restoreDefaultColumns = new QAction(tr("Restore default"), this);

horizontalHeader()->addAction(sep);
horizontalHeader()->addAction(restoreDefaultColumns);
connect(restoreDefaultColumns, &QAction::triggered,
this, &MailTable::onRestoreDefaultColumns);
}

void MailTable::initializeAction(MailboxModel::Columns columnType)
{
const QAbstractItemModel *model = this->model();
QString columnName = model->headerData (columnType,
Qt::Horizontal, Qt::DisplayRole).toString();
QString columnName = model->headerData (columnType, Qt::Horizontal,
Qt::DisplayRole).toString();
if (columnName.isEmpty())
{
// when column name is empty call getDefaultActionName.
// Case for the column e.g. "Read", "Money"
columnName = getDefaultActionName(columnType);
}
ShowColumnAction* action = new ShowColumnAction(columnName, this, columnType,
isColumnHidden(columnType) == false);

connect(action, SIGNAL( showColumn(bool, MailboxModel::Columns) ),
ShowColumnAction *action =
new ShowColumnAction(columnName, this, columnType,
isColumnHidden(columnType) == false);
// Do not let hide the column Subject.
// That although one column was visible.
if (columnType == MailboxModel::Subject)
{
action->setVisible(false);
}

_columnActionArray[columnType] = action;

connect(action, SIGNAL( showColumn(bool, MailboxModel::Columns) ),
this, SLOT( onShowColumn(bool, MailboxModel::Columns) ));

//add actions to horizontal header
Expand Down Expand Up @@ -110,4 +125,21 @@ QString MailTable::getDefaultActionName(MailboxModel::Columns columnType)
void MailTable::onShowColumn(bool visible, MailboxModel::Columns column)
{
setColumnHidden(column, visible == false);
}

void MailTable::onRestoreDefaultColumns()
{
QHeaderView *horHeader = horizontalHeader();

for (uint i = 0; i < MailboxModel::NumColumns; ++i)
{
horHeader->hideSection (i);
_columnActionArray[i]->setChecked(false);
}

for (const auto column : _defaultColumns)
{
horHeader->showSection (column);
_columnActionArray[column]->setChecked(true);
}
}
5 changes: 4 additions & 1 deletion Mail/MailTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class MailTable : public QTableView
private slots:
/// \see ShowColumnAction::showColumn signal description.
void onShowColumn(bool visible, MailboxModel::Columns column);
/// Show default columns in the current mail box
void onRestoreDefaultColumns();

private:
void setupActions();
Expand All @@ -38,5 +40,6 @@ private slots:
QString getDefaultActionName(MailboxModel::Columns columnType);

private:
QList<MailboxModel::Columns> _defaultColumns;
QList<MailboxModel::Columns> _defaultColumns;
ShowColumnAction* _columnActionArray[MailboxModel::NumColumns];
};

0 comments on commit 6745ea3

Please sign in to comment.