mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Ref T246, use different caches to remember single/multi simulator selections
* selector UI "can remember" * different caches
This commit is contained in:
@@ -135,7 +135,7 @@ namespace BlackGui
|
|||||||
// those caches do not harm if they exists default initialized
|
// those caches do not harm if they exists default initialized
|
||||||
//! \fixme this is a workaround, as it creates files on disk even if those are not copied. It was much nicer if the cache would init themself if the file appears
|
//! \fixme this is a workaround, as it creates files on disk even if those are not copied. It was much nicer if the cache would init themself if the file appears
|
||||||
BlackMisc::CData<BlackMisc::Network::Data::TLastServer> m_lastServer { this }; //!< recently used server (VATSIM, other)
|
BlackMisc::CData<BlackMisc::Network::Data::TLastServer> m_lastServer { this }; //!< recently used server (VATSIM, other)
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetLastSelection> m_modelSetCurrentSimulator { this };
|
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelection> m_modelSetCurrentSimulator { this };
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_modelsCurrentSimulator { this };
|
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_modelsCurrentSimulator { this };
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TLastModel> m_lastAircraftModel { this }; //!< recently used aircraft model
|
BlackMisc::CData<BlackMisc::Simulation::Data::TLastModel> m_lastAircraftModel { this }; //!< recently used aircraft model
|
||||||
BlackMisc::CData<BlackCore::Data::TLauncherSetup> m_launcherSetup { this };
|
BlackMisc::CData<BlackCore::Data::TLauncherSetup> m_launcherSetup { this };
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
|
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
|
||||||
|
ui->comp_SimulatorSelector->setRememberSelection(true);
|
||||||
ui->comp_SimulatorSelector->setValue(simulator);
|
ui->comp_SimulatorSelector->setValue(simulator);
|
||||||
|
|
||||||
connect(ui->pb_All, &QPushButton::pressed, this, &CDistributorPreferencesComponent::ps_loadAll);
|
connect(ui->pb_All, &QPushButton::pressed, this, &CDistributorPreferencesComponent::ps_loadAll);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace BlackGui
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setSmallLayout(true); // no disadvantage, so I always set it
|
this->setSmallLayout(true); // no disadvantage, so I always set it
|
||||||
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
|
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
|
||||||
|
ui->comp_SimulatorSelector->setRememberSelection(true);
|
||||||
ui->comp_SimulatorSelector->setToLastSelection();
|
ui->comp_SimulatorSelector->setToLastSelection();
|
||||||
connect(ui->pb_ExcludeFileDialog, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::excludeFileDialog);
|
connect(ui->pb_ExcludeFileDialog, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::excludeFileDialog);
|
||||||
connect(ui->pb_ModelFileDialog, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::modelFileDialog);
|
connect(ui->pb_ModelFileDialog, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::modelFileDialog);
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ namespace BlackGui
|
|||||||
ui->wi_RadioButtons->setVisible(true);
|
ui->wi_RadioButtons->setVisible(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
this->setToLastSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorInfo CSimulatorSelector::getValue() const
|
CSimulatorInfo CSimulatorSelector::getValue() const
|
||||||
@@ -99,8 +100,10 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CSimulatorSelector::setToLastSelection()
|
void CSimulatorSelector::setToLastSelection()
|
||||||
{
|
{
|
||||||
const CSimulatorInfo sim = m_currentSimulator.get();
|
const CSimulatorInfo simulator = (m_mode == RadioButtons) ?
|
||||||
this->setValue(sim);
|
m_currentSimulator.get() :
|
||||||
|
m_currentSimulators.get();
|
||||||
|
this->setValue(simulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSimulatorSelector::setAll()
|
void CSimulatorSelector::setAll()
|
||||||
@@ -166,6 +169,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (m_mode != RadioButtons) { return; }
|
if (m_mode != RadioButtons) { return; }
|
||||||
if (!checked) { return; } // only the checked ones are relevant, as the unchecked ones are accompanied with checked events
|
if (!checked) { return; } // only the checked ones are relevant, as the unchecked ones are accompanied with checked events
|
||||||
|
this->rememberSelection();
|
||||||
emit this->changed(this->getValue());
|
emit this->changed(this->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +177,27 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
if (m_mode != CheckBoxes) { return; }
|
if (m_mode != CheckBoxes) { return; }
|
||||||
Q_UNUSED(checked);
|
Q_UNUSED(checked);
|
||||||
|
this->rememberSelection();
|
||||||
emit this->changed(this->getValue());
|
emit this->changed(this->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSimulatorSelector::rememberSelection()
|
||||||
|
{
|
||||||
|
if (!m_rememberSelection) { return; }
|
||||||
|
if (m_mode == RadioButtons)
|
||||||
|
{
|
||||||
|
m_currentSimulator.set(this->getValue());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_currentSimulators.set(this->getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSimulatorSelector::changedLastSelection()
|
||||||
|
{
|
||||||
|
// forece decoupled update
|
||||||
|
QTimer::singleShot(100, this, &CSimulatorSelector::setToLastSelection);
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ namespace BlackGui
|
|||||||
//! Set left margin
|
//! Set left margin
|
||||||
void setLeftMargin(int margin);
|
void setLeftMargin(int margin);
|
||||||
|
|
||||||
|
//! Remember selection
|
||||||
|
void setRememberSelection(bool remember) { m_rememberSelection = remember; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Value has been changed
|
//! Value has been changed
|
||||||
void changed(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
void changed(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
@@ -86,11 +89,18 @@ namespace BlackGui
|
|||||||
//! Checkbox changed
|
//! Checkbox changed
|
||||||
void checkBoxChanged(bool checked);
|
void checkBoxChanged(bool checked);
|
||||||
|
|
||||||
private:
|
//! Remember last selection
|
||||||
|
void rememberSelection();
|
||||||
|
|
||||||
|
//! Last selection has been changed
|
||||||
|
void changedLastSelection();
|
||||||
|
|
||||||
QScopedPointer<Ui::CSimulatorSelector> ui;
|
QScopedPointer<Ui::CSimulatorSelector> ui;
|
||||||
Mode m_mode = CheckBoxes;
|
Mode m_mode = CheckBoxes;
|
||||||
bool m_noSelectionMeansAll = false; //!< for filters, no selection means all
|
bool m_noSelectionMeansAll = false; //!< for filters, no selection means all
|
||||||
BlackMisc::CDataReadOnly<BlackMisc::Simulation::Data::TModelSetLastSelection> m_currentSimulator { this }; //!< current simulator
|
bool m_rememberSelection = false; //!< remember last selection
|
||||||
|
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelection> m_currentSimulator { this, &CSimulatorSelector::changedLastSelection }; //!< current simulator (used with radio buttons)
|
||||||
|
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelections> m_currentSimulators { this, &CSimulatorSelector::changedLastSelection }; //!< current simulators (used with multiple checkboxes)
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace BlackMisc
|
|||||||
};
|
};
|
||||||
|
|
||||||
//! Last selection
|
//! Last selection
|
||||||
struct TModelSetLastSelection : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo>
|
struct TSimulatorLastSelection : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo>
|
||||||
{
|
{
|
||||||
//! First load is synchronous
|
//! First load is synchronous
|
||||||
static constexpr bool isPinned() { return true; }
|
static constexpr bool isPinned() { return true; }
|
||||||
@@ -121,7 +121,20 @@ namespace BlackMisc
|
|||||||
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
|
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
|
||||||
|
|
||||||
//! Key
|
//! Key
|
||||||
static const char *key() { return "modelsetlastselection"; }
|
static const char *key() { return "simulatorlastselection"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Last selections
|
||||||
|
struct TSimulatorLastSelections : public BlackMisc::TDataTrait<BlackMisc::Simulation::CSimulatorInfo>
|
||||||
|
{
|
||||||
|
//! First load is synchronous
|
||||||
|
static constexpr bool isPinned() { return true; }
|
||||||
|
|
||||||
|
//! Default simulator
|
||||||
|
static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); }
|
||||||
|
|
||||||
|
//! Key
|
||||||
|
static const char *key() { return "simulatorlastselections"; }
|
||||||
};
|
};
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
@@ -319,7 +332,7 @@ namespace BlackMisc
|
|||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheFs9> m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache
|
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheFs9> m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache
|
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache
|
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::TModelSetLastSelection> m_currentSimulator { this }; //!< current simulator
|
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelection> m_currentSimulator { this }; //!< current simulator
|
||||||
|
|
||||||
//! Non virtual version (can be used in ctor)
|
//! Non virtual version (can be used in ctor)
|
||||||
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
|
|||||||
Reference in New Issue
Block a user