11 #include <QStringBuilder>
18 #include "gui/menus/menuaction.h"
37 using namespace swift::misc::simulation;
38 using namespace swift::misc::aviation;
41 using namespace swift::gui::menus;
53 stashShortcut->setContext(Qt::WidgetShortcut);
54 connect(stashShortcut, &QShortcut::activated,
this, &CAircraftModelView::requestedStash);
69 case CAircraftModelListModel::StashModel:
m_menus = MenuDefaultNoClear;
break;
70 case CAircraftModelListModel::Database:
m_menus = MenuDefaultDbViews;
break;
71 case CAircraftModelListModel::VPilotRuleModel:
m_menus = MenuDefaultNoClear | MenuStashing;
break;
72 case CAircraftModelListModel::OwnAircraftModelMappingTool:
73 m_menus = MenuDefaultNoClear | MenuStashing | MenuLoadAndSave;
75 case CAircraftModelListModel::OwnAircraftModelClient:
83 const int c = this->
updateSelected(CVariant::from(livery), CAircraftModel::IndexLivery);
90 const int c = this->
updateSelected(CVariant::from(icao), CAircraftModel::IndexAircraftIcaoCode);
97 const int c = this->
updateSelected(CVariant::from(distributor), CAircraftModel::IndexDistributor);
116 m_model->setAcceptedMetaTypeIds({
117 qMetaTypeId<CAirlineIcaoCode>(),
118 qMetaTypeId<CAirlineIcaoCodeList>(),
119 qMetaTypeId<CAircraftIcaoCode>(),
120 qMetaTypeId<CAircraftIcaoCodeList>(),
121 qMetaTypeId<CLivery>(),
122 qMetaTypeId<CLiveryList>(),
123 qMetaTypeId<CDistributor>(),
124 qMetaTypeId<CDistributorList>(),
125 qMetaTypeId<CAircraftModel>(),
126 qMetaTypeId<CAircraftModelList>(),
134 return qobject_cast<CAircraftModelFilterDialog *>(this->
getFilterWidget());
138 Qt::CaseSensitivity sensitivity)
140 if (modelStrings.isEmpty()) {
return 0; }
142 const int delta =
copy.removeModelsWithString(modelStrings, sensitivity);
148 Qt::CaseSensitivity sensitivity)
154 Qt::CaseSensitivity sensitivity)
156 if (models.
isEmpty()) {
return 0; }
158 int c =
copy.replaceOrAddModelsWithString(models, sensitivity);
159 if (c == 0) {
return 0; }
166 this->
derivedModel()->setHighlightModelStrings(highlightModels);
180 const int r = this->
rowOf(invaliddModels.
front());
181 const QModelIndex i =
m_model->index(r, 0);
188 this->
derivedModel()->setHighlightModels(highlightModels);
199 m_correspondingSimulator = simulator;
200 m_correspondingSimulatorDir = simDir;
207 Qt::DropAction action =
event->dropAction();
208 if (action == Qt::MoveAction)
214 if (!event) {
return; }
215 const QMimeData *mime =
event->mimeData();
216 if (!mime) {
return; }
228 this->
derivedModel()->replaceOrAddByModelString(models);
234 if (models.
isEmpty()) {
return; }
235 this->
derivedModel()->replaceOrAddByModelString(models);
250 if (icaos.
size() != 1) {
return; }
264 if (liveries.
size() != 1) {
return; }
278 if (distributors.
size() != 1) {
return; }
293 if (airlines.
size() != 1) {
return; }
309 menuActions.
addAction(CIcons::appAircraft16(),
"Model statistics", CMenuAction::pathModel(),
310 {
this, &CAircraftModelView::displayModelStatisticsDialog });
311 if (m_withValidationContextMenu)
314 if (!(parentDialog && (qobject_cast<CAircraftModelValidationDialog *>(parentDialog))))
316 menuActions.
addAction(CIcons::disk16(),
"Model validation (selected)", CMenuAction::pathModel(),
317 {
this, &CAircraftModelView::displayModelValidationDialog });
320 if (CAircraftModelList::hasInvalidModelFile())
322 menuActions.
addAction(CIcons::disk16(),
"Highlight invalid models (from file)",
323 CMenuAction::pathModel(),
329 bool addStashMenu =
false;
335 ma.
addAction(CIcons::appDbStash16(),
"Stash selected", CMenuAction::pathModelStash(),
336 {
this, &CAircraftModelView::requestedStash });
338 ma.
addAction(CIcons::appDbStash16(),
"Stashing clears selection (on/off)",
339 CMenuAction::pathModelStash(), {
this, &CAircraftModelView::stashingClearsSelection });
340 added->setCheckable(
true);
346 const bool tooMany = selected > 500;
347 const bool canStash = selected > 0 && !tooMany;
351 a->setChecked(m_stashingClearsSelection);
361 ma.
addAction(CIcons::appDbStash16(),
"Highlight stashed (on/off)", CMenuAction::pathModelStash(),
362 {
this, &CAircraftModelView::toggleHighlightStashedModels });
363 added->setCheckable(
true);
377 ma.
addAction(CIcons::delete16(),
"Temp.disable model", CMenuAction::pathModel(),
378 {
this, &CAircraftModelView::requestTempDisable });
393 if (models.
isEmpty()) {
return CStatusMessage(
this, CStatusMessage::SeverityDebug, u
"Empty models",
true); }
397 if (removed < 1) {
return {}; }
398 return CStatusMessage(
this, CStatusMessage::SeverityWarning, u
"Reduced by %1 model(s) to only use %2 models",
400 << removed << m_correspondingSimulator.
toQString(
true);
412 return CStatusMessage(
this, CStatusMessage::SeverityError, u
"Found entry not matching %1 in model data",
425 void CAircraftModelView::toggleHighlightStashedModels()
432 void CAircraftModelView::toggleHighlightInvalidModels()
438 void CAircraftModelView::stashingClearsSelection() { m_stashingClearsSelection = !m_stashingClearsSelection; }
440 void CAircraftModelView::requestedStash()
446 if (m_stashingClearsSelection) { this->clearSelection(); }
448 CStatusMessage(CStatusMessage::SeverityInfo, u
"Stashed " % models.getModelStringList(
true).join(
" ")));
451 void CAircraftModelView::requestTempDisable()
459 u
"Temp.disabled " % selectedModels.getModelStringList(
true).join(
" ")));
463 void CAircraftModelView::displayModelStatisticsDialog()
465 if (!m_statisticsDialog) { m_statisticsDialog =
new CAircraftModelStatisticsDialog(
this); }
467 m_statisticsDialog->exec();
470 void CAircraftModelView::displayModelValidationDialog()
472 if (!m_fileValidationDialog) { m_fileValidationDialog =
new CAircraftModelValidationDialog(
this); }
474 m_correspondingSimulatorDir);
476 m_fileValidationDialog->exec();
bool isShuttingDown() const
Is application shutting down?
bool displayInStatusBar(const swift::misc::CStatusMessage &message)
direct access to main application window
static QDialog * findParentDialog(QWidget *widget)
Find parent dialog if there is any, otherwise null.
static swift::misc::CVariant fromSwiftDragAndDropData(const QMimeData *mime)
From text dropped.
static bool hasSwiftVariantMimeType(const QMimeData *mime)
Mime data with swift type.
static const QKeySequence & keyStash()
For stashing models.
Form for a aircraft model filter.
Aircraft model list model.
AircraftModelMode
How to display.
void analyzeModels(const swift::misc::simulation::CAircraftModelList &models)
Set and analyze the models.
void setModels(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator, const QString &simulatorDir)
Models.
void triggerValidation(int delayMs=2500)
Trigger a validation.
virtual void customMenu(menus::CMenuActions &menuActions)
Method creating the menu.
bool highlightModels() const
Highlight models.
void setHighlightColor(const QBrush &brush)
The highlight color.
int removeModelsWithModelString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity=Qt::CaseInsensitive)
Remove models with model strings.
void setAircraftModelMode(models::CAircraftModelListModel::AircraftModelMode mode)
Set display mode.
swift::gui::filters::CAircraftModelFilterDialog * getFilterDialog() const
Filter dialog if any.
virtual void jsonLoadedAndModelUpdated(const swift::misc::simulation::CAircraftModelList &models)
In swift::gui::views::CViewBaseNonTemplate::loadJson the view has been updated because of loaded JSON...
virtual swift::misc::CStatusMessage modifyLoadedJsonData(swift::misc::simulation::CAircraftModelList &models) const
Modify JSON data loaded in swift::gui::views::CViewBaseNonTemplate::loadJson.
virtual swift::misc::CStatusMessage validateLoadedJsonData(const swift::misc::simulation::CAircraftModelList &models) const
Verify JSON data loaded in swift::gui::views::CViewBaseNonTemplate::loadJson.
void setHighlightModelsForInvalidModels()
Set the highlight models based on the saved file.
void requestTempDisableModelsForMatching(const swift::misc::simulation::CAircraftModelList &models)
Temp.disable model.
virtual void dropEvent(QDropEvent *event)
int replaceOrAddModelsWithString(const swift::misc::simulation::CAircraftModelList &models, Qt::CaseSensitivity sensitivity=Qt::CaseInsensitive)
Replace models with sme model string, otherwise add.
void setHighlight(bool highlight)
Highlight models.
void setHighlightModels(const swift::misc::simulation::CAircraftModelList &highlightModels)
Highlight models.
void setCorrespondingSimulator(const swift::misc::simulation::CSimulatorInfo &simulator, const QString &simDir)
Corresponding simulator.
void jsonModelsForSimulatorLoaded(const swift::misc::simulation::CSimulatorInfo &simulator)
Models for simulator loaded (JSON)
void toggledHighlightStashedModels()
Highlight stashed models has been toggled.
void requestHandlingOfStashDrop(const swift::misc::aviation::CAirlineIcaoCode &airlineIcao)
Request further handling of drops I cannot handle on my own.
void setHighlightModelStrings(const QStringList &highlightModels)
Highlight models.
bool hasSelectedModelsToStash() const
Has any models to stash and it is allowed to stash.
int applyToSelected(const swift::misc::aviation::CLivery &livery)
Apply to selected objects.
void addFilterDialog()
Add my own filter dialog.
void setAcceptedMetaTypeIds()
Add the technically supported metatypes allowed for drag and drop.
void requestStash(const swift::misc::simulation::CAircraftModelList &models)
Request to stash if applicable.
Base class for views with DB objects also orderable (based on swift::misc::IOrderableList )
virtual void customMenu(swift::gui::menus::CMenuActions &menuActions)
Method creating the menu.
int rowOf(const ObjectType &obj) const
The row of the given object.
void standardInit(ModelClass *model=nullptr)
Standard initialization.
virtual void clearHighlighting()
Clear any highlighted objects.
virtual bool isEmpty() const
Empty?
void updateContainerMaybeAsync(const ContainerType &container, bool sort=true, bool resize=true)
Based on size call sync / async update.
virtual ContainerType selectedObjects() const
Selected objects.
ModelClass * derivedModel()
Model.
ModelClass * m_model
corresponding model
void setSortIndicator()
Set the search indicator based on model.
virtual swift::misc::CStatusMessage validateLoadedJsonData(const ContainerType &data) const
Verify JSON data loaded in swift::gui::views::CViewBaseNonTemplate::loadJson.
virtual bool isDropAllowed() const
Drop allowed?
const ContainerType & container() const
Access to container.
virtual void copy()
Clipboard cut/copy/paste.
int updateSelected(const swift::misc::CVariant &variant, const swift::misc::CPropertyIndex &index)
Update selected objects.
virtual void dropEvent(QDropEvent *event)
menus::IMenuDelegate * setCustomMenu(menus::IMenuDelegate *menu, bool nestPreviousMenu=true)
Set custom menu if applicable.
Menu m_menus
Default menu settings.
int selectedRowCount() const
Number of selected rows.
QWidget * getFilterWidget() const
Filter widget if any.
void setSettingsDirectoryIndex(swift::misc::CDirectories::ColumnIndex directoryIndex)
Index of the directory we "remember".
QMap< MenuFlag, menus::CMenuActions > m_menuFlagActions
initialized actions for menu flag (enum)
menus::CMenuActions initMenuActions(MenuFlag menu)
Init menu actions.
void setFilterDialog(filters::CFilterDialog *filterDialog)
Filter dialog.
@ MenuCanStashModels
stash models
@ MenuHighlightStashed
highlight stashed models
@ MenuBackend
allow to request data from backend
@ MenuDisableModelsTemp
temp.
bool hasSelection() const
Selection (selected rows)
Specialized value object compliant map for variants, based on indexes.
size_type size() const
Returns number of elements in the sequence.
reference front()
Access the first element.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
bool hasErrorMessages() const
Error messages.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
T value() const
Return the value converted to the type T.
bool isValid() const
True if this variant is valid.
bool canConvert(int typeId) const
True if this variant can be converted to the type with the given metatype ID.
Value object for ICAO classification.
CStatusMessageList validate() const
Validate data.
Value object encapsulating a list of ICAO codes.
Value object for ICAO classification.
CStatusMessageList validate() const
Validate data.
Value object encapsulating a list of ICAO codes.
Value object encapsulating information about an airpot.
CStatusMessageList validate() const
Validate data.
Value object for a list of airports.
QString toQString(bool i18n=false) const
Cast as QString.
Aircraft model (used by another pilot, my models on disk)
bool hasModelString() const
Non empty model string?
Value object encapsulating a list of aircraft models.
QStringList getModelStringList(bool sort=true) const
Model strings.
CStatusMessage loadInvalidModels()
Save/load invalid models.
CSimulatorInfo simulatorsWithMaxEntries() const
Which simulator(s) have the most entries?
bool containsNotMatchingSimulator(const CSimulatorInfo &simulators) const
Contains any model not matching any of of passed simulators?
int removeIfNotMatchingSimulator(const CSimulatorInfo &needToMatch)
Remove if not matching simulator.
Value object encapsulating information of software distributor.
swift::misc::CStatusMessageList validate() const
Validate data.
Value object encapsulating a list of distributors.
Simple hardcoded info about the corresponding simulator.
bool isNoSimulator() const
No simulator?
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Filter to search data sets.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.