7#include <QDesktopServices>
15#include <QStringBuilder>
20#include "ui_dbownmodelsetcomponent.h"
29#include "gui/menus/aircraftmodelmenus.h"
30#include "gui/menus/menuaction.h"
45using namespace swift::misc::simulation;
47using namespace swift::gui::menus;
57 ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuStashing);
62 ui->tvp_OwnModelSet->addFilterDialog();
63 ui->tvp_OwnModelSet->setCustomMenu(
new CLoadModelSetMenu(
this));
68 ui->tvp_OwnModelSet->setSorting(CAircraftModel::IndexOrderString);
69 ui->tvp_OwnModelSet->initAsOrderable();
72 ui->tvp_OwnModelSet->setCorrespondingSimulator(sim, m_simulatorSettings.getSimulatorDirectoryOrDefault(sim));
74 ui->comp_SimulatorSelector->setRememberSelectionAndSetToLastSelection();
75 const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue();
76 ui->le_Simulator->setText(simulator.toQString(
true));
79 ui->pb_SaveAsSetForSimulator->setStyleSheet(
"padding-left: 3px; padding-right: 3px;");
107 this->triggerSetSimulatorDeferred(simulator);
116 using namespace std::chrono_literals;
122 ui->tvp_OwnModelSet->clear();
127 models.matchesSimulator(simulator));
128 const int diff =
models.size() - cleanModelList.
size();
137 ui->tvp_OwnModelSet->updateContainerMaybeAsync(cleanModelList);
142 using namespace std::chrono_literals;
150 models.matchesSimulator(simulator));
151 const int diff =
models.size() - cleanModelList.
size();
166 ui->tvp_OwnModelSet->updateContainerMaybeAsync(updatedModels);
199 u
"Cannot add data for " % simulator.
toQString(
true) % u
" to " %
204 const bool allowExcludedModels = m_modelSettings.get().getAllowExcludedModels();
209 if (!allowExcludedModels)
214 ui->tvp_OwnModelSet->updateContainerMaybeAsync(
updateModels);
232 &CDbOwnModelSetComponent::tabIndexChanged);
238 ui->pb_FirstSet->setEnabled(firstSet);
239 ui->pb_CreateNewSet->setEnabled(newSet);
242 void CDbOwnModelSetComponent::tabIndexChanged(
int index) { Q_UNUSED(index) }
244 void CDbOwnModelSetComponent::buttonClicked()
246 using namespace std::chrono_literals;
254 if (
sender == ui->pb_CreateNewSet)
256 this->createNewSet();
260 if (
sender == ui->pb_LoadExistingSet)
262 ui->tvp_OwnModelSet->showFileLoadDialog();
266 if (
sender == ui->pb_SaveAsSetForSimulator)
268 const CAircraftModelList ownModelSet(ui->tvp_OwnModelSet->container());
269 if (!ownModelSet.isEmpty())
276 const QString msg = QStringLiteral(
"Saved model set for '%1'").arg(sim.
toQString(
true));
281 ui->tvp_OwnModelSet->showOverlayHTMLMessage(msg, 5s);
288 ui->tvp_OwnModelSet->showOverlayMessage(m);
295 if (
sender == ui->pb_ShowStatistics)
297 this->showModelStatistics();
301 if (
sender == ui->pb_FirstSet)
307 if (
sender == ui->pb_CopyFromAnotherSwift)
309 this->copyFromAnotherSwift();
313 if (
sender == ui->pb_Clear)
315 ui->tvp_OwnModelSet->clear();
320 void CDbOwnModelSetComponent::onRowCountChanged(
int count,
bool withFilter)
325 const int realUnfilteredCount = ui->tvp_OwnModelSet->container().size();
327 ui->pb_SaveAsSetForSimulator->setEnabled(canSave);
331 ui->pb_SaveAsSetForSimulator->setText(
336 ui->pb_SaveAsSetForSimulator->setText(
"save");
340 void CDbOwnModelSetComponent::onJsonDataLoaded(
const CSimulatorInfo &simulator)
348 void CDbOwnModelSetComponent::distributorPreferencesChanged()
350 const CDistributorListPreferences preferences = m_distributorPreferences.getThreadLocal();
354 this->updateDistributorOrder(simuulator);
358 void CDbOwnModelSetComponent::reduceModels()
360 if (!m_reduceModelsDialog)
362 m_reduceModelsDialog.reset(
new CDbReduceModelDuplicates(
this));
365 CAircraftModelList models = ui->tvp_OwnModelSet->containerOrFilteredContainer();
367 m_reduceModelsDialog->setModels(models, simulator);
373 const CAircraftModelList removeModels = m_reduceModelsDialog->getRemoveCandidates();
374 const CSimulatorInfo removeSimulator = m_reduceModelsDialog->getSimulator();
384 void CDbOwnModelSetComponent::removeExcludedModels()
387 CAircraftModelList models = ui->tvp_OwnModelSet->containerOrFilteredContainer();
396 void CDbOwnModelSetComponent::removeNonDBModels()
399 CAircraftModelList models = ui->tvp_OwnModelSet->containerOrFilteredContainer();
408 void CDbOwnModelSetComponent::viewModelChanged()
410 const bool hasData = ui->tvp_OwnModelSet->rowCount() > 0;
411 ui->pb_SaveAsSetForSimulator->setEnabled(hasData);
414 void CDbOwnModelSetComponent::setSaveFileName(
const CSimulatorInfo &simulator)
417 const QString name(
"modelset" + simulator.
toQString(
true));
418 ui->tvp_OwnModelSet->setSaveFileName(name);
421 void CDbOwnModelSetComponent::updateViewToCurrentModels()
423 const CAircraftModelList models(this->
getModelSet());
424 ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
427 void CDbOwnModelSetComponent::createNewSet()
435 CLogMessage(
this).error(u
"No single simulator!");
442 CLogMessage(
this).error(u
"No mapping component available!");
446 mc->setOwnModelsSimulator(simulator);
447 if (!m_modelSetFormDialog)
449 m_modelSetFormDialog.reset(
new CDbOwnModelSetFormDialog(
this));
453 if (mc->getOwnModelsCount() > 0)
455 m_modelSetFormDialog->setModal(
true);
456 m_modelSetFormDialog->reloadData();
460 this->
setModelSet(m_modelSetFormDialog->getModelSet(), m_modelSetFormDialog->getSimulatorInfo());
465 const CStatusMessage m = CStatusMessage(
this).
error(u
"No model data for %1") << simulator.
toQString(
true);
466 mc->showOverlayMessage(m);
470 void CDbOwnModelSetComponent::firstSet()
472 if (!m_firstModelSetDialog)
474 m_firstModelSetDialog.reset(
new CFirstModelSetDialog(
this));
476 m_firstModelSetDialog->show();
479 void CDbOwnModelSetComponent::copyFromAnotherSwift()
481 if (!m_copyFromAnotherSwiftDialog)
483 m_copyFromAnotherSwiftDialog.reset(
new CCopyModelsFromOtherSwiftVersionsDialog(
this));
485 m_copyFromAnotherSwiftDialog->show();
490 if (m_simulator == simulator)
500 m_simulator = simulator;
501 ui->comp_SimulatorSelector->setValue(simulator);
502 ui->tvp_OwnModelSet->setCorrespondingSimulator(simulator,
503 m_simulatorSettings.getSimulatorDirectoryOrDefault(m_simulator));
504 ui->le_Simulator->setText(simulator.
toQString(
true));
506 this->updateViewToCurrentModels();
511 ui->comp_SimulatorSelector->setMode(mode);
520 if (!sApp || sApp->isShuttingDown())
532 void CDbOwnModelSetComponent::showModelStatistics()
535 if (!m_modelStatisticsDialog)
539 m_modelStatisticsDialog->analyzeModels(set);
540 m_modelStatisticsDialog->show();
543 void CDbOwnModelSetComponent::updateDistributorOrder(
const CSimulatorInfo &simulator)
561 if (simulator == currentSimulator)
563 ui->tvp_OwnModelSet->updateContainerAsync(modelSet);
569 void CDbOwnModelSetComponent::CLoadModelSetMenu::customMenu(CMenuActions &menuActions)
577 Q_ASSERT_X(ownModelSetComp, Q_FUNC_INFO,
"Cannot access parent");
578 if (m_setActions.isEmpty())
585 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::P3D));
587 m_setActions.append(a);
592 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::P3D));
594 m_setNewActions.append(a);
601 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::XPLANE));
603 m_setActions.append(a);
608 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::XPLANE));
610 m_setNewActions.append(a);
617 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::FG));
619 m_setActions.append(a);
624 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::FG));
626 m_setNewActions.append(a);
633 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::MSFS));
635 m_setActions.append(a);
640 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::MSFS));
642 m_setNewActions.append(a);
649 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::MSFS2024));
651 m_setActions.append(a);
656 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::MSFS2024));
658 m_setNewActions.append(a);
664 m_setActions.append(a);
666 a =
new QAction(
CIcons::delete16(),
"Reduce models (remove duplicates)",
this);
669 m_setActions.append(a);
674 m_setActions.append(a);
679 m_setActions.append(a);
static QDialog * findParentDialog(QWidget *widget)
Find parent dialog if there is any, otherwise null.
bool showMappingComponentOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Overlay messages.
CDbMappingComponent * getMappingComponent() const
Get the mapping component.
bool showMappingComponentOverlayHtmlMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Overlay messages.
CDbMappingComponentAware(QObject *parent)
Constructor.
virtual void setMappingComponent(CDbMappingComponent *component)
Set the corresponding component.
void tabIndexChanged(int index)
Tab index has been changed.
const swift::misc::simulation::CAircraftModelList & getModelSetFromView() const
Current model set for simulator CDbOwnModelSetComponent::getModelSetSimulator.
swift::misc::simulation::CAircraftModelList getModelSet() const
Cached models for current simulator.
int getModelSetCountFromView() const
Current sount of model set for simulator CDbOwnModelSetComponent::getModelSetSimulator.
int replaceOrAddModelSet(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator)
Replace or add models provided for a given simulator.
swift::misc::simulation::CSimulatorInfo getSelectedSimulator() const
Simulator.
void setSimulator(const swift::misc::simulation::CSimulatorInfo &simulator)
Simulator.
swift::misc::CStatusMessage addToModelSet(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator)
Add to model set.
~CDbOwnModelSetComponent()
Destructor.
views::CAircraftModelView * view() const
Corresponding view.
void setSimulatorSelectorMode(CSimulatorSelector::Mode mode)
How to display.
swift::misc::simulation::CSimulatorInfo getModelSetSimulator() const
Model set is for simulator.
void setMappingComponent(CDbMappingComponent *component)
Set the corresponding component.
void triggerSetSimulatorDeferred(const swift::misc::simulation::CSimulatorInfo &simulator)
Deferred init of simulator.
CDbOwnModelSetComponent(QWidget *parent=nullptr)
Constructor.
void setModelSet(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator)
Set the model set for a given simulator.
int updateModels(const swift::misc::simulation::CAircraftModelList &models)
Update models.
void enableButtons(bool firstSet, bool newSet)
Enable buttons.
void changed(const swift::misc::simulation::CSimulatorInfo &simulator)
Value has been changed.
@ OwnModelSet
own model set
void jsonModelsForSimulatorLoaded(const swift::misc::simulation::CSimulatorInfo &simulator)
Models for simulator loaded (JSON).
void modelChanged()
Model bas been changed (means data in view have been changed).
void requestUpdate()
Ask for new data from currently loaded data.
void modelDataChanged(int count, bool withFilter)
Model data changed.
@ MenuClear
allow clearing the view via menu
@ MenuDisplayAutomaticallyAndRefresh
should come together
@ MenuRefresh
allow refreshing the view via menu
@ MenuOrderable
items can be ordered (if container is swift::misc::IOrderableList
@ MenuBackend
allow to request data from backend
@ MenuRemoveSelectedRows
allow to remove selected rows
@ MenuMaterializeFilter
materialize filter (filtered data become model data)
const T & getThreadLocal() const
Read the current value.
static const QPixmap & appModels16()
Models.
static const QPixmap & appDistributors16()
Distributors.
static const QPixmap & delete16()
Delete.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
size_type size() const
Returns number of elements in the sequence.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
bool isSuccess() const
Operation considered successful.
static constexpr auto SeverityInfo
Status severities.
static constexpr auto SeverityError
Status severities.
const CONTAINER & container() const
Container.
void resetOrder(int offset=0)
Set order member to current order.
int removeObjectsWithoutDbKey()
Remove objects without key.
QString toQString(bool i18n=false) const
Cast as QString.
Aircraft model (used by another pilot, my models on disk).
Value object encapsulating a list of aircraft models.
QStringList getModelStringList(bool sort=true) const
Model strings.
int replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity)
Replace or add based on model string.
int removeIfExcluded()
Remove if excluded CAircraftModel::Exclude.
int removeModelsWithString(const CAircraftModelList &models, Qt::CaseSensitivity sensitivity)
Remove those models with given model strings.
int updateDistributorOrder(const CDistributorList &distributors)
From given CDistributorList update the model`s distributor order.
Value object encapsulating a list of distributors.
Preferences for distributors.
const CSimulatorInfo & getLastUpdatedSimulator() const
Last updated simulator.
const CDistributorList & getDistributors(const CSimulatorInfo &simulator) const
Get distributors.
Simple hardcoded info about the corresponding simulator.
static const CSimulatorInfo & allSimulators()
All simulators.
bool isMSFS2024() const
MSFS2024?
bool isSingleSimulator() const
Single simulator selected.
bool isNoSimulator() const
No simulator?
bool isUnspecified() const
Unspecified simulator.
bool isXPlane() const
XPlane.
void admitCache(const CSimulatorInfo &simulator)
Look like IMultiSimulatorModelCaches interface.
CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const
Look like IMultiSimulatorModelCaches interface.
CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
Look like IMultiSimulatorModelCaches interface.
void synchronizeCache(const CSimulatorInfo &simulator)
Look like IMultiSimulatorModelCaches interface.
High level reusable GUI components.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.
void triggered(bool checked)
QFrame(QWidget *parent, Qt::WindowFlags f)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
T qobject_cast(QObject *object)
QObject * sender() const const
QString number(double n, char format, int precision)