mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 19:05:31 +08:00
refs #619, cache for last selections in components
1st implementation for mapping component
This commit is contained in:
@@ -29,7 +29,9 @@ HEADERS += $$PWD/views/*.h
|
||||
SOURCES += $$PWD/views/*.cpp
|
||||
|
||||
HEADERS += $$PWD/components/*.h
|
||||
HEADERS += $$PWD/components/data/*.h
|
||||
SOURCES += $$PWD/components/*.cpp
|
||||
SOURCES += $$PWD/components/data/*.cpp
|
||||
FORMS += $$PWD/components/*.ui
|
||||
|
||||
HEADERS += $$PWD/filters/*.h
|
||||
|
||||
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
|
||||
|
||||
23
src/blackgui/components/registermetadatacomponents.cpp
Normal file
23
src/blackgui/components/registermetadatacomponents.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/* 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 "registermetadatacomponents.h"
|
||||
#include "blackgui/components/data/lastselections.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
void registerMetadata()
|
||||
{
|
||||
Data::CDbMappingComponent::registerMetadata();
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
26
src/blackgui/components/registermetadatacomponents.h
Normal file
26
src/blackgui/components/registermetadatacomponents.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/* 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
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
|
||||
#ifndef BLACKGUI_COMPONENTS_REGISTERMETADATASIMULATION_H
|
||||
#define BLACKGUI_COMPONENTS_REGISTERMETADATASIMULATION_H
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
//! Register metadata for components
|
||||
BLACKGUI_EXPORT void registerMetadata();
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "guiapplication.h"
|
||||
#include "guiutility.h"
|
||||
#include "stylesheetutility.h"
|
||||
#include "registermetadata.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include "blackmisc/verify.h"
|
||||
@@ -40,9 +41,13 @@ namespace BlackGui
|
||||
|
||||
CGuiApplication::CGuiApplication(const QString &applicationName, const QPixmap &icon) : CApplication(applicationName)
|
||||
{
|
||||
setWindowIcon(icon);
|
||||
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CGuiApplication::styleSheetsChanged);
|
||||
sGui = this;
|
||||
if (!sGui)
|
||||
{
|
||||
registerMetadata();
|
||||
setWindowIcon(icon);
|
||||
sGui = this;
|
||||
connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CGuiApplication::styleSheetsChanged);
|
||||
}
|
||||
}
|
||||
|
||||
CGuiApplication::~CGuiApplication()
|
||||
|
||||
19
src/blackgui/registermetadata.cpp
Normal file
19
src/blackgui/registermetadata.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
/* 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 "registermetadata.h"
|
||||
#include "components/registermetadatacomponents.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
void registerMetadata()
|
||||
{
|
||||
BlackGui::Components::registerMetadata();
|
||||
}
|
||||
}
|
||||
21
src/blackgui/registermetadata.h
Normal file
21
src/blackgui/registermetadata.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef BLACKGUI_REGISTERMETADATA_H
|
||||
#define BLACKGUI_REGISTERMETADATA_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
//! Register metadata for GUI
|
||||
BLACKGUI_EXPORT void registerMetadata();
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user