Ref T401, info and setting object for crash dumps

This commit is contained in:
Klaus Basan
2018-10-14 01:54:29 +02:00
parent 5e070f1f8c
commit 895bb6b58f
5 changed files with 276 additions and 0 deletions

View File

@@ -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 <QStringBuilder>
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<ColumnIndex>();
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<CCrashInfo>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
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<ColumnIndex>();
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

74
src/blackmisc/crashinfo.h Normal file
View File

@@ -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 <QString>
namespace BlackMisc
{
/*!
* Crash info. Details about crash context.
*/
class BLACKMISC_EXPORT CCrashInfo : public CValueObject<CCrashInfo>
{
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

View File

@@ -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 <QStringBuilder>
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<ColumnIndex>();
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<CCrashSettings>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
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<ColumnIndex>();
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

View File

@@ -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<CCrashSettings>
{
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

View File

@@ -89,6 +89,8 @@ namespace BlackMisc
GlobalIndexCPlatform = 1000,
GlobalIndexCApplicationInfo = 1100,
GlobalIndexCDirectories = 1200,
GlobalIndexCCrashInfo = 1300,
GlobalIndexCCrashSettings = 1400,
GlobalIndexCCallsign = 2000,
GlobalIndexCAircraftSituation = 2100,
GlobalIndexCAircraftSituationChange = 2200,