From f93af52486c8e84324bb41a5c90cf22ea6a66b85 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 27 Jul 2013 13:28:12 +0200 Subject: [PATCH] handling down a reference to Data and the undo stack to the creators --- apps/opencs/view/world/creator.cpp | 3 ++- apps/opencs/view/world/creator.hpp | 17 ++++++++++++----- apps/opencs/view/world/genericcreator.cpp | 2 +- apps/opencs/view/world/genericcreator.hpp | 2 +- apps/opencs/view/world/tablebottombox.cpp | 5 +++-- apps/opencs/view/world/tablebottombox.hpp | 9 ++++++++- apps/opencs/view/world/tablesubview.cpp | 4 ++-- 7 files changed, 29 insertions(+), 13 deletions(-) diff --git a/apps/opencs/view/world/creator.cpp b/apps/opencs/view/world/creator.cpp index 7d57c2ec73..c0378151ed 100644 --- a/apps/opencs/view/world/creator.cpp +++ b/apps/opencs/view/world/creator.cpp @@ -6,7 +6,8 @@ CSVWorld::Creator:: ~Creator() {} CSVWorld::CreatorFactoryBase::~CreatorFactoryBase() {} -CSVWorld::Creator *CSVWorld::NullCreatorFactory::makeCreator() const +CSVWorld::Creator *CSVWorld::NullCreatorFactory::makeCreator (CSMWorld::Data& data, + QUndoStack& undoStack) const { return 0; } \ No newline at end of file diff --git a/apps/opencs/view/world/creator.hpp b/apps/opencs/view/world/creator.hpp index f5485534c7..9f586bcba6 100644 --- a/apps/opencs/view/world/creator.hpp +++ b/apps/opencs/view/world/creator.hpp @@ -3,6 +3,13 @@ #include +class QUndoStack; + +namespace CSMWorld +{ + class Data; +} + namespace CSVWorld { /// \brief Record creator UI base class @@ -28,7 +35,7 @@ namespace CSVWorld virtual ~CreatorFactoryBase(); - virtual Creator *makeCreator() const = 0; + virtual Creator *makeCreator (CSMWorld::Data& data, QUndoStack& undoStack) const = 0; ///< The ownership of the returned Creator is transferred to the caller. /// /// \note The function can return a 0-pointer, which means no UI for creating/deleting @@ -40,7 +47,7 @@ namespace CSVWorld { public: - virtual Creator *makeCreator() const; + virtual Creator *makeCreator (CSMWorld::Data& data, QUndoStack& undoStack) const; ///< The ownership of the returned Creator is transferred to the caller. /// /// \note The function always returns 0. @@ -51,7 +58,7 @@ namespace CSVWorld { public: - virtual Creator *makeCreator() const; + virtual Creator *makeCreator (CSMWorld::Data& data, QUndoStack& undoStac) const; ///< The ownership of the returned Creator is transferred to the caller. /// /// \note The function can return a 0-pointer, which means no UI for creating/deleting @@ -59,9 +66,9 @@ namespace CSVWorld }; template - Creator *CreatorFactory::makeCreator() const + Creator *CreatorFactory::makeCreator (CSMWorld::Data& data, QUndoStack& undoStack) const { - return new CreatorT; + return new CreatorT (data, undoStack); } } diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index 6dbd847115..9a855fc4b9 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -5,7 +5,7 @@ #include #include -CSVWorld::GenericCreator::GenericCreator() +CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack) { QHBoxLayout *layout = new QHBoxLayout; diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index 7ab125dfc3..553315ae34 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -11,7 +11,7 @@ namespace CSVWorld public: - GenericCreator(); + GenericCreator (CSMWorld::Data& data, QUndoStack& undoStack); virtual void reset(); }; diff --git a/apps/opencs/view/world/tablebottombox.cpp b/apps/opencs/view/world/tablebottombox.cpp index d84e66390d..ae2b3d9208 100644 --- a/apps/opencs/view/world/tablebottombox.cpp +++ b/apps/opencs/view/world/tablebottombox.cpp @@ -39,7 +39,8 @@ void CSVWorld::TableBottomBox::updateStatus() } } -CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFactory, QWidget *parent) +CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFactory, + CSMWorld::Data& data, QUndoStack& undoStack, QWidget *parent) : QWidget (parent), mShowStatusBar (false), mCreating (false) { for (int i=0; i<4; ++i) @@ -59,7 +60,7 @@ CSVWorld::TableBottomBox::TableBottomBox (const CreatorFactoryBase& creatorFacto setLayout (mLayout); - mCreator = creatorFactory.makeCreator(); + mCreator = creatorFactory.makeCreator (data, undoStack); mLayout->addWidget (mCreator); diff --git a/apps/opencs/view/world/tablebottombox.hpp b/apps/opencs/view/world/tablebottombox.hpp index 8f2ceda112..50741167c1 100644 --- a/apps/opencs/view/world/tablebottombox.hpp +++ b/apps/opencs/view/world/tablebottombox.hpp @@ -6,6 +6,12 @@ class QLabel; class QStackedLayout; class QStatusBar; +class QUndoStack; + +namespace CSMWorld +{ + class Data; +} namespace CSVWorld { @@ -34,7 +40,8 @@ namespace CSVWorld public: - TableBottomBox (const CreatorFactoryBase& creatorFactory, QWidget *parent = 0); + TableBottomBox (const CreatorFactoryBase& creatorFactory, CSMWorld::Data& data, + QUndoStack& undoStack, QWidget *parent = 0); virtual ~TableBottomBox(); diff --git a/apps/opencs/view/world/tablesubview.cpp b/apps/opencs/view/world/tablesubview.cpp index 61a731289c..a76042842d 100644 --- a/apps/opencs/view/world/tablesubview.cpp +++ b/apps/opencs/view/world/tablesubview.cpp @@ -13,12 +13,12 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D const CreatorFactoryBase& creatorFactory) : SubView (id) { - QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins (QMargins (0, 0, 0, 0)); - layout->addWidget (mBottom = new TableBottomBox (creatorFactory, this), 0); + layout->addWidget (mBottom = + new TableBottomBox (creatorFactory, document.getData(), document.getUndoStack(), this), 0); layout->insertWidget (0, mTable = new Table (id, document.getData(), document.getUndoStack(), mBottom->canCreateAndDelete()), 2);