swift
dbmappingcomponent.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_GUI_COMPONENTS_DBMAPPINGCOMPONENT_H
7 #define SWIFT_GUI_COMPONENTS_DBMAPPINGCOMPONENT_H
8 
9 #include <QList>
10 #include <QObject>
11 #include <QScopedPointer>
12 #include <QString>
13 #include <QStringList>
14 
18 #include "gui/menus/menudelegate.h"
20 #include "gui/swiftguiexport.h"
22 #include "misc/datacache.h"
23 #include "misc/digestsignal.h"
29 #include "misc/statusmessage.h"
30 #include "misc/statusmessagelist.h"
31 
32 class QAction;
33 class QModelIndex;
34 class QPoint;
35 
36 namespace swift::misc::aviation
37 {
38  class CAircraftIcaoCode;
39  class CLivery;
40 } // namespace swift::misc::aviation
41 namespace Ui
42 {
43  class CDbMappingComponent;
44 }
45 namespace swift::gui
46 {
47  namespace menus
48  {
49  class CMenuActions;
50  }
51  namespace views
52  {
53  class CAircraftModelView;
54  }
55 
56  namespace components
57  {
58  class CDbAutoStashingComponent;
59  class CDbAutoSimulatorStashingComponent;
60  class CDbModelMappingModifyDialog;
61 
66  public COverlayMessagesFrame,
69  {
70  Q_OBJECT
71 
72  public:
75  enum TabIndex
76  {
77  NoValidTab = -1,
78  TabOwnModelSet = 0,
79  TabOwnModels = 1,
80  TabWorkbench = 2,
81  TabStash = 3,
82  TabModelMatcher = 4,
83  TabVPilot = 5
84  };
85 
87  explicit CDbMappingComponent(QWidget *parent = nullptr);
88 
90  virtual ~CDbMappingComponent() override;
91 
93  void gracefulShutdown();
94 
96  bool withVPilot() const { return m_vPilotEnabled; }
97 
99  bool hasSelectedModelsToStash() const;
100 
102  swift::misc::simulation::CAircraftModelList getSelectedModelsToStash() const;
103 
105  TabIndex currentTabIndex() const;
106 
108  bool isStashTab() const;
109 
111  bool isWorkbenchTab() const;
112 
114  bool canAddToModelSetTab() const;
115 
117  views::CAircraftModelView *currentModelView() const;
118 
120  views::CAircraftModelView *modelView(TabIndex tab) const;
121 
124  swift::misc::simulation::CAircraftModel getEditorAircraftModel() const;
125 
126  // ---------------- stash -----------------
127 
131  const swift::misc::simulation::CAircraftModelList &getStashedModels() const;
132 
134  bool hasStashedModels() const;
135 
137  QStringList getStashedModelStrings() const;
139 
140  // ---------------- own models -----------------
141 
145  swift::misc::simulation::CAircraftModelList getOwnModels() const;
146 
149  getOwnCachedModels(const swift::misc::simulation::CSimulatorInfo &simulator) const;
150 
152  swift::misc::simulation::CAircraftModelList getOwnSelectedModels() const;
153 
155  swift::misc::simulation::CAircraftModel getOwnModelForModelString(const QString &modelString) const;
156 
158  swift::misc::simulation::CSimulatorInfo getOwnModelsSimulator() const;
159 
161  void setOwnModelsSimulator(const swift::misc::simulation::CSimulatorInfo &simulator);
162 
164  int getOwnModelsCount() const;
165 
167  QString getOwnModelsInfoString() const;
168 
170  QString getOwnModelsInfoStringFsFamily() const;
172 
173  // ---------------- own model set -----------------
174 
176  void setOwnModelSetSimulator(const swift::misc::simulation::CSimulatorInfo &simulator);
177 
179  swift::misc::simulation::CAircraftModelList getOwnModelSet() const;
180 
181  public slots:
184  bool replace = false);
185 
188 
191  const swift::misc::simulation::CSimulatorInfo &simulator);
192 
195  consolidateModel(const swift::misc::simulation::CAircraftModel &model) const;
196 
198  void replaceStashedModelsUnvalidated(const swift::misc::simulation::CAircraftModelList &models) const;
199 
201  swift::misc::CStatusMessageList validateCurrentModel(bool withNestedForms) const;
202 
204  void resizeForSelect();
205 
207  void resizeForMapping();
208 
210  void maxTableView();
211 
213  void stashSelectedModels();
214 
216  void modifyModelDialog();
217 
218  signals:
221 
224 
227 
229  void requestUpdatedData(swift::misc::network::CEntityFlags::Entity entities);
230 
232  void tabIndexChanged(int index);
233 
234  private slots:
236  void ps_addToOwnModelSet(); // still used with QShortcut
237 
238  private:
240  void onLoadVPilotDataFinished(bool success);
241 
243  void loadRemovedModels();
244 
246  void mergeWithVPilotModels();
247 
249  void onVPilotCacheChanged();
250 
252  void loadVPilotData();
253 
255  void requestVPilotDataUpdate();
256 
258  void mergeSelectedWithVPilotModels();
259 
261  void onVPilotDataChanged(int count, bool withFilter);
262 
264  void onWorkbenchDataChanged(int count, bool withFilter);
265 
267  void onTabIndexChanged(int index);
268 
270  void onStashedModelsChangedTriggerDigest();
271 
273  void onStashedModelsChangedDigest();
274 
276  void onStashedModelsDataChangedDigest(int count, bool withFilter);
277 
279  void onModelsSuccessfullyPublished(const swift::misc::simulation::CAircraftModelList &models,
280  bool directWrite);
281 
283  void handleStashDropRequest(const swift::misc::aviation::CAirlineIcaoCode &code) const;
284 
286  void onModelSetChangedDigest(int count, bool withFilter);
287 
289  void onOwnModelsChangedDigest(int count, bool withFilter);
290 
292  void onModelRowSelected(const QModelIndex &index);
293 
295  void onOwnModelsSimulatorChanged(const swift::misc::simulation::CSimulatorInfo simulator);
296 
298  void onUserChanged();
299 
301  void stashCurrentModel();
302 
304  void displayAutoStashingDialog();
305 
307  void displayAutoSimulatorStashingDialog();
308 
310  void removeDbModelsFromView();
311 
313  void showChangedAttributes();
314 
316  void toggleAutoFiltering();
317 
319  void applyFormLiveryData();
320 
322  void applyFormAircraftIcaoData();
323 
325  void applyFormDistributorData();
326 
328  void onCustomContextMenu(const QPoint &point);
329 
330  private:
331  QScopedPointer<Ui::CDbMappingComponent> ui;
332  QScopedPointer<CDbAutoStashingComponent> m_autoStashDialog;
333  QScopedPointer<CDbAutoSimulatorStashingComponent> m_autoSimulatorDialog;
334  QScopedPointer<CDbModelMappingModifyDialog> m_modelModifyDialog;
336  swift::misc::CDigestSignal m_dsStashedModelsChanged { this,
337  &CDbMappingComponent::onStashedModelsChangedDigest,
338  std::chrono::milliseconds(750), 25 };
340  this, &CDbMappingComponent::onUserChanged
341  };
342  const bool vPilotSupport = true;
343  bool m_vPilot1stInit = true;
344  bool m_vPilotEnabled = false;
345  bool m_vPilotFormatted = false;
346  bool m_autoFilterInDbViews = false;
347 
349  void initVPilotLoading();
350 
355  void formatVPilotView();
356 
358  swift::misc::simulation::CAircraftModel getModelFromView(const QModelIndex &index) const;
359 
361  QString currentTabText() const;
362 
364  void updateEditorsWhenApplicable();
365 
366  // -------------------- component specific menus --------------------------
367 
371  class CMappingVPilotMenu : public menus::IMenuDelegate
372  {
373  public:
375  CMappingVPilotMenu(CDbMappingComponent *mappingComponent) : menus::IMenuDelegate(mappingComponent) {}
376 
378  virtual void customMenu(menus::CMenuActions &menuActions) override;
379 
380  private:
382  CDbMappingComponent *mappingComponent() const;
383  QAction *m_menuAction = nullptr;
384  };
385 
394  class CStashToolsMenu : public menus::IMenuDelegate
395  {
396  public:
398  CStashToolsMenu(CDbMappingComponent *mappingComponent);
399 
401  virtual void customMenu(menus::CMenuActions &menuActions) override;
402 
403  private:
405  CDbMappingComponent *mappingComponent() const;
406 
408  void addStashViewSpecificMenus(menus::CMenuActions &menuActions);
409 
410  QAction *m_autoStashing = nullptr;
411  QAction *m_autoSimulatorStashing = nullptr;
412  QAction *m_stashFiltering = nullptr;
413  };
414 
417  class COwnModelSetMenu : public menus::IMenuDelegate
418  {
419  public:
421  COwnModelSetMenu(CDbMappingComponent *mappingComponent) : menus::IMenuDelegate(mappingComponent) {}
422 
424  virtual void customMenu(menus::CMenuActions &menuActions) override;
425 
426  private:
428  CDbMappingComponent *mappingComponent() const;
429 
430  QAction *m_menuAction = nullptr;
431  };
432 
435  class CRemovedModelsMenu : public menus::IMenuDelegate
436  {
437  public:
439  CRemovedModelsMenu(CDbMappingComponent *mappingComponent) : menus::IMenuDelegate(mappingComponent) {}
440 
442  virtual void customMenu(menus::CMenuActions &menuActions) override;
443 
444  private:
446  CDbMappingComponent *mappingComponent() const;
447 
448  QAction *m_menuAction = nullptr;
449  };
450 
453  class CApplyDbDataMenu : public menus::IMenuDelegate
454  {
455  public:
457  CApplyDbDataMenu(CDbMappingComponent *mappingComponent) : menus::IMenuDelegate(mappingComponent) {}
458 
460  virtual void customMenu(menus::CMenuActions &menuActions) override;
461 
462  private:
464  CDbMappingComponent *mappingComponent() const;
465 
466  QList<QAction *> m_menuActions;
467  };
468 
472  class CMergeWithVPilotMenu : public menus::IMenuDelegate
473  {
474  public:
476  CMergeWithVPilotMenu(CDbMappingComponent *mappingComponent);
477 
479  virtual void customMenu(menus::CMenuActions &menuActions) override;
480 
482  CDbMappingComponent *mappingComponent() const;
483 
484  private:
485  QList<QAction *> m_menuActions;
486  };
487  };
488  } // namespace components
489 } // namespace swift::gui
490 #endif // SWIFT_GUI_COMPONENTS_DBMAPPINGCOMPONENT_H
Helper class: If a component is residing in an dockable widget. This class provides access to its inf...
Hand over indication task to an embedded view.
Using this class provides a QFrame with the overlay functionality already integrated.
void tabIndexChanged(int index)
Tab index has been changed.
bool withVPilot() const
With vPilot rules?
void requestUpdatedData(swift::misc::network::CEntityFlags::Entity entities)
Request latest (incremental) data from backend.
void filterByAircraftIcao(const swift::misc::aviation::CAircraftIcaoCode &icao)
Request to filter by aircraft ICAO.
void filterByDistributor(const swift::misc::simulation::CDistributor &distributor)
Request to filter by distributor.
void filterByLivery(const swift::misc::aviation::CLivery &livery)
Request to filter by livery.
Interface to implement a custom menu.
Definition: menudelegate.h:21
Receive 1..n signals, collect them over time, and resend afer n milliseconds.
Definition: digestsignal.h:18
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
Value object for ICAO classification.
Value object for ICAO classification.
Value object encapsulating information about an airpot.
Definition: livery.h:29
Aircraft model (used by another pilot, my models on disk)
Definition: aircraftmodel.h:71
Value object encapsulating a list of aircraft models.
Value object encapsulating information of software distributor.
Definition: distributor.h:33
Simple hardcoded info about the corresponding simulator.
Definition: simulatorinfo.h:41
GUI related classes.
#define SWIFT_GUI_EXPORT
Export a class or function from the library.