ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvColorScaleSelector.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 // Qt
11 #include <QComboBox>
12 #include <QHBoxLayout>
13 #include <QToolButton>
14 
15 // Local
16 #include "ecvColorScalesManager.h"
17 
19  ccColorScalesManager* manager,
20  QWidget* parent,
21  QString defaultButtonIconPath /*=QString()*/)
22  : QFrame(parent),
23  m_manager(manager),
24  m_comboBox(new QComboBox()),
25  m_button(new QToolButton()) {
26  assert(m_manager);
27 
28  setLayout(new QHBoxLayout());
29  layout()->setContentsMargins(0, 0, 0, 0);
30  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
31 
32  // combox box
33  if (m_comboBox) {
34  layout()->addWidget(m_comboBox);
35  }
36 
37  // tool button
38  if (m_button) {
39  m_button->setIcon(QIcon(defaultButtonIconPath));
40  layout()->addWidget(m_button);
41  }
42 }
43 
45  // fill combox box
46  if (m_comboBox) {
47  m_comboBox->disconnect(this);
48 
49  m_comboBox->clear();
50  // add all available color scales
51  assert(m_manager);
52 
53  // sort the scales by their name
54  // DGM: See doc about qSort --> "An alternative to using qSort() is to
55  // put the items to sort in a QMap, using the sort key as the QMap key."
56  QMap<QString, QString> scales;
57  for (ccColorScalesManager::ScalesMap::const_iterator it =
58  m_manager->map().constBegin();
59  it != m_manager->map().constEnd(); ++it) {
60  scales.insert((*it)->getName(), (*it)->getUuid());
61  }
62 
63  for (QMap<QString, QString>::const_iterator scale = scales.constBegin();
64  scale != scales.constEnd(); ++scale) {
65  m_comboBox->addItem(scale.key(), scale.value());
66  }
67 
68  connect(m_comboBox, SIGNAL(activated(int)), this,
69  SIGNAL(colorScaleSelected(int)));
70  }
71  // advanced tool button
72  if (m_button) {
73  m_button->disconnect(this);
74  connect(m_button, SIGNAL(clicked()), this,
75  SIGNAL(colorScaleEditorSummoned()));
76  }
77 }
78 
80  return getScale(m_comboBox ? m_comboBox->currentIndex() : -1);
81 }
82 
84  if (!m_comboBox || index < 0 || index >= m_comboBox->count())
85  return ccColorScale::Shared(0);
86 
87  // get UUID associated to the combo-box item
88  QString UUID = m_comboBox->itemData(index).toString();
89 
90  return m_manager ? m_manager->getScale(UUID) : ccColorScale::Shared(0);
91 }
92 
94  if (!m_comboBox) return;
95 
96  // search right index by UUID
97  int pos = m_comboBox->findData(uuid);
98  if (pos < 0) return;
99  m_comboBox->setCurrentIndex(pos);
100 
101  emit colorScaleSelected(pos);
102 }
void colorScaleSelected(int)
Signal emitted when a color scale is selected.
ccColorScaleSelector(ccColorScalesManager *manager, QWidget *parent, QString defaultButtonIconPath=QString())
Default constructor.
void init()
Inits selector with the Color Scales Manager.
void setSelectedScale(QString uuid)
Sets selected combo box item (scale) by UUID.
ccColorScalesManager * m_manager
Color scales manager.
QComboBox * m_comboBox
Color scales combo-box.
void colorScaleEditorSummoned()
QToolButton * m_button
Spawn color scale editor button.
ccColorScale::Shared getScale(int index) const
Returns a given color scale by index.
ccColorScale::Shared getSelectedScale() const
Returns currently selected color scale.
QSharedPointer< ccColorScale > Shared
Shared pointer type.
Definition: ecvColorScale.h:74
Color scales manager/container.
ccColorScale::Shared getScale(QString UUID) const
Returns a color scale based on its UUID.
ScalesMap & map()
Access to the internal map.
Tensor Maximum(const Tensor &input, const Tensor &other)
Computes the element-wise maximum of input and other. The tensors must have same data type and device...