Kstars

indigroup.cpp
1 /*
2  SPDX-FileCopyrightText: 2003 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "indigroup.h"
8 #include "indiproperty.h"
9 #include "indidevice.h"
10 
11 #include <QLocale>
12 #include <QDialog>
13 
14 #include <QFrame>
15 #include <QTabWidget>
16 #include <QVBoxLayout>
17 #include <QDebug>
18 #include <QScrollArea>
19 
20 #include <KLocalizedString>
21 
22 /*******************************************************************
23 ** INDI Group: a tab widget for common properties. All properties
24 ** belong to a group, whether they have one or not but how the group
25 ** is displayed differs
26 *******************************************************************/
27 INDI_G::INDI_G(INDI_D *idv, const QString &inName) : QScrollArea(idv)
28 {
29  dp = idv;
30  name = (inName.isEmpty()) ? i18n("Unknown") : inName;
31 
32  m_PropertiesContainer = new QFrame(this);
33  m_PropertiesLayout = new QVBoxLayout;
34  m_PropertiesLayout->setContentsMargins(20, 20, 20, 20);
35  m_VerticalSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
36  m_PropertiesLayout->addItem(m_VerticalSpacer);
37  m_PropertiesLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
38  m_PropertiesContainer->setLayout(m_PropertiesLayout);
39 
40  setWidget(m_PropertiesContainer);
41 }
42 
43 bool INDI_G::addProperty(INDI::Property newProperty)
44 {
45  if (!newProperty.isValid())
46  return false;
47 
48  QString name(newProperty.getName());
49 
50  // No duplicates
51  if (getProperty(name))
52  return false;
53 
54  INDI_P *property = new INDI_P(this, newProperty);
55  m_PropertiesList.append(property);
56 
57  m_PropertiesLayout->removeItem(m_VerticalSpacer);
58  m_PropertiesLayout->addWidget(property);
59  m_PropertiesLayout->addItem(m_VerticalSpacer);
60  m_PropertiesLayout->invalidate();
61 
62  return true;
63 }
64 
65 bool INDI_G::removeProperty(const QString &name)
66 {
67  INDI_P *oneProp = getProperty(name);
68  if (oneProp)
69  {
70  m_PropertiesList.removeOne(oneProp);
71  delete (oneProp);
72  m_Dirty = true;
73  return true;
74  }
75 
76  return false;
77 }
78 
79 INDI_P *INDI_G::getProperty(const QString &name) const
80 {
81  auto pos = std::find_if(m_PropertiesList.begin(), m_PropertiesList.end(), [name](INDI_P * oneProperty)
82  {
83  return oneProperty->getName() == name;
84  });
85  if (pos != m_PropertiesList.end())
86  return *pos;
87  else
88  return nullptr;
89 }
QString i18n(const char *text, const TYPE &arg...)
bool isEmpty() const const
QCA_EXPORT QVariant getProperty(const QString &name)
QString name(StandardShortcut id)
void setContentsMargins(int left, int top, int right, int bottom)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.