10 #include <QScopedPointer>
22 using namespace swift::misc::aviation;
23 using namespace swift::misc::physical_quantities;
34 return keepStandardTypesConvertToStringOtherwise(dataCVariant);
39 return keepStandardTypesConvertToStringOtherwise(dataCVariant);
74 CVariant CDefaultFormatter::alignmentRole()
const
87 bool CDefaultFormatter::supportsRole(
int role)
const
93 return m_supportedRoles.contains(role);
98 if (!this->supportsRole(role)) {
return CVariant(); }
105 if (role ==
Qt::UserRole) {
return CDefaultFormatter::displayRole(inputData); }
118 int CDefaultFormatter::alignDefault() {
return alignLeftVCenter(); }
120 CVariant CDefaultFormatter::keepStandardTypesConvertToStringOtherwise(
const CVariant &inputData)
const
128 const CVariant &CDefaultFormatter::emptyStringVariant()
134 const CVariant &CDefaultFormatter::emptyPixmapVariant()
142 Q_UNUSED(dataCVariant);
143 Q_ASSERT_X(
false,
"CPixmapFormatter",
"this role should be disabled with pixmaps");
149 if (dataCVariant.
isNull()) {
return {}; }
155 return emptyStringVariant();
160 if (dataCVariant.
isNull()) {
return {}; }
161 if (m_maxWidth < 0 && m_maxHeight < 0) {
return CDefaultFormatter::decorationRole(dataCVariant); }
170 if (pm.
isNull()) {
return {}; }
171 const int pmw = pm.
width();
172 const int pmh = pm.
height();
191 CDateTimeFormatter::CDateTimeFormatter(
const QString &formatString,
int alignment,
bool i18n)
199 if (dateTime.
isNull())
return {};
222 Q_ASSERT_X(
false,
"formatQVariant",
"No QDate, QTime or QDateTime");
238 Q_ASSERT_X(
false,
"CAirspaceDistanceFormatter::formatQVariant",
"No CLength class");
254 Q_ASSERT_X(
false,
"CAviationComFrequencyFormatter::formatQVariant",
"No CFrequency class");
275 static const CVariant iv(
"invalid");
278 return CVariant::from(QStringLiteral(
"Invalid type: '%1'").arg(dataCVariant.
typeName()));
291 const bool v = dataCVariant.
toBool();
294 Q_ASSERT_X(
false,
"CBoolTextFormatter",
"no boolean value");
318 Q_UNUSED(dataCVariant);
319 Q_ASSERT_X(
false, Q_FUNC_INFO,
"this role should be disabled with led boolean");
327 const bool v = dataCVariant.
toBool();
330 Q_ASSERT_X(
false,
"CBoolLedFormatter",
"no boolean value");
343 const QString &offName,
int alignment)
348 const QString &offName,
int alignment)
350 m_iconOnVariant(
CVariant::fromValue(onIcon.toPixmap())),
351 m_iconOffVariant(
CVariant::fromValue(offIcon.toPixmap()))
356 Q_UNUSED(dataCVariant)
357 Q_ASSERT_X(
false,
"CBoolIconFormatter",
"this role should be disabled with icon boolean");
365 const bool v = dataCVariant.
toBool();
368 Q_ASSERT_X(
false,
"CBoolIconFormatter",
"no boolean value");
391 Q_UNUSED(dataCVariant)
392 Q_ASSERT_X(
false, Q_FUNC_INFO,
"this role should be disabled with RGB color");
400 return CVariant::fromValue(rgbColor.
toPixmap());
408 return rgbColor.
hex(
true);
414 switch (expectedInteger.
type())
418 const qlonglong ll = expectedInteger.
toLongLong(&ok);
424 const qulonglong ll = expectedInteger.
toULongLong(&ok);
431 const int i = expectedInteger.
toInt(&ok);
438 Q_UNUSED(dataCVariant);
445 Q_UNUSED(dataCVariant);
446 static const CVariant masked(
"******");
Bool value, format as text.
const swift::misc::CVariant m_trueNameVariant
displayed when true
const swift::misc::CVariant m_falseNameVariant
displayed when false
virtual Qt::ItemFlags flags(Qt::ItemFlags flags, bool editable) const
Flags.
virtual swift::misc::CVariant displayRole(const swift::misc::CVariant &dataCVariant) const
Value provided as CVariant, formatter converts to standard types or string. Used with Qt::DisplayRole...
Value object for icons. An icon is stored in the global icon repository and identified by its index....
QPixmap toPixmap() const
Corresponding pixmap.
const QString & getDescriptiveText() const
Constructor for generated icon.
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
QString hex(bool withHash=false) const
Hex value.
QPixmap toPixmap() const
Icon as pixmap.
bool isValid() const
Valid?
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
T to() const
Synonym for value().
static CVariant fromValue(T &&value)
Construct a variant from a value.
T value() const
Return the value converted to the type T.
bool isIntegral() const
True if this variant's type is an integral type.
bool isValid() const
True if this variant is valid.
bool toBool() const
Convert this variant to a bool.
qulonglong toULongLong(bool *ok=nullptr) const
Convert this variant to a unsigned longlong integer.
const char * typeName() const
Return the typename of the value in this variant.
QMetaType::Type type() const
Return the metatype ID of the value in this variant, or QMetaType::User if it is a user type.
qlonglong toLongLong(bool *ok=nullptr) const
Convert this variant to a longlong integer.
static CVariant from(T &&value)
Synonym for fromValue().
int toInt(bool *ok=nullptr) const
Convert this variant to an integer.
QPixmap toPixmap() const
Corresponding pixmap.
bool isNull() const
True if this variant is null.
bool canConvert(int typeId) const
True if this variant can be converted to the type with the given metatype ID.
Altitude as used in aviation, can be AGL or MSL altitude.
bool toFlightLevel()
MSL to flightlevel.
CAltitude & switchUnit(const physical_quantities::CLengthUnit &newUnit)
Value in switched unit.
QString toQString(bool i18n=false) const
Cast as QString.
Physical unit length (length)
bool isNull() const
Is quantity null?
bool isPositiveWithEpsilonConsidered() const
Value >= 0 epsilon considered.
bool isZeroEpsilonConsidered() const
Quantity value <= epsilon.
Models to be used with views, mainly QTableView.
Free functions in swift::misc.
QString toString(QStringView format) const const
QDateTime fromMSecsSinceEpoch(qint64 msecs)
QString toString(QStringView format) const const
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
bool isNull() const const
QPixmap scaledToHeight(int height, Qt::TransformationMode mode) const const
QPixmap scaledToWidth(int width, Qt::TransformationMode mode) const const
QString number(double n, char format, int precision)
QString toString(QStringView format) const const