mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
CValueObject virtual method toIcon, reprsenting the object as icon where applicable.
Currently used for status messages (severity), will be used for CAtcStation and others as well.
This commit is contained in:
committed by
Mathew Sutcliffe
parent
4ec1db4b38
commit
fda587994d
@@ -36,22 +36,12 @@ namespace BlackGui
|
||||
{
|
||||
// shortcut, fast check
|
||||
if (role != Qt::DisplayRole && role != Qt::DecorationRole) return CListModelBase::data(modelIndex, role);
|
||||
|
||||
static QPixmap w(QPixmap(":/blackgui/iconsQt/warning.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
static QPixmap e(QPixmap(":/blackgui/iconsQt/critical.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
static QPixmap i(QPixmap(":/blackgui/iconsQt/information.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
|
||||
if (this->columnToPropertyIndex(modelIndex.column()) == CStatusMessage::IndexSeverity)
|
||||
{
|
||||
if (role == Qt::DecorationRole)
|
||||
{
|
||||
CStatusMessage msg = this->at(modelIndex);
|
||||
switch (msg.getSeverity())
|
||||
{
|
||||
case CStatusMessage::SeverityError: return e;
|
||||
case CStatusMessage::SeverityWarning: return w;
|
||||
default: return i;
|
||||
}
|
||||
return msg.toIcon();
|
||||
}
|
||||
else if (role == Qt::DisplayRole)
|
||||
{
|
||||
|
||||
@@ -88,6 +88,23 @@ namespace BlackMisc
|
||||
return CStatusMessage(CStatusMessage::TypeUnspecific, CStatusMessage::SeverityInfo, message);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pixmap
|
||||
*/
|
||||
const QPixmap &CStatusMessage::convertToIcon(const CStatusMessage &statusMessage)
|
||||
{
|
||||
static QPixmap w(QPixmap(":/blackmisc/icons/warning.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
static QPixmap e(QPixmap(":/blackmisc/icons/critical.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
static QPixmap i(QPixmap(":/blackmisc/icons/information.png").scaledToWidth(16, Qt::SmoothTransformation));
|
||||
switch (statusMessage.getSeverity())
|
||||
{
|
||||
case SeverityInfo: return i;
|
||||
case SeverityWarning: return w;
|
||||
case SeverityError: return e;
|
||||
default: return i;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
@@ -260,7 +277,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Set property as index
|
||||
*/
|
||||
void CStatusMessage::propertyByIndex(const QVariant &variant, int index)
|
||||
void CStatusMessage::setPropertyByIndex(const QVariant &variant, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
|
||||
@@ -114,6 +114,9 @@ namespace BlackMisc
|
||||
//! \brief Type as string
|
||||
const QString &getTypeAsString() const;
|
||||
|
||||
//! \brief representing icon
|
||||
virtual const QPixmap &toIcon() const override { return CStatusMessage::convertToIcon(*this); }
|
||||
|
||||
//! \brief Type as string
|
||||
const QString &getSeverityAsString() const;
|
||||
|
||||
@@ -159,6 +162,9 @@ namespace BlackMisc
|
||||
*/
|
||||
static CStatusMessage getInfoMessage(const QString &message);
|
||||
|
||||
//! \representing icon
|
||||
static const QPixmap &convertToIcon(const CStatusMessage &statusMessage);
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Marshall to DBus
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QtGlobal>
|
||||
#include <QDataStream>
|
||||
#include <QDebug>
|
||||
#include <QPixmap>
|
||||
#include <type_traits>
|
||||
#include <iostream>
|
||||
|
||||
@@ -173,6 +174,12 @@ namespace BlackMisc
|
||||
*/
|
||||
virtual QVariant toQVariant() const = 0;
|
||||
|
||||
/*!
|
||||
* \brief As icon, not implement by all classes
|
||||
* \return
|
||||
*/
|
||||
virtual const QPixmap &toIcon() const { static const QPixmap p; return p; }
|
||||
|
||||
/*!
|
||||
* \brief Set property by index
|
||||
* \remarks Intentionally not abstract, avoiding all classes need to implement this method
|
||||
|
||||
Reference in New Issue
Block a user