7 #include <QDesktopServices>
13 #include <QPushButton>
15 #include <QStringBuilder>
20 #include "ui_dbownmodelsetcomponent.h"
29 #include "gui/menus/aircraftmodelmenus.h"
30 #include "gui/menus/menuaction.h"
45 using namespace swift::misc::simulation;
47 using namespace swift::gui::menus;
52 CDbOwnModelSetComponent::CDbOwnModelSetComponent(
QWidget *parent)
56 ui->tvp_OwnModelSet->setAircraftModelMode(CAircraftModelListModel::OwnModelSet);
57 ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuStashing);
58 ui->tvp_OwnModelSet->menuRemoveItems(CAircraftModelView::MenuDisplayAutomaticallyAndRefresh |
59 CAircraftModelView::MenuBackend);
60 ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows | CAircraftModelView::MenuClear |
61 CAircraftModelView::MenuMaterializeFilter);
62 ui->tvp_OwnModelSet->addFilterDialog();
63 ui->tvp_OwnModelSet->setCustomMenu(
new CLoadModelSetMenu(
this));
66 ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuLoadAndSave | CAircraftModelView::MenuRefresh |
67 CAircraftModelView::MenuOrderable);
68 ui->tvp_OwnModelSet->setSorting(CAircraftModel::IndexOrderString);
69 ui->tvp_OwnModelSet->initAsOrderable();
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;");
98 connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelDataChanged,
this,
100 connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged,
this,
102 connect(ui->tvp_OwnModelSet, &CAircraftModelView::requestUpdate,
this,
104 connect(ui->tvp_OwnModelSet, &CAircraftModelView::jsonModelsForSimulatorLoaded,
this,
116 using namespace std::chrono_literals;
122 ui->tvp_OwnModelSet->clear();
128 const int diff = models.
size() - cleanModelList.
size();
137 ui->tvp_OwnModelSet->updateContainerMaybeAsync(cleanModelList);
142 using namespace std::chrono_literals;
145 if (models.
isEmpty()) {
return 0; }
148 const int diff = models.
size() - cleanModelList.
size();
156 if (cleanModelList.
isEmpty()) {
return 0; }
160 ui->tvp_OwnModelSet->updateContainerMaybeAsync(updatedModels);
166 return ui->tvp_OwnModelSet->container();
180 if (models.
isEmpty()) {
return {
this, CStatusMessage::SeverityInfo, u
"No data",
true }; }
189 return {
this, CStatusMessage::SeverityError,
190 u
"Cannot add data for " % simulator.
toQString(
true) % u
" to " %
195 const bool allowExcludedModels = m_modelSettings.
get().getAllowExcludedModels();
200 if (!allowExcludedModels) {
updateModels.removeIfExcluded(); }
202 ui->tvp_OwnModelSet->updateContainerMaybeAsync(
updateModels);
203 return {
this, CStatusMessage::SeverityInfo,
208 else {
return {
this, CStatusMessage::SeverityInfo, u
"No data modified in model set",
true }; }
217 &CDbOwnModelSetComponent::tabIndexChanged);
223 ui->pb_FirstSet->setEnabled(firstSet);
224 ui->pb_CreateNewSet->setEnabled(newSet);
227 void CDbOwnModelSetComponent::tabIndexChanged(
int index) { Q_UNUSED(index) }
229 void CDbOwnModelSetComponent::buttonClicked()
231 using namespace std::chrono_literals;
236 if (
sender == ui->pb_CreateNewSet)
238 this->createNewSet();
242 if (
sender == ui->pb_LoadExistingSet)
244 ui->tvp_OwnModelSet->showFileLoadDialog();
248 if (
sender == ui->pb_SaveAsSetForSimulator)
251 if (!ownModelSet.isEmpty())
255 CLogMessage::preformatted(m);
263 ui->tvp_OwnModelSet->showOverlayHTMLMessage(msg, 5s);
274 if (
sender == ui->pb_ShowStatistics)
276 this->showModelStatistics();
280 if (
sender == ui->pb_FirstSet)
286 if (
sender == ui->pb_CopyFromAnotherSwift)
288 this->copyFromAnotherSwift();
292 if (
sender == ui->pb_Clear)
294 ui->tvp_OwnModelSet->clear();
299 void CDbOwnModelSetComponent::onRowCountChanged(
int count,
bool withFilter)
304 const int realUnfilteredCount = ui->tvp_OwnModelSet->container().size();
306 ui->pb_SaveAsSetForSimulator->setEnabled(canSave);
310 ui->pb_SaveAsSetForSimulator->setText(
313 else { ui->pb_SaveAsSetForSimulator->setText(
"save"); }
316 void CDbOwnModelSetComponent::onJsonDataLoaded(
const CSimulatorInfo &simulator)
321 void CDbOwnModelSetComponent::distributorPreferencesChanged()
325 if (simuulator.
isSingleSimulator()) { this->updateDistributorOrder(simuulator); }
328 void CDbOwnModelSetComponent::reduceModels()
330 if (!m_reduceModelsDialog) { m_reduceModelsDialog.reset(
new CDbReduceModelDuplicates(
this)); }
334 m_reduceModelsDialog->setModels(models, simulator);
338 const CSimulatorInfo removeSimulator = m_reduceModelsDialog->getSimulator();
339 if (removeModels.
isEmpty()) {
return; }
345 void CDbOwnModelSetComponent::removeExcludedModels()
350 if (r < 1) {
return; }
354 void CDbOwnModelSetComponent::removeNonDBModels()
359 if (r < 1) {
return; }
363 void CDbOwnModelSetComponent::viewModelChanged()
365 const bool hasData = ui->tvp_OwnModelSet->rowCount() > 0;
366 ui->pb_SaveAsSetForSimulator->setEnabled(hasData);
369 void CDbOwnModelSetComponent::setSaveFileName(
const CSimulatorInfo &simulator)
373 ui->tvp_OwnModelSet->setSaveFileName(name);
376 void CDbOwnModelSetComponent::updateViewToCurrentModels()
379 ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
382 void CDbOwnModelSetComponent::createNewSet()
401 mc->setOwnModelsSimulator(simulator);
402 if (!m_modelSetFormDialog)
404 m_modelSetFormDialog.reset(
new CDbOwnModelSetFormDialog(
this));
408 if (mc->getOwnModelsCount() > 0)
410 m_modelSetFormDialog->setModal(
true);
411 m_modelSetFormDialog->reloadData();
415 this->
setModelSet(m_modelSetFormDialog->getModelSet(), m_modelSetFormDialog->getSimulatorInfo());
421 mc->showOverlayMessage(m);
425 void CDbOwnModelSetComponent::firstSet()
427 if (!m_firstModelSetDialog) { m_firstModelSetDialog.reset(
new CFirstModelSetDialog(
this)); }
428 m_firstModelSetDialog->show();
431 void CDbOwnModelSetComponent::copyFromAnotherSwift()
433 if (!m_copyFromAnotherSwiftDialog)
435 m_copyFromAnotherSwiftDialog.reset(
new CCopyModelsFromOtherSwiftVersionsDialog(
this));
437 m_copyFromAnotherSwiftDialog->show();
442 if (m_simulator == simulator) {
return; }
446 m_simulator = simulator;
447 ui->comp_SimulatorSelector->setValue(simulator);
448 ui->tvp_OwnModelSet->setCorrespondingSimulator(simulator,
450 ui->le_Simulator->setText(simulator.
toQString(
true));
452 this->updateViewToCurrentModels();
457 ui->comp_SimulatorSelector->setMode(mode);
467 if (!myself) {
return; }
472 void CDbOwnModelSetComponent::showModelStatistics()
476 m_modelStatisticsDialog->analyzeModels(set);
477 m_modelStatisticsDialog->show();
480 void CDbOwnModelSetComponent::updateDistributorOrder(
const CSimulatorInfo &simulator)
483 if (modelSet.
isEmpty()) {
return; }
486 if (distributors.
isEmpty()) {
return; }
492 if (simulator == currentSimulator) { ui->tvp_OwnModelSet->updateContainerAsync(modelSet); }
497 void CDbOwnModelSetComponent::CLoadModelSetMenu::customMenu(
CMenuActions &menuActions)
504 auto *ownModelSetComp = qobject_cast<CDbOwnModelSetComponent *>(this->
parent());
505 Q_ASSERT_X(ownModelSetComp, Q_FUNC_INFO,
"Cannot access parent");
506 if (m_setActions.isEmpty())
510 auto *a =
new QAction(CIcons::appModels16(),
"FSX models",
this);
513 ownModelSetComp->setSimulator(
CSimulatorInfo(CSimulatorInfo::FSX));
515 m_setActions.append(a);
517 a =
new QAction(CIcons::appModels16(),
"New set FSX models",
this);
522 m_setNewActions.append(a);
526 auto *a =
new QAction(CIcons::appModels16(),
"P3D models",
this);
529 ownModelSetComp->setSimulator(
CSimulatorInfo(CSimulatorInfo::P3D));
531 m_setActions.append(a);
533 a =
new QAction(CIcons::appModels16(),
"New set P3D models",
this);
538 m_setNewActions.append(a);
542 auto *a =
new QAction(CIcons::appModels16(),
"FS9 models",
this);
545 ownModelSetComp->setSimulator(
CSimulatorInfo(CSimulatorInfo::FS9));
547 m_setActions.append(a);
549 a =
new QAction(CIcons::appModels16(),
"New set FS9 models",
this);
554 m_setNewActions.append(a);
558 auto *a =
new QAction(CIcons::appModels16(),
"XPlane models",
this);
561 ownModelSetComp->setSimulator(
CSimulatorInfo(CSimulatorInfo::XPLANE));
563 m_setActions.append(a);
565 a =
new QAction(CIcons::appModels16(),
"New set XPlane models",
this);
570 m_setNewActions.append(a);
574 auto *a =
new QAction(CIcons::appModels16(),
"FG models",
this);
577 ownModelSetComp->setSimulator(
CSimulatorInfo(CSimulatorInfo::FG));
579 m_setActions.append(a);
581 a =
new QAction(CIcons::appModels16(),
"New set FG models",
this);
586 m_setNewActions.append(a);
590 auto *a =
new QAction(CIcons::appModels16(),
"MSFS models",
this);
593 ownModelSetComp->setSimulator(
CSimulatorInfo(CSimulatorInfo::MSFS));
595 m_setActions.append(a);
597 a =
new QAction(CIcons::appModels16(),
"New set MSFS models",
this);
602 m_setNewActions.append(a);
606 auto *a =
new QAction(CIcons::appModels16(),
"MSFS2024 models",
this);
609 ownModelSetComp->setSimulator(
CSimulatorInfo(CSimulatorInfo::MSFS2024));
611 m_setActions.append(a);
613 a =
new QAction(CIcons::appModels16(),
"New set MSFS2024 models",
this);
618 m_setNewActions.append(a);
621 auto *a =
new QAction(CIcons::appDistributors16(),
"Apply distributor preferences",
this);
624 m_setActions.append(a);
626 a =
new QAction(CIcons::delete16(),
"Reduce models (remove duplicates)",
this);
629 m_setActions.append(a);
631 a =
new QAction(CIcons::delete16(),
"Remove excluded models",
this);
634 m_setActions.append(a);
636 a =
new QAction(CIcons::delete16(),
"Remove non DB models",
this);
639 m_setActions.append(a);
642 menuActions.
addActions(m_setActions, CMenuAction::pathModelSet());
643 menuActions.
addActions(m_setNewActions, CMenuAction::pathModelSetNew());
645 this->nestedCustomMenu(menuActions);
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
bool isShuttingDown() const
Is application shutting down?
static QDialog * findParentDialog(QWidget *widget)
Find parent dialog if there is any, otherwise null.
Allows subcomponents to gain access to model component.
bool showMappingComponentOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Overlay messages.
bool showMappingComponentOverlayHtmlMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Overlay messages.
CDbMappingComponent * getMappingComponent() const
Get the mapping component.
virtual void setMappingComponent(CDbMappingComponent *component)
Set the corresponding component.
void tabIndexChanged(int index)
Tab index has been changed.
Handling of the own model set.
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.
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.
const T & getThreadLocal() const
Read the current value.
T get() const
Get a copy of the current value.
Class for emitting a log message.
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.
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.
CAircraftModelList matchesSimulator(const CSimulatorInfo &simulator) const
Find for given simulator.
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.
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.
QString getSimulatorDirectoryOrDefault(const CSimulatorInfo &simulator) const
Simulator directory or default model path per simulator.
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)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QObject * sender() const const
QString arg(Args &&... args) const const
QString number(double n, char format, int precision)