From 895bb6b58f3020f70eccd9a18a2724f2a115e5b7 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 14 Oct 2018 01:54:29 +0200 Subject: [PATCH] Ref T401, info and setting object for crash dumps --- src/blackmisc/crashinfo.cpp | 59 +++++++++++++++++++++++++ src/blackmisc/crashinfo.h | 74 ++++++++++++++++++++++++++++++++ src/blackmisc/crashsettings.cpp | 65 ++++++++++++++++++++++++++++ src/blackmisc/crashsettings.h | 76 +++++++++++++++++++++++++++++++++ src/blackmisc/propertyindex.h | 2 + 5 files changed, 276 insertions(+) create mode 100644 src/blackmisc/crashinfo.cpp create mode 100644 src/blackmisc/crashinfo.h create mode 100644 src/blackmisc/crashsettings.cpp create mode 100644 src/blackmisc/crashsettings.h diff --git a/src/blackmisc/crashinfo.cpp b/src/blackmisc/crashinfo.cpp new file mode 100644 index 000000000..debfb1dbe --- /dev/null +++ b/src/blackmisc/crashinfo.cpp @@ -0,0 +1,59 @@ +/* Copyright (C) 2018 +* 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. +*/ + +#include "blackmisc/crashinfo.h" +#include + +namespace BlackMisc +{ + CCrashInfo::CCrashInfo() {} + + QString CCrashInfo::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + return QStringLiteral("{ %1, %2 }").arg(this->getInfo(), this->getUserName()); + } + + CVariant CCrashInfo::propertyByIndex(const CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexUserName: return CVariant::fromValue(m_userName); + case IndexInfo: return CVariant::fromValue(m_info); + default: break; + } + return CValueObject::propertyByIndex(index); + } + + void CCrashInfo::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexUserName: this->setUserName(variant.toQString()); break; + case IndexInfo: this->setUserName(variant.toQString()); break; + default: CValueObject::setPropertyByIndex(index, variant); break; + } + } + + int CCrashInfo::comparePropertyByIndex(const CPropertyIndex &index, const CCrashInfo &compareValue) const + { + if (index.isMyself()) { return this->getInfo().compare(compareValue.getInfo()); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexUserName: return this->getUserName().compare(compareValue.getUserName()); + case IndexInfo: return this->getInfo().compare(compareValue.getInfo()); + default: return CValueObject::comparePropertyByIndex(index.copyFrontRemoved(), compareValue); + } + } +} // ns diff --git a/src/blackmisc/crashinfo.h b/src/blackmisc/crashinfo.h new file mode 100644 index 000000000..8d137d298 --- /dev/null +++ b/src/blackmisc/crashinfo.h @@ -0,0 +1,74 @@ +/* Copyright (C) 2018 + * 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_CRASHINFO_H +#define BLACKMISC_CRASHINFO_H + +#include "blackmisc/valueobject.h" +#include + +namespace BlackMisc +{ + /*! + * Crash info. Details about crash context. + */ + class BLACKMISC_EXPORT CCrashInfo : public CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexUserName = CPropertyIndex::GlobalIndexCCrashInfo, + IndexInfo + }; + + //! Default constructor. + CCrashInfo(); + + //! Get user name + const QString &getUserName() const { return m_userName; } + + //! User name + void setUserName(const QString &userName) { m_userName = userName; } + + //! Get the info + const QString &getInfo() const { return m_info; } + + //! Set info + void setInfo(const QString &info) { m_info = info; } + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! \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 CCrashInfo &compareValue) const; + + private: + QString m_userName; + QString m_info; + + BLACK_METACLASS( + CCrashInfo, + BLACK_METAMEMBER(userName), + BLACK_METAMEMBER(info) + ); + }; +} // ns + +Q_DECLARE_METATYPE(BlackMisc::CCrashInfo) + +#endif // guard diff --git a/src/blackmisc/crashsettings.cpp b/src/blackmisc/crashsettings.cpp new file mode 100644 index 000000000..2e153f735 --- /dev/null +++ b/src/blackmisc/crashsettings.cpp @@ -0,0 +1,65 @@ +/* Copyright (C) 2018 +* 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. +*/ + +#include "blackmisc/crashsettings.h" +#include "blackmisc/stringutils.h" +#include "blackmisc/comparefunctions.h" + +#include + +namespace BlackMisc +{ + namespace Settings + { + CCrashSettings::CCrashSettings() {} + + QString CCrashSettings::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + return QStringLiteral("{ %1, %2 }").arg(boolToYesNo(this->isEnabled()), boolToYesNo(this->withPrivacyInfo())); + } + + CVariant CCrashSettings::propertyByIndex(const CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexEnabled: return CVariant::fromValue(this->isEnabled()); + case IndexPrivateInfo: return CVariant::fromValue(this->withPrivacyInfo()); + default: break; + } + return CValueObject::propertyByIndex(index); + } + + void CCrashSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexEnabled: this->setEnabled(variant.toBool()); break; + case IndexPrivateInfo: this->setPrivacyInfo(variant.toBool()); break; + default: CValueObject::setPropertyByIndex(index, variant); break; + } + } + + int CCrashSettings::comparePropertyByIndex(const CPropertyIndex &index, const CCrashSettings &compareValue) const + { + if (index.isMyself()) { return this->convertToQString().compare(compareValue.convertToQString()); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexEnabled: return Compare::compare(this->isEnabled(), compareValue.isEnabled()); + case IndexPrivateInfo: return Compare::compare(this->withPrivacyInfo(), compareValue.withPrivacyInfo()); + default: return CValueObject::comparePropertyByIndex(index.copyFrontRemoved(), compareValue); + } + } + } // ns +} // ns diff --git a/src/blackmisc/crashsettings.h b/src/blackmisc/crashsettings.h new file mode 100644 index 000000000..a7df50213 --- /dev/null +++ b/src/blackmisc/crashsettings.h @@ -0,0 +1,76 @@ +/* Copyright (C) 2018 + * 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_CRASHSETTINGS_H +#define BLACKMISC_CRASHSETTINGS_H + +#include "blackmisc/valueobject.h" + +namespace BlackMisc +{ + namespace Settings + { + /*! + * Crash info. Details about crash context. + */ + class BLACKMISC_EXPORT CCrashSettings : public CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexEnabled = CPropertyIndex::GlobalIndexCCrashSettings, + IndexPrivateInfo + }; + + //! Default constructor. + CCrashSettings(); + + //! Is enabled? + bool isEnabled() const { return m_enabled; } + + //! Set enabled + void setEnabled(bool enabled) { m_enabled = enabled; } + + //! With privacy info + bool withPrivacyInfo() const { return m_privacyInfo; } + + //! Set privacy info + void setPrivacyInfo(bool privacy) { m_privacyInfo = privacy; } + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! \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 CCrashSettings &compareValue) const; + + private: + bool m_enabled = false; + bool m_privacyInfo = false; + + BLACK_METACLASS( + CCrashSettings, + BLACK_METAMEMBER(enabled), + BLACK_METAMEMBER(privacyInfo) + ); + }; + } // ns +} // ns + +Q_DECLARE_METATYPE(BlackMisc::Settings::CCrashSettings) + +#endif // guard diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index 3d8609a98..8717e74de 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -89,6 +89,8 @@ namespace BlackMisc GlobalIndexCPlatform = 1000, GlobalIndexCApplicationInfo = 1100, GlobalIndexCDirectories = 1200, + GlobalIndexCCrashInfo = 1300, + GlobalIndexCCrashSettings = 1400, GlobalIndexCCallsign = 2000, GlobalIndexCAircraftSituation = 2100, GlobalIndexCAircraftSituationChange = 2200,