logic/ui: added CompositeView for combining Views to one DockWidget

Added CompositView, which implements both View and ViewLayout, for combining Views to one Widget. The layout can be set
to either horizontal or vertical. SearchView, RefreshView and UndoRedoView are combined to one DockWidget by the
ComponentManager now.

fortune cookie message = You'll get more secure and confident with your relationship with your co-workers.
This commit is contained in:
Eberhard Graether
2015-02-09 16:27:23 +01:00
parent 8bc11c9d9c
commit 5ecc4fb39a
43 changed files with 360 additions and 139 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ bool CodeView::CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSni
}
CodeView::CodeView(ViewLayout* viewLayout)
: View(viewLayout, Vec2i(100, 100))
: View(viewLayout)
{
}
+64
View File
@@ -0,0 +1,64 @@
#include "component/view/CompositeView.h"
CompositeView::CompositeView(ViewLayout* viewLayout, CompositeDirection direction)
: View(viewLayout)
, m_direction(direction)
{
}
CompositeView::~CompositeView()
{
}
CompositeView::CompositeDirection CompositeView::getDirection() const
{
return m_direction;
}
const std::vector<View*>& CompositeView::getViews() const
{
return m_views;
}
std::string CompositeView::getName() const
{
return "CompositeView";
}
void CompositeView::addView(View* view)
{
m_views.push_back(view);
addViewWidget(view);
}
void CompositeView::removeView(View* view)
{
std::vector<View*>::iterator it = std::find(m_views.begin(), m_views.end(), view);
if (it == m_views.end())
{
return;
}
m_views.erase(it);
}
void CompositeView::showView(View* view)
{
getViewLayout()->showView(view);
}
void CompositeView::hideView(View* view)
{
getViewLayout()->hideView(view);
}
void CompositeView::loadLayout()
{
getViewLayout()->loadLayout();
}
void CompositeView::saveLayout()
{
getViewLayout()->saveLayout();
}
+46
View File
@@ -0,0 +1,46 @@
#ifndef COMPOSITE_VIEW_H
#define COMPOSITE_VIEW_H
#include <vector>
#include "component/view/View.h"
#include "component/view/ViewLayout.h"
class CompositeView
: public View
, public ViewLayout
{
public:
enum CompositeDirection
{
DIRECTION_HORIZONTAL,
DIRECTION_VERTICAL
};
CompositeView(ViewLayout* viewLayout, CompositeDirection direction);
virtual ~CompositeView();
CompositeDirection getDirection() const;
const std::vector<View*>& getViews() const;
virtual void addViewWidget(View* view) = 0;
// View implementation
virtual std::string getName() const;
// ViewLayout implementation
virtual void addView(View* view);
virtual void removeView(View* view);
virtual void showView(View* view);
virtual void hideView(View* view);
virtual void loadLayout();
virtual void saveLayout();
private:
std::vector<View*> m_views;
CompositeDirection m_direction;
};
#endif // COMPOSITE_VIEW_H
+1 -1
View File
@@ -10,7 +10,7 @@ GraphView::Metrics::Metrics()
}
GraphView::GraphView(ViewLayout* viewLayout)
: View(viewLayout, Vec2i(100, 100))
: View(viewLayout)
{
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include "component/controller/RefreshController.h"
RefreshView::RefreshView(ViewLayout* viewLayout)
: View(viewLayout, Vec2i(100, 100))
: View(viewLayout)
{
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include "component/controller/SearchController.h"
SearchView::SearchView(ViewLayout* viewLayout)
: View(viewLayout, Vec2i(100, 100))
: View(viewLayout)
{
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include "component/controller/StatusBarController.h"
StatusBarView::StatusBarView(ViewLayout* viewLayout)
: View(viewLayout, Vec2i(100,100))
: View(viewLayout)
{
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include "component/controller/UndoRedoController.h"
UndoRedoView::UndoRedoView(ViewLayout* viewLayout)
: View(viewLayout, Vec2i(100,100))
: View(viewLayout)
{
}
+15 -19
View File
@@ -2,10 +2,9 @@
#include "component/view/ViewWidgetWrapper.h"
View::View(ViewLayout* viewLayout, const Vec2i& minSize)
View::View(ViewLayout* viewLayout)
: m_viewLayout(viewLayout)
, m_widgetWrapper(nullptr)
, m_minSize(minSize)
{
}
@@ -14,9 +13,16 @@ View::~View()
m_viewLayout->removeView(this);
}
void View::setWidgetWrapper(std::shared_ptr<ViewWidgetWrapper> widgetWrapper)
void View::init()
{
m_widgetWrapper = widgetWrapper;
createWidgetWrapper();
initView();
}
void View::addToLayout()
{
m_viewLayout->addView(this);
}
ViewWidgetWrapper* View::getWidgetWrapper() const
@@ -29,22 +35,12 @@ void View::setComponent(Component* component)
m_component = component;
}
int View::getMinWidth() const
{
return m_minSize.x;
}
int View::getMinHeight() const
{
return m_minSize.y;
}
Vec2i View::getMinSize() const
{
return m_minSize;
}
ViewLayout* View::getViewLayout() const
{
return m_viewLayout;
}
void View::setWidgetWrapper(std::shared_ptr<ViewWidgetWrapper> widgetWrapper)
{
m_widgetWrapper = widgetWrapper;
}
+13 -18
View File
@@ -14,12 +14,12 @@ class View
{
public:
template<typename T>
static std::shared_ptr<T> create(ViewLayout* viewLayout);
static std::shared_ptr<T> createInitAndAddToLayout(ViewLayout* viewLayout);
template<typename T>
static std::shared_ptr<T> createAndDontAddToLayout(ViewLayout* viewLayout);
static std::shared_ptr<T> createAndInit(ViewLayout* viewLayout);
View(ViewLayout* viewLayout, const Vec2i& minSize);
View(ViewLayout* viewLayout);
virtual ~View();
virtual std::string getName() const = 0;
@@ -28,48 +28,43 @@ public:
virtual void initView() = 0;
virtual void refreshView() = 0;
void init();
void addToLayout();
void setComponent(Component* component);
void setWidgetWrapper(std::shared_ptr<ViewWidgetWrapper> widgetWrapper);
ViewWidgetWrapper* getWidgetWrapper() const;
int getMinWidth() const;
int getMinHeight() const;
Vec2i getMinSize() const;
protected:
template <typename ControllerType>
ControllerType* getController();
ViewLayout* getViewLayout() const;
void setWidgetWrapper(std::shared_ptr<ViewWidgetWrapper> widgetWrapper);
private:
Component* m_component;
ViewLayout* const m_viewLayout;
std::shared_ptr<ViewWidgetWrapper> m_widgetWrapper;
Vec2i m_minSize;
};
template<typename T>
std::shared_ptr<T> View::create(ViewLayout* viewLayout)
std::shared_ptr<T> View::createInitAndAddToLayout(ViewLayout* viewLayout)
{
std::shared_ptr<T> ptr = std::make_shared<T>(viewLayout);
std::shared_ptr<T> ptr = View::createAndInit<T>(viewLayout);
ptr->createWidgetWrapper();
ptr->initView();
viewLayout->addView(ptr.get());
ptr->addToLayout();
return ptr;
}
template<typename T>
std::shared_ptr<T> View::createAndDontAddToLayout(ViewLayout* viewLayout)
std::shared_ptr<T> View::createAndInit(ViewLayout* viewLayout)
{
std::shared_ptr<T> ptr = std::make_shared<T>(viewLayout);
ptr->createWidgetWrapper();
ptr->initView();
ptr->init();
return ptr;
}
+5
View File
@@ -3,6 +3,8 @@
#include <memory>
#include "component/view/CompositeView.h"
class CodeView;
class GraphView;
class MainView;
@@ -19,6 +21,9 @@ public:
virtual ~ViewFactory();
virtual std::shared_ptr<MainView> createMainView() const = 0;
virtual std::shared_ptr<CompositeView> createCompositeView(
ViewLayout* viewLayout, CompositeView::CompositeDirection direction) const = 0;
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<RefreshView> createRefreshView(ViewLayout* viewLayout) const = 0;