mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 09:15:34 +08:00
refs #799, own component for view update times
* utility function in CTime * settings class for update times
This commit is contained in:
54
src/blackgui/components/settingsviewupdatetimes.cpp
Normal file
54
src/blackgui/components/settingsviewupdatetimes.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/* 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 "settingsviewupdatetimes.h"
|
||||
#include "ui_settingsviewupdatetimes.h"
|
||||
|
||||
using namespace BlackGui::Settings;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
CSettingsViewUpdateTimes::CSettingsViewUpdateTimes(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::CSettingsViewUpdateTimes)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->hs_RenderingUpdateTime, &QSlider::sliderReleased, this, &CSettingsViewUpdateTimes::ps_sliderChanged);
|
||||
connect(ui->hs_AircraftUpdateTime, &QSlider::sliderReleased, this, &CSettingsViewUpdateTimes::ps_sliderChanged);
|
||||
connect(ui->hs_AtcUpdateTime, &QSlider::sliderReleased, this, &CSettingsViewUpdateTimes::ps_sliderChanged);
|
||||
connect(ui->hs_UserUpdateTime, &QSlider::sliderReleased, this, &CSettingsViewUpdateTimes::ps_sliderChanged);
|
||||
this->ps_settingsChanged();
|
||||
}
|
||||
|
||||
CSettingsViewUpdateTimes::~CSettingsViewUpdateTimes()
|
||||
{ }
|
||||
|
||||
void CSettingsViewUpdateTimes::ps_sliderChanged()
|
||||
{
|
||||
CViewUpdateSettings settings;
|
||||
settings.setAircraftUpdateTime(CTime(ui->hs_AircraftUpdateTime->value(), CTimeUnit::s()));
|
||||
settings.setAtcUpdateTime(CTime(ui->hs_AtcUpdateTime->value(), CTimeUnit::s()));
|
||||
settings.setRenderingUpdateTime(CTime(ui->hs_RenderingUpdateTime->value(), CTimeUnit::s()));
|
||||
settings.setUserUpdateTime(CTime(ui->hs_UserUpdateTime->value(), CTimeUnit::s()));
|
||||
m_settings.setAndSave(settings);
|
||||
}
|
||||
|
||||
void CSettingsViewUpdateTimes::ps_settingsChanged()
|
||||
{
|
||||
const CViewUpdateSettings settings(this->m_settings.get());
|
||||
ui->hs_AircraftUpdateTime->setValue(settings.getAircraftUpdateTime().toSeconds());
|
||||
ui->hs_AtcUpdateTime->setValue(settings.getAtcUpdateTime().toSeconds());
|
||||
ui->hs_RenderingUpdateTime->setValue(settings.getRenderingUpdateTime().toSeconds());
|
||||
ui->hs_UserUpdateTime->setValue(settings.getUserUpdateTime().toSeconds());
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
51
src/blackgui/components/settingsviewupdatetimes.h
Normal file
51
src/blackgui/components/settingsviewupdatetimes.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* 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_COMPONENTS_SETTINGSVIEWUPDATETIMES_H
|
||||
#define BLACKGUI_COMPONENTS_SETTINGSVIEWUPDATETIMES_H
|
||||
|
||||
#include "blackgui/settings/viewupdatesettings.h"
|
||||
#include <QFrame>
|
||||
|
||||
namespace Ui { class CSettingsViewUpdateTimes; }
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
/*!
|
||||
* Update rates / times
|
||||
*/
|
||||
class CSettingsViewUpdateTimes : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CSettingsViewUpdateTimes(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
~CSettingsViewUpdateTimes();
|
||||
|
||||
private slots:
|
||||
//! Slider changed
|
||||
void ps_sliderChanged();
|
||||
|
||||
//! Settings have been changed
|
||||
void ps_settingsChanged();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CSettingsViewUpdateTimes> ui;
|
||||
BlackMisc::CSetting<BlackGui::Settings::TViewUpdateSettings> m_settings { this, &CSettingsViewUpdateTimes::ps_settingsChanged }; //!< settings changed
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
196
src/blackgui/components/settingsviewupdatetimes.ui
Normal file
196
src/blackgui/components/settingsviewupdatetimes.ui
Normal file
@@ -0,0 +1,196 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CSettingsViewUpdateTimes</class>
|
||||
<widget class="QFrame" name="CSettingsViewUpdateTimes">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>184</width>
|
||||
<height>159</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_ViewUpdateTimes">
|
||||
<property name="title">
|
||||
<string>View update times</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="fl_ViewRefreshTimes">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_AircraftUpdateTime">
|
||||
<property name="toolTip">
|
||||
<string>Aircraft update time (5-30s)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Aircraft</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSlider" name="hs_AircraftUpdateTime">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lbl_AtcUpdateTime">
|
||||
<property name="toolTip">
|
||||
<string>ATC update time (5-30s)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>ATC</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSlider" name="hs_AtcUpdateTime">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lbl_UserUpdateTime">
|
||||
<property name="toolTip">
|
||||
<string>User update time (5-30s)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>User</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSlider" name="hs_UserUpdateTime">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_RenderingUpdateTime">
|
||||
<property name="toolTip">
|
||||
<string>Rendering update time (5-30s)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Rendering</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSlider" name="hs_RenderingUpdateTime">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>lbl_UserUpdateTime</zorder>
|
||||
<zorder>lbl_AtcUpdateTime</zorder>
|
||||
<zorder>lbl_AircraftUpdateTime</zorder>
|
||||
<zorder>hs_UserUpdateTime</zorder>
|
||||
<zorder>hs_AtcUpdateTime</zorder>
|
||||
<zorder>hs_AircraftUpdateTime</zorder>
|
||||
<zorder>lbl_RenderingUpdateTime</zorder>
|
||||
<zorder>hs_RenderingUpdateTime</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "blackgui/registermetadata.h"
|
||||
#include "blackgui/settings/dockwidgetsettings.h"
|
||||
#include "blackgui/settings/navigatorsettings.h"
|
||||
#include "blackgui/settings/viewupdatesettings.h"
|
||||
#include "blackgui/components/registermetadatacomponents.h"
|
||||
|
||||
namespace BlackGui
|
||||
@@ -18,6 +19,7 @@ namespace BlackGui
|
||||
{
|
||||
BlackGui::Settings::CDockWidgetSettings::registerMetadata();
|
||||
BlackGui::Settings::CNavigatorSettings::registerMetadata();
|
||||
BlackGui::Settings::CViewUpdateSettings::registerMetadata();
|
||||
BlackGui::Components::registerMetadata();
|
||||
}
|
||||
}
|
||||
|
||||
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