Colour map widget gets band names and descriptions from the imagery data object,...
[tecorrec.git] / tcColourMapWidget.cpp
blob202d2bf92b82ef032955e879870dd10d1f2834a6
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 <QRadioButton>
34 * Constructors + destructor
37 /// Construct with colour information.
38 tcColourMapWidget::tcColourMapWidget(const QStringList& outputBands, QWidget* parent)
39 : QScrollArea(parent)
40 , m_layout(0)
41 , m_signalMapper(new QSignalMapper(this))
42 , m_outputBandButtonGroups()
43 , m_numInputBands(0)
45 QWidget* widget = new QWidget(this);
46 m_layout = new QGridLayout(widget);
47 setWidget(widget);
48 setWidgetResizable(true);
50 foreach (QString band, outputBands)
52 QButtonGroup* buttonGroup = new QButtonGroup(this);
53 connect(buttonGroup, SIGNAL(buttonClicked(int)), m_signalMapper, SLOT(map()));
54 m_signalMapper->setMapping(buttonGroup, m_outputBandButtonGroups.size());
55 m_outputBandButtonGroups << buttonGroup;
57 m_layout->addWidget(new QLabel(band, this), 0, m_outputBandButtonGroups.size(), Qt::AlignHCenter);
59 connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(inputBandChangedSlot(int)));
62 /// Destructor.
63 tcColourMapWidget::~tcColourMapWidget()
68 * Main interface
71 /// Clear bands.
72 void tcColourMapWidget::clearInputBands()
76 /// Add an input band.
77 void tcColourMapWidget::addInputBand(const QString& name, const QString& description)
79 ++m_numInputBands;
80 QLabel* mainLabel = new QLabel(name, this);
81 mainLabel->setToolTip(description);
82 m_layout->addWidget(mainLabel, m_numInputBands, 0);
83 for (int i = 0; i < m_outputBandButtonGroups.size(); ++i)
85 QRadioButton* radio = new QRadioButton(this);
86 m_outputBandButtonGroups[i]->addButton(radio, m_numInputBands-1);
87 m_layout->addWidget(radio, m_numInputBands, 1 + i, Qt::AlignHCenter);
92 * Accessors
95 /// Get the index of the input band assigned to an output band.
96 int tcColourMapWidget::inputBand(int outputBand) const
98 return m_outputBandButtonGroups[outputBand]->checkedId();
102 * Public slots
105 /// Set the input band assigned to an output.
106 void tcColourMapWidget::setInputBand(int output, int input)
108 m_outputBandButtonGroups[output]->button(input)->setChecked(true);
112 * Private slots
115 /// Indicates that the input band assigned to an output has changed.
116 void tcColourMapWidget::inputBandChangedSlot(int output)
118 emit inputBandChanged(output, m_outputBandButtonGroups[output]->checkedId());