Kstars

indigroup.cpp
1/*
2 SPDX-FileCopyrightText: 2003 Jasem Mutlaq <mutlaqja@ikarustech.com>
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*******************************************************************/
27INDI_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
43bool 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
65bool 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
79INDI_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}
INDI_D represents an INDI GUI Device.
Definition indidevice.h:35
INDI_P represents a single INDI property (Switch, Text, Number, Light, or BLOB).
QString i18n(const char *text, const TYPE &arg...)
QString name(StandardAction id)
void setContentsMargins(const QMargins &margins)
void append(QList< T > &&value)
iterator begin()
iterator end()
bool removeOne(const AT &t)
QVariant property(const char *name) const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.