1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
//##########################################################################
//# #
//# CLOUDCOMPARE #
//# #
//# This program is free software; you can redistribute it and/or modify #
//# it under the terms of the GNU General Public License as published by #
//# the Free Software Foundation; version 2 or later of the License. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU General Public License for more details. #
//# #
//# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
//# #
//##########################################################################
#include "ccColorScaleSelector.h"
//Qt
#include <QHBoxLayout>
#include <QComboBox>
#include <QToolButton>
//Local
#include "ccColorScalesManager.h"
ccColorScaleSelector::ccColorScaleSelector(ccColorScalesManager* manager, QWidget* parent, QString defaultButtonIconPath/*=QString()*/)
: QFrame(parent)
, m_manager(manager)
, m_comboBox(new QComboBox())
, m_button(new QToolButton())
{
assert(m_manager);
setLayout(new QHBoxLayout());
layout()->setContentsMargins(0, 0, 0, 0);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
//combox box
if (m_comboBox)
{
layout()->addWidget(m_comboBox);
}
//tool button
if (m_button)
{
m_button->setIcon(QIcon(defaultButtonIconPath));
layout()->addWidget(m_button);
}
}
void ccColorScaleSelector::init()
{
//fill combox box
if (m_comboBox)
{
m_comboBox->disconnect(this);
m_comboBox->clear();
//add all available color scales
assert(m_manager);
//sort the scales by their name
//DGM: See doc about qSort --> "An alternative to using qSort() is to put the items to sort in a QMap, using the sort key as the QMap key."
QMap<QString, QString> scales;
for (ccColorScalesManager::ScalesMap::const_iterator it = m_manager->map().constBegin(); it != m_manager->map().constEnd(); ++it)
{
scales.insert((*it)->getName(), (*it)->getUuid());
}
for (QMap<QString, QString>::const_iterator scale = scales.constBegin(); scale != scales.constEnd(); ++scale)
{
m_comboBox->addItem(scale.key(), scale.value());
}
connect(m_comboBox, SIGNAL(activated(int)), this, SIGNAL(colorScaleSelected(int)));
}
//advanced tool button
if (m_button)
{
m_button->disconnect(this);
connect(m_button, SIGNAL(clicked()), this, SIGNAL(colorScaleEditorSummoned()));
}
}
ccColorScale::Shared ccColorScaleSelector::getSelectedScale() const
{
return getScale(m_comboBox ? m_comboBox->currentIndex() : -1);
}
ccColorScale::Shared ccColorScaleSelector::getScale(int index) const
{
if (!m_comboBox || index < 0 || index >= m_comboBox->count())
return ccColorScale::Shared(0);
//get UUID associated to the combo-box item
QString UUID = m_comboBox->itemData(index).toString();
return m_manager ? m_manager->getScale(UUID) : ccColorScale::Shared(0);
}
void ccColorScaleSelector::setSelectedScale(QString uuid)
{
if (!m_comboBox)
return;
//search right index by UUID
int pos = m_comboBox->findData(uuid);
if (pos < 0)
return;
m_comboBox->setCurrentIndex(pos);
emit colorScaleSelected(pos);
}
|