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 #ifndef LIBPALA_SLICERPROPERTY_H
0008 #define LIBPALA_SLICERPROPERTY_H
0009 
0010 #include "libpala_export.h"
0011 
0012 #include <QPair>
0013 #include <QVariant>
0014 #include <QVariantList>
0015 
0016 #include <memory>
0017 
0018 namespace Pala
0019 {
0020     class SlicerPropertyPrivate;
0021 
0022     /**
0023      * \class SlicerProperty slicerproperty.h <Pala/SlicerProperty>
0024      * \brief Representation of a single configurable parameter of a slicing algorithm.
0025      *
0026      * Slicer properties describe configurable parameters of slicing algorithms (i.e. Pala::Slicer instances) in a presentation-agnostic way. They do not store any user-generated values, they just describe the possible input forms.
0027      *
0028      * \note This is an abstract base class. Use the subclasses provided by this library. Defining own subclasses outside libpala is senseless, because Palapeli needs to know about them to use them correctly and to their full extent.
0029      *
0030      * \sa Pala::Slicer::addProperty, Pala::AbstractSlicerPropertySet
0031      */
0032     class LIBPALA_EXPORT SlicerProperty
0033     {
0034         protected:
0035             explicit SlicerProperty(Pala::SlicerPropertyPrivate& dd);
0036         public:
0037             ///Deletes this slicer property.
0038             virtual ~SlicerProperty();
0039 
0040             //The following functions belong to the interface to the Palapeli application. They are not documented because the documentation is targeted at slicer developers.
0041             ///\internal
0042             QString caption() const;
0043             ///\internal
0044             QVariantList choices() const;
0045             ///\internal
0046             QVariant defaultValue() const;
0047             ///\internal
0048             ///\since libpala 1.2 (KDE SC 4.6)
0049             bool isAdvanced() const;
0050             ///\internal
0051             ///\since libpala 1.2 (KDE SC 4.6)
0052             bool isEnabled() const;
0053             ///\internal
0054             ///\since libpala 1.2 (KDE SC 4.6)
0055             QByteArray key() const;
0056             ///\internal
0057             ///\since libpala 1.2 (KDE SC 4.6)
0058             void setKey(const QByteArray& key);
0059             ///\internal
0060             QMetaType::Type type() const;
0061 
0062             ///Sets whether this property is advanced (false by default). If it is set, Palapeli is allowed to hide the property widget from the puzzle creation interface unless an "Advanced" button is pressed (or similar).
0063             ///\since libpala 1.2 (KDE SC 4.6)
0064             void setAdvanced(bool advanced = true);
0065             ///Limits the user input to the selection of one of the given values. The first value in the given list will be the default.
0066             ///\warning This setting will override any other constraints to the user input, including the default value defined by setDefaultValue().
0067             void setChoices(const QVariantList& choices);
0068             ///Sets the default value of this property.
0069             void setDefaultValue(const QVariant& value);
0070             ///Sets whether this property is enabled (true by default). If you do not use multiple slicer modes (see Pala::Slicer::addSlicerMode), setting this to false is senseless. On the other hand, if you do use multiple slicer modes and have certain properties which are only useful in single modes, you probably want to set this to false, and enable the property in the relevant slicer modes using the Pala::SlicerMode::setPropertyEnabled method.
0071             ///\since libpala 1.2 (KDE SC 4.6)
0072             void setEnabled(bool enabled);
0073         protected:
0074             std::unique_ptr<SlicerPropertyPrivate> const d_ptr;
0075         private:
0076             Q_DECLARE_PRIVATE(SlicerProperty)
0077             Q_DISABLE_COPY(SlicerProperty)
0078     };
0079 
0080     class BooleanPropertyPrivate;
0081     /**
0082      * \class BooleanProperty slicerproperty.h <Pala/SlicerProperty>
0083      */
0084     class LIBPALA_EXPORT BooleanProperty : public Pala::SlicerProperty
0085     {
0086         public:
0087             explicit BooleanProperty(const QString& caption);
0088             ~BooleanProperty() override;
0089         private:
0090             Q_DECLARE_PRIVATE(BooleanProperty)
0091     };
0092 
0093     class IntegerPropertyPrivate;
0094     /**
0095      * \class IntegerProperty slicerproperty.h <Pala/SlicerProperty>
0096      */
0097     class LIBPALA_EXPORT IntegerProperty : public Pala::SlicerProperty
0098     {
0099         public:
0100             ///Decides how the property is represented in the user interface of Palapeli.
0101             enum Representation { SpinBox, Slider, DefaultRepresentation = SpinBox };
0102 
0103             explicit IntegerProperty(const QString& caption);
0104             ~IntegerProperty() override;
0105 
0106             ///\internal
0107             QPair<int, int> range() const;
0108             ///\internal
0109             Representation representation() const;
0110 
0111             ///Limits the user input to the selection of a number inside the given range (including the bounds).
0112             void setRange(int min, int max);
0113             ///Decides how the property is represented in the user interface of Palapeli.
0114             void setRepresentation(Representation representation);
0115         private:
0116             Q_DECLARE_PRIVATE(IntegerProperty)
0117     };
0118 
0119     class StringPropertyPrivate;
0120     /**
0121      * \class StringProperty slicerproperty.h <Pala/SlicerProperty>
0122      */
0123     class LIBPALA_EXPORT StringProperty : public Pala::SlicerProperty
0124     {
0125         public:
0126             explicit StringProperty(const QString& caption);
0127             ~StringProperty() override;
0128         private:
0129             Q_DECLARE_PRIVATE(StringProperty)
0130     };
0131 }
0132 
0133 #endif // LIBPALA_SLICERPROPERTY_H