mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 16:55:36 +08:00
refs #799, own component for view update times
* utility function in CTime * settings class for update times
This commit is contained in:
97
src/blackgui/settings/viewupdatesettings.cpp
Normal file
97
src/blackgui/settings/viewupdatesettings.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
/* 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 "viewupdatesettings.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include <QStringList>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackGui;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
CViewUpdateSettings::CViewUpdateSettings()
|
||||
{ }
|
||||
|
||||
void CViewUpdateSettings::reset()
|
||||
{
|
||||
this->m_updateAircraft = CTime(5.0, CTimeUnit::s());
|
||||
this->m_updateAtc = CTime(5.0, CTimeUnit::s());
|
||||
this->m_updateRendering = CTime(5.0, CTimeUnit::s());
|
||||
this->m_updateUser = CTime(5.0, CTimeUnit::s());
|
||||
}
|
||||
|
||||
bool CViewUpdateSettings::isValid() const
|
||||
{
|
||||
// too fast updates cause CPU overload
|
||||
static const CTime min(5.0, CTimeUnit::s());
|
||||
return
|
||||
this->m_updateAircraft >= min &&
|
||||
this->m_updateAtc >= min &&
|
||||
this->m_updateRendering >= min &&
|
||||
this->m_updateUser >= min;
|
||||
}
|
||||
|
||||
QString CViewUpdateSettings::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
const QString s("Atc: %1 Aircraft: %2 User: %3 Rendering %4");
|
||||
return s.arg(m_updateAtc.valueRounded(CTimeUnit::s(), 2)).arg(m_updateAircraft.valueRounded(CTimeUnit::s(), 2))
|
||||
.arg(m_updateUser.valueRounded(CTimeUnit::s(), 2)).arg(m_updateRendering.valueRounded(CTimeUnit::s(), 2));
|
||||
}
|
||||
|
||||
CVariant CViewUpdateSettings::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAircraft:
|
||||
return CVariant::fromValue(this->m_updateAircraft);
|
||||
case IndexAtc:
|
||||
return CVariant::fromValue(this->m_updateAtc);
|
||||
case IndexRendering:
|
||||
return CVariant::fromValue(this->m_updateRendering);
|
||||
case IndexUser:
|
||||
return CVariant::fromValue(this->m_updateUser);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CViewUpdateSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CViewUpdateSettings>(); return; }
|
||||
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAircraft:
|
||||
this->m_updateAircraft = variant.value<CTime>();
|
||||
break;
|
||||
case IndexAtc:
|
||||
this->m_updateAtc = variant.value<CTime>();
|
||||
break;
|
||||
case IndexRendering:
|
||||
this->m_updateRendering = variant.value<CTime>();
|
||||
break;
|
||||
case IndexUser:
|
||||
this->m_updateUser = variant.value<CTime>();
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
116
src/blackgui/settings/viewupdatesettings.h
Normal file
116
src/blackgui/settings/viewupdatesettings.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/* 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 BLACKGUI_SETTINGS_VIEWUPDATESETTINGS_H
|
||||
#define BLACKGUI_SETTINGS_VIEWUPDATESETTINGS_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/pq/time.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QMetaType>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
//! Settings about view update rates
|
||||
class BLACKGUI_EXPORT CViewUpdateSettings :
|
||||
public BlackMisc::CValueObject<CViewUpdateSettings>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexAtc = BlackMisc::CPropertyIndex::GlobalIndexCViewUpdateSettings,
|
||||
IndexAircraft,
|
||||
IndexRendering,
|
||||
IndexUser
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CViewUpdateSettings();
|
||||
|
||||
//! Reset to defaults
|
||||
void reset();
|
||||
|
||||
//! Get time
|
||||
const BlackMisc::PhysicalQuantities::CTime &getAtcUpdateTime() const { return m_updateAtc; }
|
||||
|
||||
//! Set time
|
||||
void setAtcUpdateTime(const BlackMisc::PhysicalQuantities::CTime &time) { this->m_updateAtc = time; }
|
||||
|
||||
//! Get time
|
||||
const BlackMisc::PhysicalQuantities::CTime &getAircraftUpdateTime() const { return m_updateAircraft; }
|
||||
|
||||
//! Set time
|
||||
void setAircraftUpdateTime(const BlackMisc::PhysicalQuantities::CTime &time) { this->m_updateAircraft = time; }
|
||||
|
||||
//! Get time
|
||||
const BlackMisc::PhysicalQuantities::CTime &getUserUpdateTime() const { return m_updateUser; }
|
||||
|
||||
//! Set time
|
||||
void setUserUpdateTime(const BlackMisc::PhysicalQuantities::CTime &time) { this->m_updateUser = time; }
|
||||
|
||||
//! Get time
|
||||
const BlackMisc::PhysicalQuantities::CTime &getRenderingUpdateTime() const { return m_updateRendering; }
|
||||
|
||||
//! Set time
|
||||
void setRenderingUpdateTime(const BlackMisc::PhysicalQuantities::CTime &time) { this->m_updateRendering = time; }
|
||||
|
||||
//! Valid?
|
||||
bool isValid() const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \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);
|
||||
|
||||
private:
|
||||
BlackMisc::PhysicalQuantities::CTime m_updateAtc;
|
||||
BlackMisc::PhysicalQuantities::CTime m_updateAircraft;
|
||||
BlackMisc::PhysicalQuantities::CTime m_updateRendering;
|
||||
BlackMisc::PhysicalQuantities::CTime m_updateUser;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CViewUpdateSettings,
|
||||
BLACK_METAMEMBER(updateAtc),
|
||||
BLACK_METAMEMBER(updateAircraft),
|
||||
BLACK_METAMEMBER(updateRendering),
|
||||
BLACK_METAMEMBER(updateUser)
|
||||
);
|
||||
};
|
||||
|
||||
//! Trait for settings about update rates
|
||||
struct TViewUpdateSettings : public BlackMisc::TSettingTrait<CViewUpdateSettings>
|
||||
{
|
||||
//! Key in data cache
|
||||
static const char *key() { return "guiviewupdatesettings"; }
|
||||
|
||||
//! Validator function.
|
||||
static bool isValid(const CViewUpdateSettings &settings) { return settings.isValid(); }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackGui::Settings::CViewUpdateSettings)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackGui::Settings::CViewUpdateSettings>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackGui::Settings::CViewUpdateSettings>)
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user