mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
refs #619, cache for last selections in components
1st implementation for mapping component
This commit is contained in:
71
src/blackgui/components/data/lastselections.cpp
Normal file
71
src/blackgui/components/data/lastselections.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "lastselections.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
namespace Data
|
||||
{
|
||||
QString CDbMappingComponent::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s(this->m_simulator.toQString(i18n));
|
||||
return s;
|
||||
}
|
||||
|
||||
CVariant CDbMappingComponent::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexLastSimulator:
|
||||
return this->m_simulator.propertyByIndex(index.copyFrontRemoved());
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbMappingComponent::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CDbMappingComponent>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexLastSimulator:
|
||||
this->m_simulator.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int CDbMappingComponent::comparePropertyByIndex(const CDbMappingComponent &compareValue, const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return this->toQString().compare(compareValue.toQString()); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexLastSimulator:
|
||||
return this->m_simulator.comparePropertyByIndex(compareValue.getLastSimulatorSelection(), index.copyFrontRemoved());
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison");
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
84
src/blackgui/components/data/lastselections.h
Normal file
84
src/blackgui/components/data/lastselections.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_COMPONENTS_DATA_LASTSELECTIONS_H
|
||||
#define BLACKGUI_COMPONENTS_DATA_LASTSELECTIONS_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/datacache.h"
|
||||
#include "blackmisc/simulation/simulatorinfo.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
namespace Data
|
||||
{
|
||||
/*!
|
||||
* Store last selections/interactions with this component
|
||||
*/
|
||||
class BLACKGUI_EXPORT CDbMappingComponent : public BlackMisc::CValueObject<CDbMappingComponent>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexLastSimulator = BlackMisc::CPropertyIndex::GlobalIndexCCountry + 33
|
||||
};
|
||||
|
||||
//! Simulator last selected
|
||||
const BlackMisc::Simulation::CSimulatorInfo &getLastSimulatorSelection() const { return m_simulator; }
|
||||
|
||||
//! Simulator last selected
|
||||
void setLastSimulatorSelection(const BlackMisc::Simulation::CSimulatorInfo &simulator) { m_simulator = simulator; }
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! Compare by index
|
||||
int comparePropertyByIndex(const CDbMappingComponent &compareValue, const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CDbMappingComponent)
|
||||
BlackMisc::Simulation::CSimulatorInfo m_simulator; //!< Last simulator selection
|
||||
};
|
||||
|
||||
//! Trait for model cache
|
||||
struct DbMappingComponent : public BlackMisc::CDataTrait<CDbMappingComponent>
|
||||
{
|
||||
//! Default value
|
||||
static const CDbMappingComponent &defaultValue()
|
||||
{
|
||||
static const CDbMappingComponent ls;
|
||||
return ls;
|
||||
}
|
||||
|
||||
//! Key in data cache
|
||||
static const char *key() { return "dbmappingcomponent"; }
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackGui::Components::Data::CDbMappingComponent)
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackGui::Components::Data::CDbMappingComponent, (
|
||||
attr(o.m_simulator)
|
||||
))
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user