mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +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 "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 "blackgui/filters/aircraftmodelfilterdialog.h"
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QShortcut>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -33,6 +40,9 @@ namespace BlackGui
|
|||||||
Q_ASSERT_X(mainWindow, Q_FUNC_INFO, "no main window found");
|
Q_ASSERT_X(mainWindow, Q_FUNC_INFO, "no main window found");
|
||||||
this->setFilterDialog(new CAircraftModelFilterDialog(mainWindow));
|
this->setFilterDialog(new CAircraftModelFilterDialog(mainWindow));
|
||||||
|
|
||||||
|
// shortcut
|
||||||
|
new QShortcut(CShortcut::keyStash(), this, SLOT(ps_stashShortcut()), nullptr, Qt::WidgetShortcut);
|
||||||
|
|
||||||
// default mode
|
// default mode
|
||||||
CAircraftModelListModel::AircraftModelMode mode = derivedModel()->getModelMode();
|
CAircraftModelListModel::AircraftModelMode mode = derivedModel()->getModelMode();
|
||||||
this->setAircraftModelMode(mode);
|
this->setAircraftModelMode(mode);
|
||||||
@@ -42,6 +52,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
this->m_withMenuDisplayAutomatically = false;
|
this->m_withMenuDisplayAutomatically = false;
|
||||||
this->setCustomMenu(nullptr, false); // delete everything
|
this->setCustomMenu(nullptr, false); // delete everything
|
||||||
|
derivedModel()->setAircraftModelMode(mode);
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case CAircraftModelListModel::StashModel:
|
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);
|
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);
|
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);
|
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()
|
void CAircraftModelView::ps_toggleHighlightDbModels()
|
||||||
@@ -112,6 +232,12 @@ namespace BlackGui
|
|||||||
derivedModel()->setHighlightModelsStrings(!h);
|
derivedModel()->setHighlightModelsStrings(!h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAircraftModelView::ps_stashShortcut()
|
||||||
|
{
|
||||||
|
if (!m_allowStash) { return; }
|
||||||
|
emit requestStash();
|
||||||
|
}
|
||||||
|
|
||||||
void CAircraftModelView::CHighlightDbModelsMenu::customMenu(QMenu &menu) const
|
void CAircraftModelView::CHighlightDbModelsMenu::customMenu(QMenu &menu) const
|
||||||
{
|
{
|
||||||
const CAircraftModelView *mv = qobject_cast<const CAircraftModelView *>(parent());
|
const CAircraftModelView *mv = qobject_cast<const CAircraftModelView *>(parent());
|
||||||
@@ -131,6 +257,5 @@ namespace BlackGui
|
|||||||
a->setChecked(mv->derivedModel()->highlightGivenModelStrings());
|
a->setChecked(mv->derivedModel()->highlightGivenModelStrings());
|
||||||
this->nestedCustomMenu(menu);
|
this->nestedCustomMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -35,17 +35,33 @@ namespace BlackGui
|
|||||||
void setAircraftModelMode(Models::CAircraftModelListModel::AircraftModelMode mode);
|
void setAircraftModelMode(Models::CAircraftModelListModel::AircraftModelMode mode);
|
||||||
|
|
||||||
//! Apply to selected objects
|
//! Apply to selected objects
|
||||||
void applyToSelected(const BlackMisc::Aviation::CLivery &livery);
|
int applyToSelected(const BlackMisc::Aviation::CLivery &livery);
|
||||||
|
|
||||||
//! Apply to selected objects
|
//! Apply to selected objects
|
||||||
void applyToSelected(const BlackMisc::Aviation::CAircraftIcaoCode &icao);
|
int applyToSelected(const BlackMisc::Aviation::CAircraftIcaoCode &icao);
|
||||||
|
|
||||||
//! Apply to selected objects
|
//! Apply to selected objects
|
||||||
void applyToSelected(const BlackMisc::Simulation::CDistributor &distributor);
|
int applyToSelected(const BlackMisc::Simulation::CDistributor &distributor);
|
||||||
|
|
||||||
|
//! Allow to stash
|
||||||
|
void setAllowStash(bool stash) { m_allowStash = stash; }
|
||||||
|
|
||||||
|
//! Has any models to stash amd is allowed to stash
|
||||||
|
bool hasModelsToStash() const;
|
||||||
|
|
||||||
|
//! Add the technically supported metatypes as allows
|
||||||
|
void setImplementedMetaTypeIds();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Request to load VPilot data
|
//! Request to stash if applicable
|
||||||
void requestVPilotRules();
|
void requestStash();
|
||||||
|
|
||||||
|
//! Request further handling of drops I cannot handle on my own
|
||||||
|
void requestHandlingOfStashDrop(const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcao);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! \copydoc QTableView::dropEvent
|
||||||
|
virtual void dropEvent(QDropEvent *event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Highlight DB models
|
//! Highlight DB models
|
||||||
@@ -54,7 +70,12 @@ namespace BlackGui
|
|||||||
//! Highlight stashed models
|
//! Highlight stashed models
|
||||||
void ps_toggleHighlightStashedModels();
|
void ps_toggleHighlightStashedModels();
|
||||||
|
|
||||||
|
//! Stash shortcut pressed
|
||||||
|
void ps_stashShortcut();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_allowStash = false; //!< allow to stash
|
||||||
|
|
||||||
//! Custom menu for the models which have been loaded
|
//! Custom menu for the models which have been loaded
|
||||||
class CHighlightDbModelsMenu : public BlackGui::IMenuDelegate
|
class CHighlightDbModelsMenu : public BlackGui::IMenuDelegate
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user