diff --git a/src/blackgui/blackgui.pro b/src/blackgui/blackgui.pro index 6aa2a6e2e..c5c367b3e 100644 --- a/src/blackgui/blackgui.pro +++ b/src/blackgui/blackgui.pro @@ -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 diff --git a/src/blackgui/components/data/lastselections.cpp b/src/blackgui/components/data/lastselections.cpp new file mode 100644 index 000000000..c67d6bf8b --- /dev/null +++ b/src/blackgui/components/data/lastselections.cpp @@ -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(); + 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(); return; } + ColumnIndex i = index.frontCasted(); + 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(); + 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 diff --git a/src/blackgui/components/data/lastselections.h b/src/blackgui/components/data/lastselections.h new file mode 100644 index 000000000..b0b3e80cb --- /dev/null +++ b/src/blackgui/components/data/lastselections.h @@ -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 + { + 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 + { + //! 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 + diff --git a/src/blackgui/components/registermetadatacomponents.cpp b/src/blackgui/components/registermetadatacomponents.cpp new file mode 100644 index 000000000..10e288e19 --- /dev/null +++ b/src/blackgui/components/registermetadatacomponents.cpp @@ -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 diff --git a/src/blackgui/components/registermetadatacomponents.h b/src/blackgui/components/registermetadatacomponents.h new file mode 100644 index 000000000..6bf898746 --- /dev/null +++ b/src/blackgui/components/registermetadatacomponents.h @@ -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 diff --git a/src/blackgui/guiapplication.cpp b/src/blackgui/guiapplication.cpp index e77c01889..5bb3f756f 100644 --- a/src/blackgui/guiapplication.cpp +++ b/src/blackgui/guiapplication.cpp @@ -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() diff --git a/src/blackgui/registermetadata.cpp b/src/blackgui/registermetadata.cpp new file mode 100644 index 000000000..fc0ac7f50 --- /dev/null +++ b/src/blackgui/registermetadata.cpp @@ -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(); + } +} diff --git a/src/blackgui/registermetadata.h b/src/blackgui/registermetadata.h new file mode 100644 index 000000000..72c54788b --- /dev/null +++ b/src/blackgui/registermetadata.h @@ -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