mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 23:35:33 +08:00
refs #685, settings for readers (value object, traits)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "blackcore/registermetadata.h"
|
||||
#include "blackcore/contextapplication.h"
|
||||
#include "blackcore/db/databasereader.h"
|
||||
#include "blackcore/settings/reader.h"
|
||||
#include "blackcore/data/globalsetup.h"
|
||||
#include "blackcore/data/updateinfo.h"
|
||||
#include "blackcore/data/vatsimsetup.h"
|
||||
@@ -23,8 +24,6 @@
|
||||
#include <QDBusMetaType>
|
||||
#include <QMetaType>
|
||||
|
||||
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
void registerMetadata()
|
||||
@@ -43,5 +42,7 @@ namespace BlackCore
|
||||
BlackCore::Data::CGlobalSetup::registerMetadata();
|
||||
BlackCore::Data::CUpdateInfo::registerMetadata();
|
||||
BlackCore::Data::CVatsimSetup::registerMetadata();
|
||||
|
||||
BlackCore::Settings::CSettingsReader::registerMetadata();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
78
src/blackcore/settings/reader.cpp
Normal file
78
src/blackcore/settings/reader.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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 "reader.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
CSettingsReader::CSettingsReader()
|
||||
{ }
|
||||
|
||||
CSettingsReader::CSettingsReader(const CTime &initialTime, const CTime &periodicTime, bool neverUpdate) :
|
||||
m_initialTime(initialTime), m_periodicTime(periodicTime), m_neverUpdate(neverUpdate)
|
||||
{ }
|
||||
|
||||
QString CSettingsReader::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s("CReaderSettings");
|
||||
s.append(" ").append(this->m_initialTime.convertToQString(i18n));
|
||||
s.append(" ").append(this->m_periodicTime.convertToQString(i18n));
|
||||
return s;
|
||||
}
|
||||
|
||||
const CSettingsReader &CSettingsReader::neverUpdateSettings()
|
||||
{
|
||||
static const CSettingsReader s(CTime{ 1.0, CTimeUnit::d()}, CTime{ 1.0, CTimeUnit::d()}, true);
|
||||
return s;
|
||||
}
|
||||
|
||||
CVariant CSettingsReader::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexInitialTime:
|
||||
return this->m_initialTime.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexPeriodicTime:
|
||||
return this->m_periodicTime.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexNeverUpdate:
|
||||
return CVariant::fromValue(this->m_neverUpdate);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsReader::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSettingsReader>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexInitialTime:
|
||||
this->m_initialTime.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexPeriodicTime:
|
||||
this->m_periodicTime.setPropertyByIndex(index.copyFrontRemoved(), variant);
|
||||
break;
|
||||
case IndexNeverUpdate:
|
||||
this->m_neverUpdate = variant.toBool();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
133
src/blackcore/settings/reader.h
Normal file
133
src/blackcore/settings/reader.h
Normal file
@@ -0,0 +1,133 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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 BLACKCORE_SETTINGS_READER_H
|
||||
#define BLACKCORE_SETTINGS_READER_H
|
||||
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/pq/time.h"
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
/*!
|
||||
* Settings used with readers
|
||||
*/
|
||||
class BLACKCORE_EXPORT CSettingsReader : public BlackMisc::CValueObject<BlackCore::Settings::CSettingsReader>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexInitialTime = BlackMisc::CPropertyIndex::GlobalIndexCSettingsReaders,
|
||||
IndexPeriodicTime,
|
||||
IndexNeverUpdate
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
CSettingsReader();
|
||||
|
||||
//! Simplified constructor
|
||||
CSettingsReader(const BlackMisc::PhysicalQuantities::CTime &initialTime, const BlackMisc::PhysicalQuantities::CTime &periodicTime, bool neverUpdate = false);
|
||||
|
||||
//! Get time
|
||||
const BlackMisc::PhysicalQuantities::CTime &getInitialTime() const { return m_initialTime; }
|
||||
|
||||
//! Set time
|
||||
void setInitialTime(const BlackMisc::PhysicalQuantities::CTime &time) { m_initialTime = time; }
|
||||
|
||||
//! Get time
|
||||
const BlackMisc::PhysicalQuantities::CTime &getPeriodicTime() const { return m_periodicTime; }
|
||||
|
||||
//! Set time
|
||||
void setPeriodicTime(const BlackMisc::PhysicalQuantities::CTime &time) { m_periodicTime = time; }
|
||||
|
||||
//! Never ever update?
|
||||
bool isNeverUpdate() const { return m_neverUpdate; }
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! Settings used when a reader is manually triggered and never updates
|
||||
static const CSettingsReader &neverUpdateSettings();
|
||||
|
||||
private:
|
||||
BlackMisc::PhysicalQuantities::CTime m_initialTime { 30.0, BlackMisc::PhysicalQuantities::CTimeUnit::s()};
|
||||
BlackMisc::PhysicalQuantities::CTime m_periodicTime { 30.0, BlackMisc::PhysicalQuantities::CTimeUnit::s()};
|
||||
bool m_neverUpdate = false;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CSettingsReader,
|
||||
BLACK_METAMEMBER(initialTime),
|
||||
BLACK_METAMEMBER(periodicTime),
|
||||
BLACK_METAMEMBER(neverUpdate)
|
||||
);
|
||||
};
|
||||
|
||||
//! Reader settings
|
||||
struct SettingsVatsimBookings : public BlackMisc::CSettingTrait<CSettingsReader>
|
||||
{
|
||||
//! \copydoc BlackCore::CSettingTrait::key
|
||||
static const char *key() { return "vatsimreaders/bookings"; }
|
||||
|
||||
//! \copydoc BlackCore::CSettingTrait::defaultValue
|
||||
static const CSettingsReader &defaultValue()
|
||||
{
|
||||
static const CSettingsReader reader {};
|
||||
return reader;
|
||||
}
|
||||
};
|
||||
|
||||
//! Reader settings
|
||||
struct SettingsVatsimDataFile : public BlackMisc::CSettingTrait<CSettingsReader>
|
||||
{
|
||||
//! \copydoc BlackCore::CSettingTrait::key
|
||||
static const char *key() { return "vatsimreaders/datafile"; }
|
||||
|
||||
//! \copydoc BlackCore::CSettingTrait::defaultValue
|
||||
static const CSettingsReader &defaultValue()
|
||||
{
|
||||
static const CSettingsReader reader {};
|
||||
return reader;
|
||||
}
|
||||
};
|
||||
|
||||
//! Reader settings
|
||||
struct SettingsVatsimMetars : public BlackMisc::CSettingTrait<CSettingsReader>
|
||||
{
|
||||
//! \copydoc BlackCore::CSettingTrait::key
|
||||
static const char *key() { return "vatsimreaders/metars"; }
|
||||
|
||||
//! \copydoc BlackCore::CSettingTrait::defaultValue
|
||||
static const CSettingsReader &defaultValue()
|
||||
{
|
||||
static const CSettingsReader reader {};
|
||||
return reader;
|
||||
}
|
||||
};
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackCore::Settings::CSettingsReader)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackCore::Settings::CSettingsReader>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackCore::Settings::CSettingsReader>)
|
||||
|
||||
#endif
|
||||
@@ -108,6 +108,7 @@ namespace BlackMisc
|
||||
GlobalIndexCGuiStateDbOwnModelSetComponent = 14100,
|
||||
GlobalIndexCSettingsDockWidget = 14200,
|
||||
GlobalIndexCSettingsNavigator = 14300,
|
||||
GlobalIndexCSettingsReaders = 14400,
|
||||
GlobalIndexAbuseMode = 20000 // property index abused as map key or otherwise, to be removed if no longer needed
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user