libdrmconf 0.13.3
A library to program DMR radios.
Loading...
Searching...
No Matches
radiolimits.hh
1
29#ifndef RADIOLIMITS_HH
30#define RADIOLIMITS_HH
31
32#include <QObject>
33#include <QRegularExpression>
34#include <QTextStream>
35#include <QMetaType>
36#include <QSet>
37
38#include "frequency.hh"
39#include "ranges.hh"
40
41// Forward declaration
42class Config;
43class ConfigItem;
44class ConfigObject;
45class RadioLimits;
46
47
50class RadioLimitIssue: public QTextStream
51{
52public:
60
61public:
64 RadioLimitIssue(Severity severity, const QStringList &stack);
66 RadioLimitIssue(const RadioLimitIssue &other);
67
71 RadioLimitIssue &operator =(const QString &message);
72
74 Severity severity() const;
76 const QString &message() const;
78 const QStringList &stack() const;
80 QString format() const;
81
82protected:
86 QStringList _stack;
88 QString _message;
89};
90
91
97{
98public:
100 explicit RadioLimitContext(bool ignoreFrequencyLimits=false);
101
104
106 int count() const;
108 const RadioLimitIssue &message(int n) const;
109
112 void push(const QString &element);
114 void pop();
115
117 bool ignoreFrequencyLimits() const;
119 void enableIgnoreFrequencyLimits(bool enable=true);
120
123
124protected:
126 QStringList _stack;
128 QList<RadioLimitIssue> _messages;
133};
134
135
139class RadioLimitElement: public QObject
140{
141 Q_OBJECT
142
143public:
145 typedef std::initializer_list< std::pair<QString, RadioLimitElement *> > PropList;
146
147protected:
149 explicit RadioLimitElement(QObject *parent=nullptr);
150
151public:
154 virtual bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const = 0;
155
156public:
158 virtual ~RadioLimitElement();
159};
160
161
167{
168 Q_OBJECT
169
170protected:
173 QObject *parent=nullptr);
174
175protected:
178};
179
180
188{
189 Q_OBJECT
190
191public:
198
199public:
205 RadioLimitString(int minLen, int maxLen, Encoding enc,
207 QObject *parent=nullptr);
208
209 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
210
211protected:
218};
219
220
224{
225 Q_OBJECT
226
227public:
232 RadioLimitStringRegEx(const QString &pattern,
234 QObject *parent=nullptr);
235
236 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
237
238protected:
240 QRegularExpression _pattern;
241};
242
243
248 Q_OBJECT
249
250public:
253
254 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
255};
256
257
261{
262 Q_OBJECT
263
264public:
266 explicit RadioLimitBool(QObject *parent=nullptr);
267
268 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
269};
270
271
276{
277 Q_OBJECT
278
279public:
284 QObject *parent=nullptr);
285
286 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
287
288protected:
291};
292
293
297{
298 Q_OBJECT
299
300public:
306 RadioLimitUInt(qint64 minValue=-1, qint64 maxValue=-1, qint64 defValue=-1,
308 QObject *parent=nullptr);
309
310 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
311
312protected:
314 qint64 _minValue;
316 qint64 _maxValue;
318 qint64 _defValue;
319};
320
321
326{
327 Q_OBJECT
328
329public:
333 QObject *parent=nullptr);
334};
335
336
340{
341 Q_OBJECT
342
343public:
345 RadioLimitEnum(const std::initializer_list<unsigned> &values,
347 QObject *parent=nullptr);
348
349 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
350
351protected:
353 QSet<unsigned> _values;
354};
355
356
360{
361 Q_OBJECT
362
363public:
365 typedef std::initializer_list<std::pair<Frequency, Frequency>> RangeList;
366
367public:
370 QObject *parent=nullptr);
372 RadioLimitFrequencies(const RangeList &ranges,
374 QObject *parent=nullptr);
375
376 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
377
378protected:
380 QList<FrequencyRange> _frequencyRanges;
381};
382
383
388{
389 Q_OBJECT
390
391public:
394 QObject *parent=nullptr);
398 QObject *parent=nullptr);
399
400 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
401};
402
403
411{
412 Q_OBJECT
413
414public:
416 explicit RadioLimitItem(QObject *parent=nullptr);
419 RadioLimitItem(const PropList &list, QObject *parent=nullptr);
420
429 bool add(const QString &prop, RadioLimitElement *structure);
430
431 virtual bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
433 virtual bool verifyItem(const ConfigItem *item, RadioLimitContext &context) const;
434
435protected:
437 QHash<QString, RadioLimitElement *> _elements;
438};
439
440
444{
445 Q_OBJECT
446
447public:
449 explicit RadioLimitObject(QObject *parent=nullptr);
452 RadioLimitObject(const PropList &list, QObject *parent=nullptr);
453
455 virtual bool verifyObject(const ConfigObject *item, RadioLimitContext &context) const;
456};
457
458
466{
467 Q_OBJECT
468
469public:
472
473 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
474 bool verifyObject(const ConfigObject *item, RadioLimitContext &context) const;
475
476protected:
479};
480
481
490{
491 Q_OBJECT
492
493public:
495 typedef std::initializer_list<std::pair<const QMetaObject&, RadioLimitObject *> > TypeList;
496
497public:
516 RadioLimitObjects(const TypeList &list, QObject *parent=nullptr);
517
518 bool verifyItem(const ConfigItem *item, RadioLimitContext &context) const;
519
520protected:
522 QHash<QString, RadioLimitObject *> _types;
523};
524
525
529{
530 Q_OBJECT
531
532public:
534 typedef std::initializer_list<QMetaObject> MetaObjectList;
535
536public:
541 RadioLimitObjRef(const QMetaObject &type, bool allowNull=true, QObject *parent=nullptr);
542
547 RadioLimitObjRef(const MetaObjectList &types, bool allowNull=true, QObject *parent=nullptr);
548
549 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
550
551protected:
553 bool validType(const QMetaObject *type) const;
554
555protected:
559 QSet<QString> _types;
560};
561
562
566{
567 Q_OBJECT
568
569public:
576 QObject *parent=nullptr);
577
578 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
579
580protected:
585};
586
587
591{
592 Q_OBJECT
593
594public:
597 const QMetaObject &type;
601 };
602
603public:
611 RadioLimitList(const QMetaObject &type, int minSize, int maxSize, RadioLimitObject *element, QObject *parent=nullptr);
613 RadioLimitList(const std::initializer_list<ElementLimits> &elements, QObject *parent=nullptr);
614
615 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
616
617protected:
619 QString findClassName(const QMetaObject &type) const;
620
621protected:
623 QHash<QString, RadioLimitObject *> _elements;
625 QHash<QString, qint64> _minCount;
627 QHash<QString, qint64> _maxCount;
628};
629
630
634{
635 Q_OBJECT
636
637public:
643 RadioLimitRefList(int minSize, int maxSize, const QMetaObject &type, QObject *parent=nullptr);
644
645 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
646
647protected:
649 bool validType(const QMetaObject *type) const;
650
651protected:
653 qint64 _minSize;
655 qint64 _maxSize;
657 QSet<QString> _types;
658};
659
660
665{
666 Q_OBJECT
667
668public:
673 RadioLimitGroupCallRefList(int minSize, int maxSize, QObject *parent=nullptr);
674
675 bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const;
676
677protected:
679 qint64 _minSize;
681 qint64 _maxSize;
682};
683
684
693{
694 Q_OBJECT
695
696public:
701 RadioLimitSingleZone(qint64 maxSize, const PropList &list, QObject *parent=nullptr);
702
703 bool verifyItem(const ConfigItem *item, RadioLimitContext &context) const;
704};
705
706
712{
713 Q_OBJECT
714
715public:
717 explicit RadioLimits(bool betaWarning, QObject *parent = nullptr);
719 RadioLimits(const std::initializer_list<std::pair<QString,RadioLimitElement *> > &list, QObject *parent=nullptr);
720
722 virtual bool verifyConfig(const Config *config, RadioLimitContext &context) const;
723
725 bool hasCallSignDB() const;
727 bool callSignDBImplemented() const;
729 unsigned numCallSignDBEntries() const;
730
732 bool hasSatelliteConfig() const;
734 bool satelliteConfigImplemented() const;
736 unsigned numSatellites() const;
737
738protected:
754};
755
756#endif // RADIOLIMITS_HH
Base class for all configuration objects (channels, zones, contacts, etc).
Definition configobject.hh:35
Base class of all labeled and named objects.
Definition configobject.hh:194
The config class, representing the codeplug configuration.
Definition config.hh:70
Checks if a property is a boolean value.
Definition radiolimits.hh:261
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:308
Collects the issues found during verification.
Definition radiolimits.hh:97
RadioLimitIssue::Severity _maxSeverity
Holds the highest severity of all messages.
Definition radiolimits.hh:132
bool ignoreFrequencyLimits() const
If true, frequency limit voilations are warnings.
Definition radiolimits.cc:121
void pop()
Pops the top-most property name/element index from the stack.
Definition radiolimits.cc:116
const RadioLimitIssue & message(int n) const
Returns the n-th issue.
Definition radiolimits.cc:106
bool _ignoreFrequencyLimits
If true, any frequency range voilation is a warning.
Definition radiolimits.hh:130
void push(const QString &element)
Push a property name/element index onto the stack.
Definition radiolimits.cc:111
QStringList _stack
The current item stack.
Definition radiolimits.hh:126
QList< RadioLimitIssue > _messages
The list of issues found.
Definition radiolimits.hh:128
RadioLimitIssue::Severity maxSeverity() const
Returns the highest severity of the messages.
Definition radiolimits.cc:130
RadioLimitIssue & newMessage(RadioLimitIssue::Severity severity=RadioLimitIssue::Hint)
Constructs a new message and puts it into the list of issues.
Definition radiolimits.cc:93
int count() const
Returns the number of issues.
Definition radiolimits.cc:101
void enableIgnoreFrequencyLimits(bool enable=true)
Enables/disables that frequency range voilations are handled as warnings.
Definition radiolimits.cc:125
Represents a DMR ID.
Definition radiolimits.hh:326
Abstract base class for all radio limits.
Definition radiolimits.hh:140
virtual ~RadioLimitElement()
Destructor.
Definition radiolimits.cc:144
std::initializer_list< std::pair< QString, RadioLimitElement * > > PropList
Initializer lists of ConfigItem properties.
Definition radiolimits.hh:145
virtual bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const =0
Verifies the given property of the specified item.
Represents a limit for a set of enum values.
Definition radiolimits.hh:340
QSet< unsigned > _values
Holds the set of valid values.
Definition radiolimits.hh:353
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:407
Represents a limit on frequencies in MHz.
Definition radiolimits.hh:360
std::initializer_list< std::pair< Frequency, Frequency > > RangeList
Typedef for the initializer list.
Definition radiolimits.hh:365
QList< FrequencyRange > _frequencyRanges
Holds the frequency ranges for the device.
Definition radiolimits.hh:380
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:452
Implements the limits for a list of references to group call contacts.
Definition radiolimits.hh:665
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:876
qint64 _minSize
Holds the minimum size of the list.
Definition radiolimits.hh:679
qint64 _maxSize
Holds the maximum size of the list.
Definition radiolimits.hh:681
Specifies an boolean value as ignored.
Definition radiolimits.hh:276
RadioLimitIssue::Severity _severity
The severity of the issue generated.
Definition radiolimits.hh:290
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:331
Represents an ignored element in the codeplug.
Definition radiolimits.hh:466
RadioLimitIssue::Severity _notification
Holds the level of the notification.
Definition radiolimits.hh:478
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:159
bool verifyObject(const ConfigObject *item, RadioLimitContext &context) const
Verifies the properties of the given object.
Definition radiolimits.cc:168
Represents a single issue found during verification.
Definition radiolimits.hh:51
Severity
Defines the possible severity levels.
Definition radiolimits.hh:54
@ Critical
Assembly of the codeplug will fail or a non-functional codeplug might be created.
Definition radiolimits.hh:58
@ Hint
Just a hint, a working codeplug will be assembled.
Definition radiolimits.hh:56
@ Silent
The user will not be notified.
Definition radiolimits.hh:55
@ Warning
The codeplug gets changed but a working codeplug might be assembled.
Definition radiolimits.hh:57
Severity severity() const
Returns the severity of the issue.
Definition radiolimits.cc:54
QStringList _stack
Holds the item-stack (where the issue occurred).
Definition radiolimits.hh:86
QString format() const
Formats the message.
Definition radiolimits.cc:69
const QString & message() const
Returns the text message.
Definition radiolimits.cc:59
const QStringList & stack() const
Returns the traceback of the issue.
Definition radiolimits.cc:64
RadioLimitIssue & operator=(const RadioLimitIssue &other)
Copy assignment.
Definition radiolimits.cc:39
QString _message
Holds the text message.
Definition radiolimits.hh:88
Severity _severity
Holds the severity of the issue.
Definition radiolimits.hh:84
Represents the limits for a ConfigItem instance.
Definition radiolimits.hh:411
virtual bool verifyItem(const ConfigItem *item, RadioLimitContext &context) const
Verifies the properties of the given item.
Definition radiolimits.cc:559
bool add(const QString &prop, RadioLimitElement *structure)
Adds a property declaration.
Definition radiolimits.cc:527
QHash< QString, RadioLimitElement * > _elements
Holds the property <-> limits map.
Definition radiolimits.hh:437
virtual bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:536
Specifies the limits for a list of ConfigObject instances.
Definition radiolimits.hh:591
QString findClassName(const QMetaObject &type) const
Searches for the specified type or one of its super-clsases in the set of allowed types.
Definition radiolimits.cc:797
QHash< QString, qint64 > _minCount
Maps typename to minimum count.
Definition radiolimits.hh:625
QHash< QString, RadioLimitObject * > _elements
Maps typename to element definition.
Definition radiolimits.hh:623
QHash< QString, qint64 > _maxCount
Maps typename to maximum count.
Definition radiolimits.hh:627
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:732
Issues a notification if a reference is set.
Definition radiolimits.hh:566
ConfigObject * _default
A weak reference to a default value, that gets silently ignored.
Definition radiolimits.hh:584
RadioLimitIssue::Severity _severity
The severity of the issue.
Definition radiolimits.hh:582
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:695
Limits the possible classes a ConfigObjectReference may refer to.
Definition radiolimits.hh:529
std::initializer_list< QMetaObject > MetaObjectList
Initializer lists of allowed classes.
Definition radiolimits.hh:534
bool _allowNull
If true, a null reference is allowed.
Definition radiolimits.hh:557
bool validType(const QMetaObject *type) const
Checks if the given type is one of the valid ones in _types.
Definition radiolimits.cc:674
QSet< QString > _types
Possible classes of instances, the reference may point to.
Definition radiolimits.hh:559
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:643
Represents the limits for all properties of a ConfigObject instance.
Definition radiolimits.hh:444
virtual bool verifyObject(const ConfigObject *item, RadioLimitContext &context) const
Verifies the properties of the given object.
Definition radiolimits.cc:594
Dispatch by class.
Definition radiolimits.hh:490
bool verifyItem(const ConfigItem *item, RadioLimitContext &context) const
Verifies the properties of the given item.
Definition radiolimits.cc:615
std::initializer_list< std::pair< const QMetaObject &, RadioLimitObject * > > TypeList
Initializer lists of type properties.
Definition radiolimits.hh:495
QHash< QString, RadioLimitObject * > _types
Maps class-names to object limits.
Definition radiolimits.hh:522
Implements the limits for reference lists.
Definition radiolimits.hh:634
qint64 _maxSize
Holds the maximum size of the list.
Definition radiolimits.hh:655
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:816
QSet< QString > _types
Possible classes of instances, the references may point to.
Definition radiolimits.hh:657
qint64 _minSize
Holds the minimum size of the list.
Definition radiolimits.hh:653
bool validType(const QMetaObject *type) const
Checks if the given type is one of the valid ones in _types.
Definition radiolimits.cc:857
Specialized RadioLimitObject handling a zone for radio supporting only a single channel list per zone...
Definition radiolimits.hh:693
bool verifyItem(const ConfigItem *item, RadioLimitContext &context) const
Verifies the properties of the given item.
Definition radiolimits.cc:934
Notifies the user that a string gets ignored.
Definition radiolimits.hh:247
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:278
Verifies that a string matches a regular expression.
Definition radiolimits.hh:224
QRegularExpression _pattern
Holds the regular expression pattern.
Definition radiolimits.hh:240
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:246
Checks a string valued property.
Definition radiolimits.hh:188
int _minLen
Holds the minimum length of the string.
Definition radiolimits.hh:213
int _maxLen
Holds the maximum length of the string.
Definition radiolimits.hh:215
Encoding
Possible encoding of strings.
Definition radiolimits.hh:193
@ ASCII
Just ASCII is allowed.
Definition radiolimits.hh:195
@ Unicode
Any Unicode character is allowed.
Definition radiolimits.hh:196
@ DTMF
Just DTMF symbols are allowed (0-9, A-D, *, #).
Definition radiolimits.hh:194
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:198
Encoding _encoding
Holds the allowed character encoding.
Definition radiolimits.hh:217
Specialization for transmit frequency limits.
Definition radiolimits.hh:388
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:494
Represents a limit for an unsigned integer value.
Definition radiolimits.hh:297
qint64 _maxValue
Holds the maximum value.
Definition radiolimits.hh:316
qint64 _defValue
Holds the default value.
Definition radiolimits.hh:318
bool verify(const ConfigItem *item, const QMetaProperty &prop, RadioLimitContext &context) const
Verifies the given property of the specified item.
Definition radiolimits.cc:361
qint64 _minValue
Holds the minimum value.
Definition radiolimits.hh:314
Base class to verify values.
Definition radiolimits.hh:167
RadioLimitIssue::Severity _severity
The severity of the issue, if the test fails.
Definition radiolimits.hh:177
Represents the limits or the entire codeplug.
Definition radiolimits.hh:712
bool _satelliteConfigImplemented
If true, satellite config is implemented.
Definition radiolimits.hh:751
unsigned numCallSignDBEntries() const
Returns the maximum number of entries in the call-sign DB.
Definition radiolimits.cc:980
virtual bool verifyConfig(const Config *config, RadioLimitContext &context) const
Verifies the given configuration.
Definition radiolimits.cc:1002
bool hasSatelliteConfig() const
Returns true if the radio supports satellite config.
Definition radiolimits.cc:986
bool _callSignDBImplemented
If true, the call-sign is implemented.
Definition radiolimits.hh:745
bool _hasSatelliteConfig
If true, the radio supports satellite config.
Definition radiolimits.hh:749
bool _hasCallSignDB
If true, the radio supports a call-sign DB.
Definition radiolimits.hh:743
bool satelliteConfigImplemented() const
Returns true if satellite config is implemented.
Definition radiolimits.cc:991
bool hasCallSignDB() const
Returns true if the radio supports a call-sign DB.
Definition radiolimits.cc:970
unsigned _numSatellites
Holds the number of possible satellites.
Definition radiolimits.hh:753
unsigned _numCallSignDBEntries
Holds the number of possible call-sign DB entries.
Definition radiolimits.hh:747
bool callSignDBImplemented() const
Returns true if the call-sign DB is implemented.
Definition radiolimits.cc:975
bool _betaWarning
If true, a warning is issued that the radio is still under development and not well tested yet.
Definition radiolimits.hh:741
unsigned numSatellites() const
Returns the maximum number of satellites.
Definition radiolimits.cc:996
Helper struct to pass list entry definitions.
Definition radiolimits.hh:596
int minCount
Minimum count of elements.
Definition radiolimits.hh:598
const QMetaObject & type
The type of the object.
Definition radiolimits.hh:597
int maxCount
Maximum count of elements.
Definition radiolimits.hh:599
RadioLimitObject * structure
The structure of the elements.
Definition radiolimits.hh:600