Elevation correction triggers signal to refresh DEM channels if they depend on it
[tecorrec.git] / tcColourMapWidget.cpp
blobea521d83dc69eefbcc5fbc3a431a334fa26fb874
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec 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. *
9 * *
10 * Tecorrec 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. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file tcColourMapWidget.cpp
22 * @brief Colour mapping widget.
25 #include "tcColourMapWidget.h"
27 #include <QGridLayout>
28 #include <QButtonGroup>
29 #include <QSignalMapper>
30 #include <QLabel>
31 #include <QPushButton>
32 #include <QRadioButton>
35 * Constructors + destructor
38 /// Construct with colour information.
39 tcColourMapWidget::tcColourMapWidget(const QStringList& outputBands, QWidget* parent)
40 : QScrollArea(parent)
41 , m_layout(0)
42 , m_inputSignalMapper(new QSignalMapper(this))
43 , m_groupSignalMapper(new QSignalMapper(this))
44 , m_outputBandButtonGroups()
45 , m_numInputBands(0)
47 QWidget* widget = new QWidget(this);
48 m_layout = new QGridLayout(widget);
49 setWidget(widget);
50 setWidgetResizable(true);
52 foreach (QString band, outputBands)
54 QButtonGroup* buttonGroup = new QButtonGroup(this);
55 connect(buttonGroup, SIGNAL(buttonClicked(int)), m_groupSignalMapper, SLOT(map()));
56 m_groupSignalMapper->setMapping(buttonGroup, m_outputBandButtonGroups.size());
57 m_outputBandButtonGroups << buttonGroup;
59 m_layout->addWidget(new QLabel(band, this), 0, m_outputBandButtonGroups.size(), Qt::AlignHCenter);
61 connect(m_groupSignalMapper, SIGNAL(mapped(int)), this, SLOT(inputBandChangedSlot(int)));
62 connect(m_inputSignalMapper, SIGNAL(mapped(int)), this, SIGNAL(inputBandClicked(int)));
65 /// Destructor.
66 tcColourMapWidget::~tcColourMapWidget()
71 * Main interface
74 /// Clear bands.
75 void tcColourMapWidget::clearInputBands()
79 /// Add an input band.
80 void tcColourMapWidget::addInputBand(const QString& name, const QString& description)
82 ++m_numInputBands;
83 QPushButton* mainLabel = new QPushButton(name, this);
84 mainLabel->setToolTip(description);
85 m_layout->addWidget(mainLabel, m_numInputBands, 0);
86 connect(mainLabel, SIGNAL(clicked()), m_inputSignalMapper, SLOT(map()));
87 m_inputSignalMapper->setMapping(mainLabel, m_numInputBands-1);
88 for (int i = 0; i < m_outputBandButtonGroups.size(); ++i)
90 QRadioButton* radio = new QRadioButton(this);
91 m_outputBandButtonGroups[i]->addButton(radio, m_numInputBands-1);
92 m_layout->addWidget(radio, m_numInputBands, 1 + i, Qt::AlignHCenter);
97 * Accessors
100 /// Get the index of the input band assigned to an output band.
101 int tcColourMapWidget::inputBand(int outputBand) const
103 return m_outputBandButtonGroups[outputBand]->checkedId();
107 * Public slots
110 /// Set the input band assigned to an output.
111 void tcColourMapWidget::setInputBand(int output, int input)
113 m_outputBandButtonGroups[output]->button(input)->setChecked(true);
117 * Private slots
120 /// Indicates that the input band assigned to an output has changed.
121 void tcColourMapWidget::inputBandChangedSlot(int output)
123 emit inputBandChanged(output, m_outputBandButtonGroups[output]->checkedId());