mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 09:45:44 +08:00
* removed CDockWidgetsSettings (note Widgets, not Widget) * goal: Use CDockWidgetSettings for all dock widgets refs #684
This commit is contained in:
@@ -103,7 +103,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CDockWidgetSettings s = this->getSettings();
|
CDockWidgetSettings s = this->getSettings();
|
||||||
s.setMarginsWhenFloating(margins);
|
s.setMarginsWhenFloating(margins);
|
||||||
this->setSettings(s);
|
this->saveSettings(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::setMarginsWhenFloating(int left, int top, int right, int bottom)
|
void CDockWidget::setMarginsWhenFloating(int left, int top, int right, int bottom)
|
||||||
@@ -120,7 +120,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CDockWidgetSettings s = this->getSettings();
|
CDockWidgetSettings s = this->getSettings();
|
||||||
s.setMarginsWhenFramelessFloating(margins);
|
s.setMarginsWhenFramelessFloating(margins);
|
||||||
this->setSettings(s);
|
this->saveSettings(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::setMarginsWhenFramelessFloating(int left, int top, int right, int bottom)
|
void CDockWidget::setMarginsWhenFramelessFloating(int left, int top, int right, int bottom)
|
||||||
@@ -137,7 +137,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
CDockWidgetSettings s = this->getSettings();
|
CDockWidgetSettings s = this->getSettings();
|
||||||
s.setMarginsWhenDocked(margins);
|
s.setMarginsWhenDocked(margins);
|
||||||
this->setSettings(s);
|
this->saveSettings(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::setMarginsWhenDocked(int left, int top, int right, int bottom)
|
void CDockWidget::setMarginsWhenDocked(int left, int top, int right, int bottom)
|
||||||
@@ -343,7 +343,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
// State actions (windows state)
|
// State actions (windows state)
|
||||||
contextMenu->addAction(BlackMisc::CIcons::load16(), "Restore", this, &CDockWidget::restoreFromSettings);
|
contextMenu->addAction(BlackMisc::CIcons::load16(), "Restore", this, &CDockWidget::restoreFromSettings);
|
||||||
contextMenu->addAction(BlackMisc::CIcons::save16(), "Save state", this, &CDockWidget::saveToSettings);
|
contextMenu->addAction(BlackMisc::CIcons::save16(), "Save state", this, &CDockWidget::saveCurrentStateToSettings);
|
||||||
contextMenu->addAction(BlackMisc::CIcons::refresh16(), "Reset to defaults", this, &CDockWidget::resetSettings);
|
contextMenu->addAction(BlackMisc::CIcons::refresh16(), "Reset to defaults", this, &CDockWidget::resetSettings);
|
||||||
contextMenu->addAction(BlackMisc::CIcons::refresh16(), "Reset position", this, &CDockWidget::resetPosition);
|
contextMenu->addAction(BlackMisc::CIcons::refresh16(), "Reset position", this, &CDockWidget::resetPosition);
|
||||||
|
|
||||||
@@ -354,10 +354,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CDockWidget::initialFloating()
|
void CDockWidget::initialFloating()
|
||||||
{
|
{
|
||||||
// settings, ii here because name now is set
|
// init status bar, as we have now all structures set and name is known
|
||||||
this->initSettings();
|
|
||||||
|
|
||||||
// init status bar, as we have now all structures set
|
|
||||||
this->initStatusBarAndProperties();
|
this->initStatusBarAndProperties();
|
||||||
|
|
||||||
// for the first time resize
|
// for the first time resize
|
||||||
@@ -386,10 +383,10 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CDockWidget::ps_onTopLevelChanged(bool topLevel)
|
void CDockWidget::ps_onTopLevelChanged(bool topLevel)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_LINUX
|
# ifdef Q_OS_LINUX
|
||||||
// Give XCB platforms enough time to handle window events before adjusting it.
|
// Give XCB platforms enough time to handle window events before adjusting it.
|
||||||
QThread::msleep(100);
|
QThread::msleep(100);
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
this->setMargins();
|
this->setMargins();
|
||||||
if (topLevel)
|
if (topLevel)
|
||||||
@@ -542,58 +539,37 @@ namespace BlackGui
|
|||||||
this->setStyleSheet(qss);
|
this->setStyleSheet(qss);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::initSettings()
|
|
||||||
{
|
|
||||||
const QString name(this->getNameForSettings());
|
|
||||||
CDockWidgetsSettings all = this->m_settings.get();
|
|
||||||
if (all.contains(name)) { return; }
|
|
||||||
all.getByNameOrInitToDefault(name);
|
|
||||||
this->m_settings.setAndSave(all);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CDockWidget::getNameForSettings() const
|
|
||||||
{
|
|
||||||
const QString n(this->objectName().toLower().remove(' '));
|
|
||||||
Q_ASSERT_X(!n.isEmpty(), Q_FUNC_INFO, "No settings name");
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
CDockWidgetSettings CDockWidget::getSettings() const
|
CDockWidgetSettings CDockWidget::getSettings() const
|
||||||
{
|
{
|
||||||
const CDockWidgetsSettings all = this->m_settings.get();
|
Q_ASSERT_X(!this->objectName().isEmpty(), Q_FUNC_INFO, "Need object name for settings %OwnerName%");
|
||||||
const QString name(this->getNameForSettings());
|
const CDockWidgetSettings s = this->m_settings.get();
|
||||||
const CDockWidgetSettings s = all.value(name);
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::setSettings(const CDockWidgetSettings &settings)
|
void CDockWidget::saveSettings(const CDockWidgetSettings &settings)
|
||||||
{
|
{
|
||||||
const CDockWidgetSettings current = getSettings();
|
Q_ASSERT_X(!this->objectName().isEmpty(), Q_FUNC_INFO, "Need object name for settings %OwnerName%");
|
||||||
if (current == settings) { return; }
|
const CStatusMessage m = this->m_settings.setAndSave(settings);
|
||||||
CDockWidgetsSettings all = this->m_settings.get();
|
|
||||||
const QString name(this->getNameForSettings());
|
|
||||||
all.insert(name, settings);
|
|
||||||
const CStatusMessage m = this->m_settings.set(all); // saved when shutdown
|
|
||||||
if (m.isFailure())
|
if (m.isFailure())
|
||||||
{
|
{
|
||||||
CLogMessage::preformatted(m);
|
CLogMessage::preformatted(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::saveToSettings()
|
void CDockWidget::saveCurrentStateToSettings()
|
||||||
{
|
{
|
||||||
CDockWidgetSettings s = this->getSettings();
|
CDockWidgetSettings s = this->getSettings();
|
||||||
s.setFloating(this->isFloating());
|
s.setFloating(this->isFloating());
|
||||||
s.setFrameless(this->isFrameless());
|
s.setFrameless(this->isFrameless());
|
||||||
s.setGeometry(this->saveGeometry());
|
s.setGeometry(this->saveGeometry());
|
||||||
this->setSettings(s);
|
this->saveSettings(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDockWidget::resetSettings()
|
void CDockWidget::resetSettings()
|
||||||
{
|
{
|
||||||
CDockWidgetSettings s = this->getSettings();
|
CDockWidgetSettings s = this->getSettings();
|
||||||
s.reset();
|
s.reset();
|
||||||
this->setSettings(s);
|
this->saveSettings(s);
|
||||||
this->restoreFromSettings();
|
this->restoreFromSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ namespace BlackGui
|
|||||||
bool restoreFromSettings();
|
bool restoreFromSettings();
|
||||||
|
|
||||||
//! Remember widget state
|
//! Remember widget state
|
||||||
void saveToSettings();
|
void saveCurrentStateToSettings();
|
||||||
|
|
||||||
//! Reset margin settings
|
//! Reset margin settings
|
||||||
void resetSettings();
|
void resetSettings();
|
||||||
@@ -231,11 +231,11 @@ namespace BlackGui
|
|||||||
QPoint m_offsetWhenFloating; //!< initial offset to main window when floating first time
|
QPoint m_offsetWhenFloating; //!< initial offset to main window when floating first time
|
||||||
bool m_allowStatusBar = true;
|
bool m_allowStatusBar = true;
|
||||||
bool m_windowTitleWhenDocked = true;
|
bool m_windowTitleWhenDocked = true;
|
||||||
bool m_wasAlreadyFloating = false;
|
bool m_wasAlreadyFloating = false; //!< flag if widget was at least once in floating state
|
||||||
bool m_selected = false; //!< selected when tabbed
|
bool m_selected = false; //!< selected when tabbed
|
||||||
bool m_dockWidgetVisible = false; //!< logical visible, not to be confused with QDockWidget::isVisible()
|
bool m_dockWidgetVisible = false; //!< logical visible, not to be confused with QDockWidget::isVisible()
|
||||||
bool m_wasFrameless = false; //!< frameless when last floating
|
bool m_wasFrameless = false; //!< frameless when last floating
|
||||||
BlackMisc::CSetting<BlackGui::Settings::TDockWidgets> m_settings { this, &CDockWidget::ps_settingsChanged }; //!< all docked wigets settings
|
BlackMisc::CSetting<BlackGui::Settings::TDockWidget> m_settings { this, &CDockWidget::ps_settingsChanged }; //!< all docked wigets settings
|
||||||
|
|
||||||
//! Empty widget with no size
|
//! Empty widget with no size
|
||||||
void initTitleBarWidgets();
|
void initTitleBarWidgets();
|
||||||
@@ -246,17 +246,11 @@ namespace BlackGui
|
|||||||
//! Force a style sheet update
|
//! Force a style sheet update
|
||||||
void forceStyleSheetUpdate();
|
void forceStyleSheetUpdate();
|
||||||
|
|
||||||
//! Init settings
|
|
||||||
void initSettings();
|
|
||||||
|
|
||||||
//! Name used as key for settings
|
|
||||||
QString getNameForSettings() const;
|
|
||||||
|
|
||||||
//! This widget`s settings
|
//! This widget`s settings
|
||||||
BlackGui::Settings::CDockWidgetSettings getSettings() const;
|
BlackGui::Settings::CDockWidgetSettings getSettings() const;
|
||||||
|
|
||||||
//! Save my updated settings
|
//! Save settings
|
||||||
void setSettings(const BlackGui::Settings::CDockWidgetSettings &settings);
|
void saveSettings(const BlackGui::Settings::CDockWidgetSettings &settings);
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ namespace BlackGui
|
|||||||
void registerMetadata()
|
void registerMetadata()
|
||||||
{
|
{
|
||||||
BlackGui::Settings::CDockWidgetSettings::registerMetadata();
|
BlackGui::Settings::CDockWidgetSettings::registerMetadata();
|
||||||
BlackGui::Settings::CDockWidgetsSettings::registerMetadata();
|
|
||||||
BlackGui::Settings::CNavigatorSettings::registerMetadata();
|
BlackGui::Settings::CNavigatorSettings::registerMetadata();
|
||||||
BlackGui::Components::registerMetadata();
|
BlackGui::Components::registerMetadata();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,25 +149,5 @@ namespace BlackGui
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CDockWidgetSettings CDockWidgetsSettings::getByNameOrInitToDefault(const QString &name)
|
|
||||||
{
|
|
||||||
if (this->contains(name)) { return this->value(name); }
|
|
||||||
CDockWidgetSettings s;
|
|
||||||
|
|
||||||
// default values can be set here, this could be enhanced if needed
|
|
||||||
// e.g. by platform dependent defaults
|
|
||||||
s.reset();
|
|
||||||
this->insert(name, s);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDockWidgetsSettings::resetToDefaults(const QString &name)
|
|
||||||
{
|
|
||||||
if (this->contains(name))
|
|
||||||
{
|
|
||||||
this->remove(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace BlackGui
|
|||||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
//! To string
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
QString convertToQString(const QString &separator, bool i18n = false) const;
|
QString convertToQString(const QString &separator, bool i18n = false) const;
|
||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||||
@@ -120,33 +120,13 @@ namespace BlackGui
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Needed to compile properly with Q_DECLARE_METATYPE
|
|
||||||
using CDockWidgetSettingsDictionary = BlackMisc::CDictionary<QString, CDockWidgetSettings, QMap>;
|
|
||||||
|
|
||||||
//! Settings for all dock widgets
|
|
||||||
class BLACKGUI_EXPORT CDockWidgetsSettings :
|
|
||||||
public CDockWidgetSettingsDictionary,
|
|
||||||
public BlackMisc::Mixin::MetaType<CDockWidgetsSettings>,
|
|
||||||
public BlackMisc::Mixin::JsonOperators<CDockWidgetsSettings>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CDockWidgetsSettings)
|
|
||||||
|
|
||||||
//! Default constructor.
|
|
||||||
CDockWidgetsSettings() {}
|
|
||||||
|
|
||||||
//! Get setting or init by estimated default values
|
|
||||||
CDockWidgetSettings getByNameOrInitToDefault(const QString &name);
|
|
||||||
|
|
||||||
//! Reset to defaults
|
|
||||||
void resetToDefaults(const QString &name);
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Trait for settings for dock widget
|
//! Trait for settings for dock widget
|
||||||
struct TDockWidgets : public BlackMisc::TSettingTrait<CDockWidgetsSettings>
|
//! \details All settings will go in one file, separated by application and object name
|
||||||
|
//! (of the parent object using this setting). If the object name is not set, it will not work correctly
|
||||||
|
struct TDockWidget : public BlackMisc::TSettingTrait<CDockWidgetSettings>
|
||||||
{
|
{
|
||||||
//! Key in data cache
|
//! Key in data cache https://dev.vatsim-germany.org/issues/776
|
||||||
static const char *key() { return "guidockwidget"; }
|
static const char *key() { return "guidockwidget/%Application%/%OwnerName%"; }
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
@@ -154,7 +134,5 @@ namespace BlackGui
|
|||||||
Q_DECLARE_METATYPE(BlackGui::Settings::CDockWidgetSettings)
|
Q_DECLARE_METATYPE(BlackGui::Settings::CDockWidgetSettings)
|
||||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackGui::Settings::CDockWidgetSettings>)
|
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackGui::Settings::CDockWidgetSettings>)
|
||||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackGui::Settings::CDockWidgetSettings>)
|
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackGui::Settings::CDockWidgetSettings>)
|
||||||
Q_DECLARE_METATYPE(BlackGui::Settings::CDockWidgetSettingsDictionary)
|
|
||||||
Q_DECLARE_METATYPE(BlackGui::Settings::CDockWidgetsSettings)
|
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user