From 8e93bfa607ba7e38a507e7ffe346df0f5c9ecaec Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 3 Dec 2012 22:03:02 +0100 Subject: [PATCH] turned the global class into a general purpose table subview class --- apps/opencs/CMakeLists.txt | 4 ++-- apps/opencs/view/doc/view.cpp | 5 ++--- apps/opencs/view/world/globals.cpp | 15 --------------- apps/opencs/view/world/globals.hpp | 24 ------------------------ apps/opencs/view/world/subview.hpp | 23 +++++++++++++++++++++++ apps/opencs/view/world/table.cpp | 2 +- apps/opencs/view/world/tablesubview.cpp | 16 ++++++++++++++++ apps/opencs/view/world/tablesubview.hpp | 25 +++++++++++++++++++++++++ 8 files changed, 69 insertions(+), 45 deletions(-) delete mode 100644 apps/opencs/view/world/globals.cpp delete mode 100644 apps/opencs/view/world/globals.hpp create mode 100644 apps/opencs/view/world/tablesubview.cpp create mode 100644 apps/opencs/view/world/tablesubview.hpp diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 6d18a1811a..4ef4f93c7a 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -9,7 +9,7 @@ set (OPENCS_SRC view/doc/viewmanager.cpp view/doc/view.cpp view/doc/operations.cpp view/doc/operation.cpp - view/world/subview.cpp view/world/table.cpp view/world/globals.cpp + view/world/subview.cpp view/world/table.cpp view/world/tablesubview.cpp ) set (OPENCS_HDR @@ -23,7 +23,7 @@ set (OPENCS_HDR view/doc/viewmanager.hpp view/doc/view.hpp view/doc/operations.hpp view/doc/operation.hpp - view/world/subview.hpp view/world/table.hpp view/world/globals.hpp + view/world/subview.hpp view/world/table.hpp view/world/tablesubview.hpp ) set (OPENCS_US diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 1a8d568787..65ec103a21 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -10,8 +10,7 @@ #include "../../model/doc/document.hpp" -#include "../world/subview.hpp" -#include "../world/globals.hpp" +#include "../world/tablesubview.hpp" #include "viewmanager.hpp" #include "operations.hpp" @@ -122,7 +121,7 @@ CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int to setupUi(); mSubViewFactories.insert (std::make_pair (CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Globals), - new CSVWorld::SubViewFactory())); + new CSVWorld::SubViewFactoryWithCreateFlag (true))); } CSVDoc::View::~View() diff --git a/apps/opencs/view/world/globals.cpp b/apps/opencs/view/world/globals.cpp deleted file mode 100644 index 20cdb80f4d..0000000000 --- a/apps/opencs/view/world/globals.cpp +++ /dev/null @@ -1,15 +0,0 @@ - -#include "globals.hpp" - -#include "table.hpp" - -CSVWorld::Globals::Globals (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack) -: SubView (id) -{ - setWidget (mTable = new Table (id, data, undoStack, true)); -} - -void CSVWorld::Globals::setEditLock (bool locked) -{ - mTable->setEditLock (locked); -} \ No newline at end of file diff --git a/apps/opencs/view/world/globals.hpp b/apps/opencs/view/world/globals.hpp deleted file mode 100644 index 33cbce47f6..0000000000 --- a/apps/opencs/view/world/globals.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef CSV_WORLD_GLOBALS_H -#define CSV_WORLD_GLOBALS_H - -#include "subview.hpp" - -class QUndoStack; - -namespace CSVWorld -{ - class Table; - - class Globals : public SubView - { - Table *mTable; - - public: - - Globals (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack); - - virtual void setEditLock (bool locked); - }; -} - -#endif \ No newline at end of file diff --git a/apps/opencs/view/world/subview.hpp b/apps/opencs/view/world/subview.hpp index 543a9b2a1e..95448cb47b 100644 --- a/apps/opencs/view/world/subview.hpp +++ b/apps/opencs/view/world/subview.hpp @@ -51,6 +51,29 @@ namespace CSVWorld { return new SubViewT (id, data, undoStack); } + + template + struct SubViewFactoryWithCreateFlag : public SubViewFactoryBase + { + bool mCreateAndDelete; + + SubViewFactoryWithCreateFlag (bool createAndDelete); + + virtual SubView *makeSubView (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack); + }; + + template + SubViewFactoryWithCreateFlag::SubViewFactoryWithCreateFlag (bool createAndDelete) + : mCreateAndDelete (createAndDelete) + {} + + template + SubView *SubViewFactoryWithCreateFlag::makeSubView (const CSMWorld::UniversalId& id, + CSMWorld::Data& data, + QUndoStack& undoStack) + { + return new SubViewT (id, data, undoStack, mCreateAndDelete); + } } #endif \ No newline at end of file diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 862ebdc79d..4f20d9fd26 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -145,7 +145,7 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q if (createAndDelete) { - mCreateAction = new QAction (tr ("CreateRecord"), this); + mCreateAction = new QAction (tr ("Add Record"), this); connect (mCreateAction, SIGNAL (triggered()), this, SLOT (createRecord())); addAction (mCreateAction); } diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp new file mode 100644 index 0000000000..3bc555a2d0 --- /dev/null +++ b/apps/opencs/view/world/tablesubview.cpp @@ -0,0 +1,16 @@ + +#include "tablesubview.hpp" + +#include "table.hpp" + +CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, + bool createAndDelete) +: SubView (id) +{ + setWidget (mTable = new Table (id, data, undoStack, createAndDelete)); +} + +void CSVWorld::TableSubView::setEditLock (bool locked) +{ + mTable->setEditLock (locked); +} \ No newline at end of file diff --git a/apps/opencs/view/world/tablesubview.hpp b/apps/opencs/view/world/tablesubview.hpp new file mode 100644 index 0000000000..b45b3c2796 --- /dev/null +++ b/apps/opencs/view/world/tablesubview.hpp @@ -0,0 +1,25 @@ +#ifndef CSV_WORLD_TABLESUBVIEW_H +#define CSV_WORLD_TABLESUBVIEW_H + +#include "subview.hpp" + +class QUndoStack; + +namespace CSVWorld +{ + class Table; + + class TableSubView : public SubView + { + Table *mTable; + + public: + + TableSubView (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, + bool createAndDelete); + + virtual void setEditLock (bool locked); + }; +} + +#endif \ No newline at end of file