mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #587, allow to modify multiple properties at once
functions to update a property map
This commit is contained in:
@@ -204,6 +204,13 @@ namespace BlackGui
|
||||
this->ui->tvp_StashAircraftModels->applyToSelected(distributor);
|
||||
}
|
||||
|
||||
void CDbStashComponent::applyToSelected(const CPropertyIndexVariantMap &vm)
|
||||
{
|
||||
if (vm.isEmpty()) { return; }
|
||||
if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; }
|
||||
this->ui->tvp_StashAircraftModels->applyToSelected(vm);
|
||||
}
|
||||
|
||||
void CDbStashComponent::ps_onUnstashPressed()
|
||||
{
|
||||
this->ui->tvp_StashAircraftModels->removeSelectedRows();
|
||||
|
||||
@@ -82,18 +82,21 @@ namespace BlackGui
|
||||
//! The stashed models
|
||||
const BlackMisc::Simulation::CAircraftModelList &getStashedModels() const;
|
||||
|
||||
//! Apply object to select objects
|
||||
//! Apply livery to selected objects
|
||||
void applyToSelected(const BlackMisc::Aviation::CLivery &livery, bool acceptWarnings = true);
|
||||
|
||||
//! Apply object to select objects
|
||||
//! Apply airline ICAO code to selected objects
|
||||
void applyToSelected(const BlackMisc::Aviation::CAircraftIcaoCode &icao, bool acceptWarnings = true);
|
||||
|
||||
//! Apply object to select objects
|
||||
//! Apply aircraft ICAO code to selected objects
|
||||
void applyToSelected(const BlackMisc::Aviation::CAirlineIcaoCode &icao, bool acceptWarnings = true);
|
||||
|
||||
//! Apply object to select objects
|
||||
//! Apply distributor to selected objects
|
||||
void applyToSelected(const BlackMisc::Simulation::CDistributor &distributor, bool acceptWarnings = true);
|
||||
|
||||
//! Apply set of properties to selected objects
|
||||
void applyToSelected(const BlackMisc::CPropertyIndexVariantMap &vm);
|
||||
|
||||
//! Consolidate with other available data
|
||||
BlackMisc::Simulation::CAircraftModel consolidateModel(const BlackMisc::Simulation::CAircraftModel &model) const;
|
||||
|
||||
|
||||
@@ -91,6 +91,13 @@ namespace BlackGui
|
||||
return c;
|
||||
}
|
||||
|
||||
int CAircraftModelView::applyToSelected(const CPropertyIndexVariantMap &vm)
|
||||
{
|
||||
if (!hasSelection()) { return 0; }
|
||||
int c = this->updateSelected(vm);
|
||||
return c;
|
||||
}
|
||||
|
||||
bool CAircraftModelView::hasSelectedModelsToStash() const
|
||||
{
|
||||
return m_menus.testFlag(MenuCanStashModels) && hasSelection();
|
||||
|
||||
@@ -43,6 +43,9 @@ namespace BlackGui
|
||||
//! Apply to selected objects
|
||||
int applyToSelected(const BlackMisc::Simulation::CDistributor &distributor);
|
||||
|
||||
//! Apply to selected objects
|
||||
int applyToSelected(const BlackMisc::CPropertyIndexVariantMap &vm);
|
||||
|
||||
//! Has any models to stash and it is allowed to stash
|
||||
bool hasSelectedModelsToStash() const;
|
||||
|
||||
|
||||
@@ -731,21 +731,31 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
int CViewBase<ModelClass, ContainerType, ObjectType>::updateSelected(const CVariant &variant, const CPropertyIndex &index)
|
||||
int CViewBase<ModelClass, ContainerType, ObjectType>::updateSelected(const CPropertyIndexVariantMap &vm)
|
||||
{
|
||||
if (vm.isEmpty()) { return 0; }
|
||||
if (!hasSelection()) { return 0; }
|
||||
QModelIndexList indexes = this->selectedRows();
|
||||
int c = 0;
|
||||
int lastRow = -1;
|
||||
int firstRow = -1;
|
||||
|
||||
QModelIndexList indexes = this->selectedRows();
|
||||
int lastUpdatedRow = -1;
|
||||
int firstUpdatedRow = -1;
|
||||
const CPropertyIndexList pis(vm.indexes());
|
||||
|
||||
for (const QModelIndex &i : indexes)
|
||||
{
|
||||
if (i.row() == lastRow) { continue; }
|
||||
lastRow = i.row();
|
||||
if (firstRow < 0 || lastRow < firstRow) { firstRow = lastRow; }
|
||||
if (i.row() == lastUpdatedRow) { continue; }
|
||||
lastUpdatedRow = i.row();
|
||||
if (firstUpdatedRow < 0 || lastUpdatedRow < firstUpdatedRow) { firstUpdatedRow = lastUpdatedRow; }
|
||||
ObjectType obj(this->at(i));
|
||||
obj.setPropertyByIndex(variant, index);
|
||||
|
||||
// update all properties in map
|
||||
for (const CPropertyIndex &pi : pis)
|
||||
{
|
||||
obj.setPropertyByIndex(vm.value(pi), pi);
|
||||
}
|
||||
|
||||
// and update container
|
||||
if (this->derivedModel()->setInContainer(i, obj))
|
||||
{
|
||||
c++;
|
||||
@@ -754,11 +764,18 @@ namespace BlackGui
|
||||
|
||||
if (c > 0)
|
||||
{
|
||||
this->derivedModel()->sendDataChanged(firstRow, lastRow);
|
||||
this->derivedModel()->sendDataChanged(firstUpdatedRow, lastUpdatedRow);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
int CViewBase<ModelClass, ContainerType, ObjectType>::updateSelected(const CVariant &variant, const CPropertyIndex &index)
|
||||
{
|
||||
const CPropertyIndexVariantMap vm(index, variant);
|
||||
return this->updateSelected(vm);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType>
|
||||
ObjectType CViewBase<ModelClass, ContainerType, ObjectType>::selectedObject() const
|
||||
{
|
||||
|
||||
@@ -434,6 +434,9 @@ namespace BlackGui
|
||||
//! Update selected objects
|
||||
int updateSelected(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Update selected objects
|
||||
int updateSelected(const BlackMisc::CPropertyIndexVariantMap &vm);
|
||||
|
||||
//! Selected object (or default)
|
||||
ObjectType selectedObject() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user