diff --git a/src/swiftdata/swiftdata.cpp b/src/swiftdata/swiftdata.cpp index c339076e2..368771f37 100644 --- a/src/swiftdata/swiftdata.cpp +++ b/src/swiftdata/swiftdata.cpp @@ -9,12 +9,12 @@ #include "swiftdata.h" #include "ui_swiftdata.h" -#include "blackgui/components/logcomponent.h" #include "blackgui/components/datamaininfoareacomponent.h" -#include "blackgui/components/datamappingcomponent.h" +#include "blackgui/components/datainfoareacomponent.h" +#include "blackgui/components/logcomponent.h" #include "blackgui/components/enableforruntime.h" #include "blackgui/stylesheetutility.h" -#include "blackcore/web_datareader.h" +#include "blackcore/webdataservices.h" #include "blackmisc/icon.h" #include "blackmisc/loghandler.h" #include "blackmisc/project.h" @@ -28,8 +28,10 @@ using namespace BlackGui; using namespace BlackGui::Components; CSwiftData::CSwiftData(QWidget *parent) : - QMainWindow(parent), CIdentifiable(this), ui(new Ui::CSwiftData), - m_webDataReader(new CWebDataReader(CWebDataReader::AllSwiftDbReaders)) + QMainWindow(parent), + CIdentifiable(this), + ui(new Ui::CSwiftData), + m_webDataReader(new CWebDataServices(CWebReaderFlags::AllSwiftDbReaders)) { ui->setupUi(this); this->init(); @@ -50,9 +52,21 @@ void CSwiftData::initStyleSheet() CSwiftData::~CSwiftData() { } +void CSwiftData::closeEvent(QCloseEvent *event) +{ + Q_UNUSED(event); + this->performGracefulShutdown(); + QApplication::exit(); +} + void CSwiftData::ps_appendLogMessage(const CStatusMessage &message) { - ui->comp_MainInfoArea->getLogComponent()->appendStatusMessageToList(message); + CLogComponent *logComponent = ui->comp_MainInfoArea->getLogComponent(); + Q_ASSERT_X(logComponent, Q_FUNC_INFO, "missing log component"); + logComponent->appendStatusMessageToList(message); + + // status bar + m_statusBar.displayStatusMessage(message); } void CSwiftData::ps_onStyleSheetsChanged() @@ -66,12 +80,16 @@ void CSwiftData::init() this->setWindowTitle(QString("swiftdata %1").arg(CProject::version())); this->setObjectName("CSwiftData"); this->initStyleSheet(); + this->initLogDisplay(); connect(&CStyleSheetUtility::instance(), &CStyleSheetUtility::styleSheetsChanged, this, &CSwiftData::ps_onStyleSheetsChanged); this->initReaders(); + this->initMenu(); } void CSwiftData::initLogDisplay() { + this->m_statusBar.initStatusBar(this->ui->sb_SwiftData); + CLogHandler::instance()->install(true); CLogHandler::instance()->enableConsoleOutput(false); // default disable auto logHandler = CLogHandler::instance()->handlerForPattern( @@ -83,9 +101,35 @@ void CSwiftData::initLogDisplay() void CSwiftData::initReaders() { - CDataMappingComponent *mc = this->ui->comp_MainInfoArea->getMappingComponent(); - Q_ASSERT_X(mc, Q_FUNC_INFO, "Missing mapping component"); Q_ASSERT_X(this->m_webDataReader, Q_FUNC_INFO, "Missing reader"); - mc->readersInitialized(this->m_webDataReader); - this->m_webDataReader->readAllInBackground(1000); // kick of readers + this->ui->comp_MainInfoArea->setProvider(this->m_webDataReader); + this->ui->comp_InfoBar->setProvider(this->m_webDataReader); + this->m_webDataReader->readAllInBackground(1000); // kick of readers a little delayed +} + +void CSwiftData::initMenu() +{ + // menu + this->initDynamicMenus(); + this->ui->menu_WindowMinimize->setIcon(this->style()->standardIcon(QStyle::SP_TitleBarMinButton)); + connect(this->ui->menu_TestInternals, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_FileExit, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_FileSettingsDirectory, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_FileResetSettings, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_FileReloadStyleSheets, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_WindowFont, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_WindowMinimize, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_WindowToggleOnTop, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_DebugMetaTypes, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_MappingMaxData, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); + connect(this->ui->menu_MappingMaxMapping, &QAction::triggered, this, &CSwiftData::ps_onMenuClicked); +} + +void CSwiftData::performGracefulShutdown() +{ + if (this->m_webDataReader) + { + m_webDataReader->gracefulShutdown(); + m_webDataReader = nullptr; + } } diff --git a/src/swiftdata/swiftdata.h b/src/swiftdata/swiftdata.h index 83b86cc1f..163b88e34 100644 --- a/src/swiftdata/swiftdata.h +++ b/src/swiftdata/swiftdata.h @@ -14,20 +14,20 @@ #include "blackcore/context_runtime.h" #include "blackgui/systemtraywindow.h" -#include "blackgui/components/enableforruntime.h" #include "blackgui/managedstatusbar.h" #include "blackmisc/statusmessage.h" #include "blackmisc/identifiable.h" #include namespace Ui { class CSwiftData; } -namespace BlackCore { class CWebDataReader; } +namespace BlackCore { class CWebDataServices; } -//! swift data entry control +/*! + * swift data entry control (aka mapping tool) + */ class CSwiftData : public QMainWindow, - public BlackMisc::CIdentifiable, - public BlackGui::Components::CEnableForRuntime + public BlackMisc::CIdentifiable { Q_OBJECT @@ -38,6 +38,10 @@ public: //! Destructor ~CSwiftData(); +protected: + //! \copydoc QMainWindow::closeEvent + virtual void closeEvent(QCloseEvent *event) override; + private slots: //! Append log message void ps_appendLogMessage(const BlackMisc::CStatusMessage &message); @@ -45,14 +49,21 @@ private slots: //! Style sheet has changed void ps_onStyleSheetsChanged(); + //! Menu clicked + void ps_onMenuClicked(); + private: void init(); void initLogDisplay(); void initStyleSheet(); void initReaders(); + void initMenu(); + void initDynamicMenus(); + void performGracefulShutdown(); + QScopedPointer ui; BlackGui::CManagedStatusBar m_statusBar; - BlackCore::CWebDataReader *m_webDataReader = nullptr; + BlackCore::CWebDataServices *m_webDataReader = nullptr; }; #endif // guard diff --git a/src/swiftdata/swiftdata.pro b/src/swiftdata/swiftdata.pro index 4b3f8bc56..a7a2b3a32 100644 --- a/src/swiftdata/swiftdata.pro +++ b/src/swiftdata/swiftdata.pro @@ -2,6 +2,7 @@ include ($$SourceRoot/config.pri) include ($$SourceRoot/build.pri) QT += core dbus network xml multimedia gui svg +CONFIG += console greaterThan(QT_MAJOR_VERSION, 4): QT += widgets diff --git a/src/swiftdata/swiftdata.ui b/src/swiftdata/swiftdata.ui index c306606f0..8e3fb1358 100644 --- a/src/swiftdata/swiftdata.ui +++ b/src/swiftdata/swiftdata.ui @@ -2,24 +2,22 @@ CSwiftData - - - 0 - 0 - 800 - 600 - - - 800 - 600 + 900 + 700 swiftdata + + + 0 + 0 + + 2 @@ -33,6 +31,16 @@ 2 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + @@ -44,13 +52,8 @@ 0 - - - - - - - + + @@ -60,24 +63,132 @@ 0 0 - 800 + 1024 21 - + File - + + + + + - + + + Window + + + + + + + Info areas + + + + + Mapping + + + + + + + Test + + + + Debug + + + + + + + + + + Help + + + + + + + + - + Exit + + + Settings directory + + + + + Reset settings + + + + + Reload style sheets + + + + + Font + + + + + Minimize + + + + + Internals + + + + + Max. mapping area + + + Ctrl+M, M + + + + + Max. data area + + + Ctrl+M, D + + + + + Toggle stay on top + + + + + Navigator + + + + + Debug metatypes (to console) + + @@ -87,6 +198,12 @@
blackgui/components/datamaininfoareacomponent.h
1 + + BlackGui::Components::CInfoBarWebReadersStatusComponent + QFrame +
blackgui/components/infobarwebreadersstatuscomponent.h
+ 1 +
diff --git a/src/swiftdata/swiftdata_menus.cpp b/src/swiftdata/swiftdata_menus.cpp new file mode 100644 index 000000000..1a6f02da5 --- /dev/null +++ b/src/swiftdata/swiftdata_menus.cpp @@ -0,0 +1,84 @@ +/* Copyright (C) 2013 + * 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 "swiftdata.h" +#include "ui_swiftdata.h" +#include "blackgui/components/dbmappingcomponent.h" +#include "blackgui/components/logcomponent.h" +#include "blackgui/stylesheetutility.h" +#include "blackmisc/statusmessagelist.h" +#include "blackmisc/logmessage.h" +#include +#include +#include +#include +#include + +using namespace BlackGui; +using namespace BlackGui::Components; +using namespace BlackMisc; + +/* + * Menu clicked + */ +void CSwiftData::ps_onMenuClicked() +{ + QObject *sender = QObject::sender(); + if (sender == this->ui->menu_FileReloadStyleSheets) + { + CStyleSheetUtility::instance().read(); + } + else if (sender == this->ui->menu_WindowFont) + { +// this->ps_setMainPageToInfoArea(); +// this->ui->comp_MainInfoArea->selectSettingsTab(BlackGui::Components::CSettingsComponent::SettingTabGui); + } + else if (sender == this->ui->menu_WindowMinimize) + { + this->showMinimized(); + } + else if (sender == this->ui->menu_FileExit) + { + CLogMessage(this).info("Closing"); + this->close(); // graceful shutdown in close event + } + else if (sender == this->ui->menu_FileSettingsDirectory) + { + QString path; + QDesktopServices::openUrl(QUrl("file:///" + path)); + } + else if (sender == this->ui->menu_FileResetSettings) + { + // !\todo reset settings + } + else if (sender == this->ui->menu_DebugMetaTypes) + { + QString metadata; + QTextStream stream(&metadata); + BlackMisc::displayAllUserMetatypesTypes(stream); + this->ui->comp_MainInfoArea->getLogComponent()->appendPlainTextToConsole(metadata); + } + else if (sender == this->ui->menu_MappingMaxData) + { + CDbMappingComponent *mappingComponent = this->ui->comp_MainInfoArea->getMappingComponent(); + mappingComponent->resizeForSelect(); + } + else if (sender == this->ui->menu_MappingMaxMapping) + { + CDbMappingComponent *mappingComponent = this->ui->comp_MainInfoArea->getMappingComponent(); + mappingComponent->resizeForMapping(); + } +} + +void CSwiftData::initDynamicMenus() +{ + Q_ASSERT(this->ui->menu_InfoAreas); + Q_ASSERT(this->ui->comp_MainInfoArea); + this->ui->menu_InfoAreas->addActions(this->ui->comp_MainInfoArea->getInfoAreaSelectActions(this->ui->menu_InfoAreas)); +}