File indexing completed on 2024-05-05 04:05:48

0001 /*
0002     SPDX-FileCopyrightText: 2009, 2010 Stefan Majewsky <majewsky@gmx.net>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "slicerproperty.h"
0008 
0009 #include <QMutableListIterator>
0010 
0011 //BEGIN private classes
0012 
0013 class Pala::SlicerPropertyPrivate
0014 {
0015 public:
0016     SlicerPropertyPrivate(QMetaType::Type type, const QString& caption)
0017         : m_type(type)
0018         , m_caption(caption)
0019     {
0020     }
0021     virtual ~SlicerPropertyPrivate() = default;
0022 
0023     QMetaType::Type const m_type;
0024     QString m_caption;
0025     QByteArray m_key;
0026 
0027     QVariantList m_choices;
0028     QVariant m_defaultValue;
0029 
0030     bool m_advanced = false;
0031     bool m_enabled = true;
0032 };
0033 
0034 class Pala::BooleanPropertyPrivate : public Pala::SlicerPropertyPrivate
0035 {
0036 public:
0037     BooleanPropertyPrivate(QMetaType::Type type, const QString& caption)
0038         : SlicerPropertyPrivate(type, caption)
0039     {
0040     }
0041 };
0042 
0043 class Pala::IntegerPropertyPrivate : public Pala::SlicerPropertyPrivate
0044 {
0045 public:
0046     IntegerPropertyPrivate(QMetaType::Type type, const QString& caption)
0047         : SlicerPropertyPrivate(type, caption)
0048     {
0049     }
0050 
0051     QPair<int, int> m_range;
0052     Pala::IntegerProperty::Representation m_representation;
0053 };
0054 
0055 class Pala::StringPropertyPrivate : public Pala::SlicerPropertyPrivate
0056 {
0057 public:
0058     StringPropertyPrivate(QMetaType::Type type, const QString& caption)
0059         : SlicerPropertyPrivate(type, caption)
0060     {
0061     }
0062 };
0063 
0064 //END private classes
0065 
0066 //BEGIN Pala::SlicerProperty
0067 
0068 Pala::SlicerProperty::SlicerProperty(Pala::SlicerPropertyPrivate& dd)
0069     : d_ptr(&dd)
0070 {
0071 }
0072 
0073 Pala::SlicerProperty::~SlicerProperty() = default;
0074 
0075 QString Pala::SlicerProperty::caption() const
0076 {
0077     Q_D(const SlicerProperty);
0078     return d->m_caption;
0079 }
0080 
0081 QVariantList Pala::SlicerProperty::choices() const
0082 {
0083     Q_D(const SlicerProperty);
0084     return d->m_choices;
0085 }
0086 
0087 QVariant Pala::SlicerProperty::defaultValue() const
0088 {
0089     Q_D(const SlicerProperty);
0090     return d->m_defaultValue;
0091 }
0092 
0093 bool Pala::SlicerProperty::isAdvanced() const
0094 {
0095     Q_D(const SlicerProperty);
0096     return d->m_advanced;
0097 }
0098 
0099 bool Pala::SlicerProperty::isEnabled() const
0100 {
0101     Q_D(const SlicerProperty);
0102     return d->m_enabled;
0103 }
0104 
0105 QByteArray Pala::SlicerProperty::key() const
0106 {
0107     Q_D(const SlicerProperty);
0108     return d->m_key;
0109 }
0110 
0111 QMetaType::Type Pala::SlicerProperty::type() const
0112 {
0113     Q_D(const SlicerProperty);
0114     return d->m_type;
0115 }
0116 
0117 void Pala::SlicerProperty::setAdvanced(bool advanced)
0118 {
0119     Q_D(SlicerProperty);
0120     d->m_advanced = advanced;
0121 }
0122 
0123 void Pala::SlicerProperty::setChoices(const QVariantList& choices)
0124 {
0125     Q_D(SlicerProperty);
0126     d->m_choices = choices;
0127     QMutableListIterator<QVariant> iter(d->m_choices);
0128     while (iter.hasNext())
0129         iter.next().convert(QMetaType(d->m_type));
0130 }
0131 
0132 void Pala::SlicerProperty::setDefaultValue(const QVariant& value)
0133 {
0134     Q_D(SlicerProperty);
0135     d->m_defaultValue = value;
0136     d->m_defaultValue.convert(QMetaType(d->m_type));
0137 }
0138 
0139 void Pala::SlicerProperty::setEnabled(bool enabled)
0140 {
0141     Q_D(SlicerProperty);
0142     d->m_enabled = enabled;
0143 }
0144 
0145 void Pala::SlicerProperty::setKey(const QByteArray& key)
0146 {
0147     Q_D(SlicerProperty);
0148     d->m_key = key;
0149 }
0150 
0151 //END Pala::SlicerProperty
0152 
0153 //BEGIN concrete implementations
0154 
0155 Pala::BooleanProperty::BooleanProperty(const QString& caption)
0156     : Pala::SlicerProperty(*new Pala::BooleanPropertyPrivate(QMetaType::Bool, caption))
0157 {
0158 }
0159 
0160 Pala::BooleanProperty::~BooleanProperty() = default;
0161 
0162 Pala::IntegerProperty::IntegerProperty(const QString& caption)
0163     : Pala::SlicerProperty(*new Pala::IntegerPropertyPrivate(QMetaType::Int, caption))
0164 {
0165     Q_D(IntegerProperty);
0166     d->m_range.first = d->m_range.second = 0;
0167     d->m_representation = Pala::IntegerProperty::DefaultRepresentation;
0168 }
0169 
0170 Pala::IntegerProperty::~IntegerProperty() = default;
0171 
0172 QPair<int, int> Pala::IntegerProperty::range() const
0173 {
0174     Q_D(const IntegerProperty);
0175     return d->m_range;
0176 }
0177 
0178 Pala::IntegerProperty::Representation Pala::IntegerProperty::representation() const
0179 {
0180     Q_D(const IntegerProperty);
0181     return d->m_representation;
0182 }
0183 
0184 void Pala::IntegerProperty::setRange(int min, int max)
0185 {
0186     Q_D(IntegerProperty);
0187     d->m_range.first = min;
0188     d->m_range.second = max;
0189 }
0190 
0191 void Pala::IntegerProperty::setRepresentation(Pala::IntegerProperty::Representation representation)
0192 {
0193     Q_D(IntegerProperty);
0194     d->m_representation = representation;
0195 }
0196 
0197 Pala::StringProperty::StringProperty(const QString& caption)
0198     : Pala::SlicerProperty(*new Pala::StringPropertyPrivate(QMetaType::QString, caption))
0199 {
0200 }
0201 
0202 Pala::StringProperty::~StringProperty() = default;
0203 
0204 //END concrete implementations