1 /***************************************************************************
2 * Copyright (C) 2009 by Lassi Väätämöinen *
3 * lassi.vaatamoinen@ixonos.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include <QGridLayout>
22 #include <QTreeWidgetItem>
24 #include <QDialogButtonBox>
25 #include <QAbstractButton>
27 #include "ColumnSelectorDialog.h"
30 ColumnSelectorDialog::ColumnSelectorDialog(QTreeWidget *treewidget, QWidget* parent, Qt::WindowFlags f) :
31 QDialog(parent, f), // Superclass construct
34 treeWidget_(treewidget),
37 QBoxLayout *verticalBox = new QBoxLayout(QBoxLayout::TopToBottom);
38 grid_ = new QGridLayout;
39 QCheckBox *cbox = NULL;
41 setLayout(verticalBox);
42 verticalBox->addLayout(grid_);
44 if (treeWidget_ != NULL) {
45 QTreeWidgetItem *item = treeWidget_->headerItem();
47 for (unsigned i = 0; i < item->columnCount(); ++i) {
48 cbox = new QCheckBox(item->text(i));
49 grid_->addWidget(cbox, i, 0);
50 treeWidget_->isColumnHidden(i) ? cbox->setCheckState(Qt::Unchecked) : cbox->setCheckState(Qt::Checked);
51 checkBoxes_.push_back(cbox);
56 dialogButtons_ = new QDialogButtonBox(this);
57 dialogButtons_->setStandardButtons(QDialogButtonBox::Ok
58 | QDialogButtonBox::Cancel);
60 verticalBox->addWidget(dialogButtons_);
62 connect(dialogButtons_, SIGNAL(clicked(QAbstractButton*)),
63 this, SLOT(on_buttonClicked(QAbstractButton*)));
67 ColumnSelectorDialog::~ColumnSelectorDialog()
72 void ColumnSelectorDialog::on_buttonClicked(QAbstractButton *button)
74 switch (dialogButtons_->buttonRole ( button ) ) {
75 case QDialogButtonBox::AcceptRole :
77 done(QDialog::Accepted);
79 case QDialogButtonBox::ApplyRole :
81 done(QDialog::Accepted);
83 case QDialogButtonBox::RejectRole :
84 done(QDialog::Rejected);
92 void ColumnSelectorDialog::ApplySettings()
94 if (treeWidget_ != NULL) {
95 QTreeWidgetItem *item = treeWidget_->headerItem();
96 QCheckBox *cbox = NULL;
98 for (unsigned i = 0; i < checkBoxes_.size(); ++i) {
99 cbox = checkBoxes_.at(i);
100 cbox->isChecked() ? treeWidget_->showColumn(i) : treeWidget_->hideColumn(i);