mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #535, model view adjusted
* allows to drop entities * using shortcut to stash * updating selected rows only and return number of altered rows
This commit is contained in:
@@ -8,8 +8,15 @@
|
||||
*/
|
||||
|
||||
#include "aircraftmodelview.h"
|
||||
#include "blackmisc/aviation/aircrafticaocodelist.h"
|
||||
#include "blackmisc/aviation/airlineicaocodelist.h"
|
||||
#include "blackmisc/aviation/liverylist.h"
|
||||
#include "blackmisc/simulation//distributorlist.h"
|
||||
#include "blackgui/shortcut.h"
|
||||
#include "blackgui/guiutility.h"
|
||||
#include "blackgui/filters/aircraftmodelfilterdialog.h"
|
||||
#include <QHeaderView>
|
||||
#include <QShortcut>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
@@ -33,6 +40,9 @@ namespace BlackGui
|
||||
Q_ASSERT_X(mainWindow, Q_FUNC_INFO, "no main window found");
|
||||
this->setFilterDialog(new CAircraftModelFilterDialog(mainWindow));
|
||||
|
||||
// shortcut
|
||||
new QShortcut(CShortcut::keyStash(), this, SLOT(ps_stashShortcut()), nullptr, Qt::WidgetShortcut);
|
||||
|
||||
// default mode
|
||||
CAircraftModelListModel::AircraftModelMode mode = derivedModel()->getModelMode();
|
||||
this->setAircraftModelMode(mode);
|
||||
@@ -42,6 +52,7 @@ namespace BlackGui
|
||||
{
|
||||
this->m_withMenuDisplayAutomatically = false;
|
||||
this->setCustomMenu(nullptr, false); // delete everything
|
||||
derivedModel()->setAircraftModelMode(mode);
|
||||
switch (mode)
|
||||
{
|
||||
case CAircraftModelListModel::StashModel:
|
||||
@@ -81,23 +92,132 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftModelView::applyToSelected(const CLivery &livery)
|
||||
int CAircraftModelView::applyToSelected(const CLivery &livery)
|
||||
{
|
||||
if (!hasSelection()) { return; }
|
||||
if (!hasSelection()) { return 0; }
|
||||
int c = this->updateSelected(CVariant::from(livery), CAircraftModel::IndexLivery);
|
||||
// this->updateContainer(models);
|
||||
return c;
|
||||
}
|
||||
|
||||
void CAircraftModelView::applyToSelected(const CAircraftIcaoCode &icao)
|
||||
int CAircraftModelView::applyToSelected(const CAircraftIcaoCode &icao)
|
||||
{
|
||||
if (!hasSelection()) { return; }
|
||||
if (!hasSelection()) { return 0; }
|
||||
int c = this->updateSelected(CVariant::from(icao), CAircraftModel::IndexAircraftIcaoCode);
|
||||
return c;
|
||||
}
|
||||
|
||||
void CAircraftModelView::applyToSelected(const CDistributor &distributor)
|
||||
int CAircraftModelView::applyToSelected(const CDistributor &distributor)
|
||||
{
|
||||
if (!hasSelection()) { return; }
|
||||
if (!hasSelection()) { return 0; }
|
||||
int c = this->updateSelected(CVariant::from(distributor), CAircraftModel::IndexDistributor);
|
||||
return c;
|
||||
}
|
||||
|
||||
bool CAircraftModelView::hasModelsToStash() const
|
||||
{
|
||||
return m_allowStash && hasSelection();
|
||||
}
|
||||
|
||||
void CAircraftModelView::setImplementedMetaTypeIds()
|
||||
{
|
||||
this->setAcceptedMetaTypeIds(
|
||||
{
|
||||
qMetaTypeId<CAirlineIcaoCode>(), qMetaTypeId<CAirlineIcaoCodeList>(),
|
||||
qMetaTypeId<CAircraftIcaoCode>(), qMetaTypeId<CAircraftIcaoCodeList>(),
|
||||
qMetaTypeId<CLivery>(), qMetaTypeId<CLiveryList>(),
|
||||
qMetaTypeId<CDistributor>(), qMetaTypeId<CDistributorList>(),
|
||||
qMetaTypeId<CAircraftModel>(), qMetaTypeId<CAircraftModelList>(),
|
||||
});
|
||||
}
|
||||
|
||||
void CAircraftModelView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (!isDropAllowed()) { return; }
|
||||
if (!event) { return; }
|
||||
const QMimeData *mime = event->mimeData();
|
||||
if (!mime) { return; }
|
||||
|
||||
if (CGuiUtility::hasSwiftVariantMimeType(mime))
|
||||
{
|
||||
CVariant valueVariant(CGuiUtility::fromSwiftDragAndDropData(mime));
|
||||
if (valueVariant.isValid())
|
||||
{
|
||||
if (valueVariant.canConvert<CAircraftModel>())
|
||||
{
|
||||
CAircraftModel model = valueVariant.value<CAircraftModel>();
|
||||
if (!model.hasModelString()) { return; }
|
||||
const CAircraftModelList models({model});
|
||||
this->derivedModel()->replaceOrAddByModelString(models);
|
||||
return;
|
||||
}
|
||||
else if (valueVariant.canConvert<CAircraftModelList>())
|
||||
{
|
||||
CAircraftModelList models(valueVariant.value<CAircraftModelList>());
|
||||
if (models.isEmpty()) { return; }
|
||||
this->derivedModel()->replaceOrAddByModelString(models);
|
||||
return;
|
||||
}
|
||||
|
||||
// only for selected members
|
||||
if (!this->hasSelection()) { return; }
|
||||
if (valueVariant.canConvert<CAircraftIcaoCode>())
|
||||
{
|
||||
CAircraftIcaoCode icao = valueVariant.value<CAircraftIcaoCode>();
|
||||
if (icao.validate().hasErrorMessages()) { return; }
|
||||
this->applyToSelected(icao);
|
||||
}
|
||||
else if (valueVariant.canConvert<CAircraftIcaoCodeList>())
|
||||
{
|
||||
CAircraftIcaoCodeList icaos(valueVariant.value<CAircraftIcaoCodeList>());
|
||||
if (icaos.size() != 1) { return; }
|
||||
CAircraftIcaoCode icao = icaos.front();
|
||||
if (icao.validate().hasErrorMessages()) { return; }
|
||||
this->applyToSelected(icao);
|
||||
}
|
||||
else if (valueVariant.canConvert<CLivery>())
|
||||
{
|
||||
CLivery livery = valueVariant.value<CLivery>();
|
||||
if (livery.validate().hasErrorMessages()) { return; }
|
||||
this->applyToSelected(livery);
|
||||
}
|
||||
else if (valueVariant.canConvert<CLiveryList>())
|
||||
{
|
||||
CLiveryList liveries(valueVariant.value<CLiveryList>());
|
||||
if (liveries.size() != 1) { return; }
|
||||
CLivery livery = liveries.front();
|
||||
if (livery.validate().hasErrorMessages()) { return; }
|
||||
this->applyToSelected(livery);
|
||||
}
|
||||
else if (valueVariant.canConvert<CDistributor>())
|
||||
{
|
||||
CDistributor distributor = valueVariant.value<CDistributor>();
|
||||
if (distributor.validate().hasErrorMessages()) { return; }
|
||||
this->applyToSelected(distributor);
|
||||
}
|
||||
else if (valueVariant.canConvert<CDistributorList>())
|
||||
{
|
||||
CDistributorList distributors(valueVariant.value<CDistributorList>());
|
||||
if (distributors.size() != 1) { return; }
|
||||
CDistributor distributor = distributors.front();
|
||||
if (distributor.validate().hasErrorMessages()) { return; }
|
||||
this->applyToSelected(distributor);
|
||||
}
|
||||
else if (valueVariant.canConvert<CAirlineIcaoCode>())
|
||||
{
|
||||
CAirlineIcaoCode airline = valueVariant.value<CAirlineIcaoCode>();
|
||||
if (airline.validate().hasErrorMessages()) { return; }
|
||||
emit requestHandlingOfStashDrop(airline); // I need to convert to stanard livery, which I can`t do here
|
||||
}
|
||||
else if (valueVariant.canConvert<CAirlineIcaoCodeList>())
|
||||
{
|
||||
CAirlineIcaoCodeList airlines(valueVariant.value<CAirlineIcaoCodeList>());
|
||||
if (airlines.size() != 1) { return; }
|
||||
CAirlineIcaoCode airline = airlines.front();
|
||||
if (airline.validate().hasErrorMessages()) { return; }
|
||||
emit requestHandlingOfStashDrop(airline); // I need to convert to stanard livery, which I can`t do here
|
||||
}
|
||||
}
|
||||
} // valid mime?
|
||||
}
|
||||
|
||||
void CAircraftModelView::ps_toggleHighlightDbModels()
|
||||
@@ -112,6 +232,12 @@ namespace BlackGui
|
||||
derivedModel()->setHighlightModelsStrings(!h);
|
||||
}
|
||||
|
||||
void CAircraftModelView::ps_stashShortcut()
|
||||
{
|
||||
if (!m_allowStash) { return; }
|
||||
emit requestStash();
|
||||
}
|
||||
|
||||
void CAircraftModelView::CHighlightDbModelsMenu::customMenu(QMenu &menu) const
|
||||
{
|
||||
const CAircraftModelView *mv = qobject_cast<const CAircraftModelView *>(parent());
|
||||
@@ -131,6 +257,5 @@ namespace BlackGui
|
||||
a->setChecked(mv->derivedModel()->highlightGivenModelStrings());
|
||||
this->nestedCustomMenu(menu);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user