logic: Use ControllerProxy in Bookmarking UI classes instead of messaging
* changed ControllerProxy to template class * allow passing method pointers and arguments to ControllerProxy * replaced some messages with ControllerProxy calls * moved logic from BookmarkView into BookmarkController
This commit is contained in:
@@ -11,16 +11,12 @@
|
||||
#include "qt/window/QtBookmarkBrowser.h"
|
||||
#include "qt/view/QtMainView.h"
|
||||
#include "qt/window/QtMainWindow.h"
|
||||
|
||||
#include "utility/messaging/type/MessageDeleteBookmarkForActiveTokens.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarks.h"
|
||||
#include "utility/messaging/type/MessageDisplayBookmarkCreator.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "utility/ResourcePaths.h"
|
||||
|
||||
QtBookmarkView::QtBookmarkView(ViewLayout* viewLayout)
|
||||
: BookmarkView(viewLayout)
|
||||
, m_controllerProxy(this)
|
||||
, m_bookmarkBrowser(nullptr)
|
||||
, m_createButtonState(BookmarkView::CreateButtonState::CANNOT_CREATE)
|
||||
{
|
||||
@@ -116,6 +112,85 @@ void QtBookmarkView::setCreateButtonState(const CreateButtonState& state)
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarkCreator(
|
||||
const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories, Id nodeId
|
||||
){
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
QtBookmarkCreator* bookmarkCreator = new QtBookmarkCreator(
|
||||
&m_controllerProxy,
|
||||
dynamic_cast<QtMainView*>(dynamic_cast<View*>(getViewLayout())->getViewLayout())->getMainWindow()
|
||||
);
|
||||
bookmarkCreator->setupBookmarkCreator();
|
||||
|
||||
std::string displayName = "";
|
||||
|
||||
for (unsigned int i = 0; i < names.size(); i++)
|
||||
{
|
||||
displayName += names[i];
|
||||
|
||||
if (i < names.size() - 1)
|
||||
{
|
||||
displayName += "; ";
|
||||
}
|
||||
}
|
||||
|
||||
bookmarkCreator->setDisplayName(displayName);
|
||||
bookmarkCreator->setBookmarkCategories(categories);
|
||||
bookmarkCreator->setNodeId(nodeId);
|
||||
|
||||
bookmarkCreator->show();
|
||||
bookmarkCreator->raise();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarkEditor(
|
||||
std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories
|
||||
){
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
QtBookmarkCreator* bookmarkCreator = new QtBookmarkCreator(
|
||||
&m_controllerProxy,
|
||||
dynamic_cast<QtMainView*>(dynamic_cast<View*>(getViewLayout())->getViewLayout())->getMainWindow(),
|
||||
bookmark->getId()
|
||||
);
|
||||
|
||||
bookmarkCreator->setupBookmarkCreator();
|
||||
bookmarkCreator->setDisplayName(bookmark->getName());
|
||||
bookmarkCreator->setComment(bookmark->getComment());
|
||||
bookmarkCreator->setBookmarkCategories(categories);
|
||||
bookmarkCreator->setCurrentBookmarkCategory(bookmark->getCategory());
|
||||
|
||||
bookmarkCreator->show();
|
||||
bookmarkCreator->raise();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
if (m_bookmarkBrowser == nullptr)
|
||||
{
|
||||
m_bookmarkBrowser = new QtBookmarkBrowser(
|
||||
&m_controllerProxy,
|
||||
dynamic_cast<QtMainView*>(dynamic_cast<View*>(getViewLayout())->getViewLayout())->getMainWindow()
|
||||
);
|
||||
m_bookmarkBrowser->setupBookmarkBrowser();
|
||||
}
|
||||
|
||||
m_bookmarkBrowser->setBookmarks(bookmarks);
|
||||
m_bookmarkBrowser->show();
|
||||
m_bookmarkBrowser->raise();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::enableDisplayBookmarks(bool enable)
|
||||
{
|
||||
m_onQtThread(
|
||||
@@ -142,7 +217,7 @@ void QtBookmarkView::createBookmarkClicked()
|
||||
{
|
||||
if (m_createButtonState == BookmarkView::CreateButtonState::CAN_CREATE)
|
||||
{
|
||||
MessageDisplayBookmarkCreator().dispatch();
|
||||
m_controllerProxy.executeAsTaskWithArgs(&BookmarkController::showBookmarkCreator, 0);
|
||||
}
|
||||
else if (m_createButtonState == BookmarkView::CreateButtonState::ALREADY_CREATED)
|
||||
{
|
||||
@@ -158,89 +233,24 @@ void QtBookmarkView::createBookmarkClicked()
|
||||
|
||||
if (ret == 0) // QMessageBox::Yes
|
||||
{
|
||||
MessageDisplayBookmarkCreator().dispatch();
|
||||
m_controllerProxy.executeAsTaskWithArgs(&BookmarkController::showBookmarkCreator, 0);
|
||||
}
|
||||
else if (ret == 1)
|
||||
{
|
||||
MessageDeleteBookmarkForActiveTokens().dispatch();
|
||||
m_controllerProxy.executeAsTask(&BookmarkController::deleteBookmarkForActiveTokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QtBookmarkView::showBookmarksClicked()
|
||||
{
|
||||
MessageDisplayBookmarks().dispatch();
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
if (m_bookmarkBrowser == nullptr)
|
||||
{
|
||||
m_bookmarkBrowser = new QtBookmarkBrowser(dynamic_cast<QtMainView*>(dynamic_cast<View*>(getViewLayout())->getViewLayout())->getMainWindow());
|
||||
m_bookmarkBrowser->setupBookmarkBrowser();
|
||||
}
|
||||
|
||||
m_bookmarkBrowser->setBookmarks(bookmarks);
|
||||
m_bookmarkBrowser->show();
|
||||
m_bookmarkBrowser->raise();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories, Id nodeId)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
QtBookmarkCreator* bookmarkCreator = new QtBookmarkCreator(dynamic_cast<QtMainView*>(dynamic_cast<View*>(getViewLayout())->getViewLayout())->getMainWindow());
|
||||
bookmarkCreator->setupBookmarkCreator();
|
||||
|
||||
std::string displayName = "";
|
||||
|
||||
for (unsigned int i = 0; i < names.size(); i++)
|
||||
{
|
||||
displayName += names[i];
|
||||
|
||||
if (i < names.size() - 1)
|
||||
{
|
||||
displayName += "; ";
|
||||
}
|
||||
}
|
||||
|
||||
bookmarkCreator->setDisplayName(displayName);
|
||||
bookmarkCreator->setBookmarkCategories(categories);
|
||||
bookmarkCreator->setNodeId(nodeId);
|
||||
|
||||
bookmarkCreator->show();
|
||||
bookmarkCreator->raise();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void QtBookmarkView::displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories)
|
||||
{
|
||||
m_onQtThread(
|
||||
[=]()
|
||||
{
|
||||
QtBookmarkCreator* bookmarkCreator = new QtBookmarkCreator(dynamic_cast<QtMainView*>(dynamic_cast<View*>(getViewLayout())->getViewLayout())->getMainWindow(), true, bookmark->getId());
|
||||
bookmarkCreator->setupBookmarkCreator();
|
||||
bookmarkCreator->setDisplayName(bookmark->getName());
|
||||
bookmarkCreator->setComment(bookmark->getComment());
|
||||
bookmarkCreator->setBookmarkCategories(categories);
|
||||
bookmarkCreator->setCurrentBookmarkCategory(bookmark->getCategory());
|
||||
|
||||
bookmarkCreator->show();
|
||||
bookmarkCreator->raise();
|
||||
}
|
||||
);
|
||||
m_controllerProxy.executeAsTask(&BookmarkController::displayBookmarks);
|
||||
}
|
||||
|
||||
void QtBookmarkView::setStyleSheet()
|
||||
{
|
||||
m_widget->setStyleSheet(utility::getStyleSheet(ResourcePaths::getGuiPath().concat(FilePath("bookmark_view/bookmark_view.css"))).c_str());
|
||||
m_widget->setStyleSheet(utility::getStyleSheet(
|
||||
ResourcePaths::getGuiPath().concat(FilePath("bookmark_view/bookmark_view.css"))).c_str());
|
||||
}
|
||||
|
||||
void QtBookmarkView::refreshStyle()
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef QT_BOOKMARK_VIEW_H
|
||||
#define QT_BOOKMARK_VIEW_H
|
||||
|
||||
#include "component/controller/BookmarkController.h"
|
||||
#include "component/controller/helper/ControllerProxy.h"
|
||||
#include "component/view/BookmarkView.h"
|
||||
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
@@ -25,6 +27,13 @@ public:
|
||||
virtual void refreshView();
|
||||
|
||||
virtual void setCreateButtonState(const CreateButtonState& state);
|
||||
|
||||
virtual void displayBookmarkCreator(
|
||||
const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories, Id nodeId);
|
||||
virtual void displayBookmarkEditor(
|
||||
std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories);
|
||||
|
||||
virtual void displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks);
|
||||
virtual void enableDisplayBookmarks(bool enable);
|
||||
|
||||
virtual bool bookmarkBrowserIsVisible() const;
|
||||
@@ -34,13 +43,10 @@ private slots:
|
||||
void showBookmarksClicked();
|
||||
|
||||
private:
|
||||
virtual void displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks);
|
||||
virtual void displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories, Id nodeId);
|
||||
virtual void displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories);
|
||||
|
||||
void setStyleSheet();
|
||||
void refreshStyle();
|
||||
|
||||
ControllerProxy<BookmarkController> m_controllerProxy;
|
||||
QtThreadedLambdaFunctor m_onQtThread;
|
||||
|
||||
QFrame* m_widget;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <QToolBar>
|
||||
|
||||
#include "component/controller/ScreenSearchController.h"
|
||||
#include "qt/element/QtScreenSearchBox.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "qt/view/QtMainView.h"
|
||||
@@ -89,10 +88,5 @@ void QtScreenSearchView::hide()
|
||||
m_bar->hide();
|
||||
m_widget->setMatchCount(0);
|
||||
|
||||
m_controllerProxy.executeAsTask<ScreenSearchController>(
|
||||
[](ScreenSearchController* controller)
|
||||
{
|
||||
controller->clearMatches();
|
||||
}
|
||||
);
|
||||
m_controllerProxy.executeAsTask(&ScreenSearchController::clearMatches);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define QT_SCREEN_SEARCH_VIEW_H
|
||||
|
||||
#include "component/controller/helper/ControllerProxy.h"
|
||||
#include "component/controller/ScreenSearchController.h"
|
||||
#include "component/view/ScreenSearchView.h"
|
||||
#include "qt/utility/QtThreadedFunctor.h"
|
||||
|
||||
@@ -34,7 +35,7 @@ public slots:
|
||||
void hide();
|
||||
|
||||
private:
|
||||
ControllerProxy m_controllerProxy;
|
||||
ControllerProxy<ScreenSearchController> m_controllerProxy;
|
||||
QtThreadedLambdaFunctor m_onQtThread;
|
||||
|
||||
QtScreenSearchBox* m_widget;
|
||||
|
||||
Reference in New Issue
Block a user