Files
pilotclient/src/blackmisc/aviation/informationmessage.h
Klaus Basan 62601bde9d Ref T345, fixed value class CInformationMessage
- added property functions
- used ITimestampBased
2018-09-12 17:40:31 +02:00

137 lines
4.3 KiB
C++

/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_AVIATION_INFORMATIONMESSAGE_H
#define BLACKMISC_AVIATION_INFORMATIONMESSAGE_H
#include "blackmisc/timestampbased.h"
#include "blackmisc/metaclass.h"
#include "blackmisc/valueobject.h"
#include "blackmisc/blackmiscexport.h"
#include <QDateTime>
#include <QMetaType>
#include <QString>
#include <QtGlobal>
namespace BlackMisc
{
namespace Aviation
{
//! Value object encapsulating information message (ATIS, METAR, TAF)
class BLACKMISC_EXPORT CInformationMessage :
public CValueObject<CInformationMessage>,
public ITimestampBased
{
public:
//! Type
enum InformationType
{
Unspecified,
ATIS,
METAR,
TAF
};
//! Properties by index
enum ColumnIndex
{
IndexType = CPropertyIndex::GlobalIndexCInformationMessage,
IndexMessage,
};
//! Default constructor.
CInformationMessage() : m_type(CInformationMessage::Unspecified)
{}
//! Information message of type
explicit CInformationMessage(InformationType type) : m_type(type) {}
//! Information message of type
CInformationMessage(InformationType type, const QString &message)
: m_type(type), m_message(message)
{}
//! Get message.
const QString &getMessage() const { return m_message; }
//! Is a message available
bool hasMessage() const { return !m_message.isEmpty(); }
//! Set message
void setMessage(const QString &message)
{
this->setCurrentUtcTime();
m_message = message;
}
//! Append message part
void appendMessage(const QString &messagePart)
{
this->setCurrentUtcTime();
m_message.append(messagePart);
}
//! Type as string
const QString &getTypeAsString() const;
//! Type
InformationType getType() const { return m_type; }
//! Set type
void setType(InformationType type) { m_type = type; }
//! Received before n ms
qint64 timeDiffReceivedMs() const
{
return this->getTimeDifferenceToNowMs();
}
//! Is empty?
bool isEmpty() const { return m_message.isEmpty(); }
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
CVariant propertyByIndex(const CPropertyIndex &index) const;
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
//! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex
int comparePropertyByIndex(const CPropertyIndex &index, const CInformationMessage &compareValue) const;
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! \copydoc BlackMisc::CValueObject::registerMetadata
static void registerMetadata();
//! Unspecified object
static const CInformationMessage &unspecified();
private:
InformationType m_type;
QString m_message;
BLACK_METACLASS(
CInformationMessage,
BLACK_METAMEMBER(type),
BLACK_METAMEMBER(message),
BLACK_METAMEMBER(timestampMSecsSinceEpoch)
);
};
} // namespace
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Aviation::CInformationMessage)
Q_DECLARE_METATYPE(BlackMisc::Aviation::CInformationMessage::InformationType)
#endif // guard