some general cleanup

This commit is contained in:
Marc Zinnschlag 2014-03-06 13:51:21 +01:00
parent f04348fb8e
commit 0254a209f6
3 changed files with 27 additions and 30 deletions

View file

@ -2,7 +2,6 @@
#include "table.hpp" #include "table.hpp"
#include <QHeaderView> #include <QHeaderView>
#include <QAction> #include <QAction>
#include <QApplication> #include <QApplication>
#include <QMenu> #include <QMenu>
@ -10,6 +9,8 @@
#include <QString> #include <QString>
#include <QtCore/qnamespace.h> #include <QtCore/qnamespace.h>
#include "../../model/doc/document.hpp"
#include "../../model/world/data.hpp" #include "../../model/world/data.hpp"
#include "../../model/world/commands.hpp" #include "../../model/world/commands.hpp"
#include "../../model/world/idtableproxymodel.hpp" #include "../../model/world/idtableproxymodel.hpp"
@ -47,7 +48,7 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
CSMWorld::UniversalId id = mModel->view (row).first; CSMWorld::UniversalId id = mModel->view (row).first;
if (!mData.getCells().getRecord (id.getId()).isDeleted()) if (!mDocument.getData().getCells().getRecord (id.getId()).isDeleted())
menu.addAction (mViewAction); menu.addAction (mViewAction);
} }
} }
@ -175,11 +176,12 @@ std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const
return deletableIds; return deletableIds;
} }
CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, CSVWorld::Table::Table (const CSMWorld::UniversalId& id,
bool createAndDelete, bool sorting, const CSMDoc::Document& document) bool createAndDelete, bool sorting, CSMDoc::Document& document)
: mUndoStack (undoStack), mCreateAction (0), mCloneAction(0), mEditLock (false), mRecordStatusDisplay (0), mDocument(document), mData (data) : mCreateAction (0), mCloneAction(0), mEditLock (false), mRecordStatusDisplay (0),
mDocument (document)
{ {
mModel = &dynamic_cast<CSMWorld::IdTable&> (*data.getTableModel (id)); mModel = &dynamic_cast<CSMWorld::IdTable&> (*mDocument.getData().getTableModel (id));
mProxyModel = new CSMWorld::IdTableProxyModel (this); mProxyModel = new CSMWorld::IdTableProxyModel (this);
mProxyModel->setSourceModel (mModel); mProxyModel->setSourceModel (mModel);
@ -203,7 +205,7 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q
mModel->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt()); mModel->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate (display, CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate (display,
undoStack, this); mDocument.getUndoStack(), this);
mDelegates.push_back (delegate); mDelegates.push_back (delegate);
setItemDelegateForColumn (i, delegate); setItemDelegateForColumn (i, delegate);
@ -285,13 +287,13 @@ void CSVWorld::Table::revertRecord()
if (revertableIds.size()>0) if (revertableIds.size()>0)
{ {
if (revertableIds.size()>1) if (revertableIds.size()>1)
mUndoStack.beginMacro (tr ("Revert multiple records")); mDocument.getUndoStack().beginMacro (tr ("Revert multiple records"));
for (std::vector<std::string>::const_iterator iter (revertableIds.begin()); iter!=revertableIds.end(); ++iter) for (std::vector<std::string>::const_iterator iter (revertableIds.begin()); iter!=revertableIds.end(); ++iter)
mUndoStack.push (new CSMWorld::RevertCommand (*mModel, *iter)); mDocument.getUndoStack().push (new CSMWorld::RevertCommand (*mModel, *iter));
if (revertableIds.size()>1) if (revertableIds.size()>1)
mUndoStack.endMacro(); mDocument.getUndoStack().endMacro();
} }
} }
} }
@ -305,13 +307,13 @@ void CSVWorld::Table::deleteRecord()
if (deletableIds.size()>0) if (deletableIds.size()>0)
{ {
if (deletableIds.size()>1) if (deletableIds.size()>1)
mUndoStack.beginMacro (tr ("Delete multiple records")); mDocument.getUndoStack().beginMacro (tr ("Delete multiple records"));
for (std::vector<std::string>::const_iterator iter (deletableIds.begin()); iter!=deletableIds.end(); ++iter) for (std::vector<std::string>::const_iterator iter (deletableIds.begin()); iter!=deletableIds.end(); ++iter)
mUndoStack.push (new CSMWorld::DeleteCommand (*mModel, *iter)); mDocument.getUndoStack().push (new CSMWorld::DeleteCommand (*mModel, *iter));
if (deletableIds.size()>1) if (deletableIds.size()>1)
mUndoStack.endMacro(); mDocument.getUndoStack().endMacro();
} }
} }
} }
@ -364,7 +366,7 @@ void CSVWorld::Table::moveUpRecord()
for (int i=1; i<row2-row; ++i) for (int i=1; i<row2-row; ++i)
newOrder[i] = i; newOrder[i] = i;
mUndoStack.push (new CSMWorld::ReorderRowsCommand (*mModel, row, newOrder)); mDocument.getUndoStack().push (new CSMWorld::ReorderRowsCommand (*mModel, row, newOrder));
} }
} }
} }
@ -393,7 +395,7 @@ void CSVWorld::Table::moveDownRecord()
for (int i=1; i<row2-row; ++i) for (int i=1; i<row2-row; ++i)
newOrder[i] = i; newOrder[i] = i;
mUndoStack.push (new CSMWorld::ReorderRowsCommand (*mModel, row, newOrder)); mDocument.getUndoStack().push (new CSMWorld::ReorderRowsCommand (*mModel, row, newOrder));
} }
} }
} }
@ -551,7 +553,7 @@ void CSVWorld::Table::dropEvent(QDropEvent *event)
std::auto_ptr<CSMWorld::ModifyCommand> command (new CSMWorld::ModifyCommand std::auto_ptr<CSMWorld::ModifyCommand> command (new CSMWorld::ModifyCommand
(*mProxyModel, index, QVariant (QString::fromUtf8 (record.getId().c_str())))); (*mProxyModel, index, QVariant (QString::fromUtf8 (record.getId().c_str()))));
mUndoStack.push (command.release()); mDocument.getUndoStack().push (command.release());
} }
} //TODO handle drops from different document } //TODO handle drops from different document
} }

View file

@ -10,13 +10,14 @@
#include "../../model/filter/node.hpp" #include "../../model/filter/node.hpp"
#include "../../model/world/columnbase.hpp" #include "../../model/world/columnbase.hpp"
namespace CSMDoc {
class Document;
}
class QUndoStack; class QUndoStack;
class QAction; class QAction;
namespace CSMDoc
{
class Document;
}
namespace CSMWorld namespace CSMWorld
{ {
class Data; class Data;
@ -35,7 +36,6 @@ namespace CSVWorld
Q_OBJECT Q_OBJECT
std::vector<CommandDelegate *> mDelegates; std::vector<CommandDelegate *> mDelegates;
QUndoStack& mUndoStack;
QAction *mEditAction; QAction *mEditAction;
QAction *mCreateAction; QAction *mCreateAction;
QAction *mCloneAction; QAction *mCloneAction;
@ -48,11 +48,7 @@ namespace CSVWorld
CSMWorld::IdTable *mModel; CSMWorld::IdTable *mModel;
bool mEditLock; bool mEditLock;
int mRecordStatusDisplay; int mRecordStatusDisplay;
CSMWorld::Data& mData; CSMDoc::Document& mDocument;
/// \brief This variable is used exclusivly for checking if dropEvents came from the same document. Most likely you
/// should NOT use it for anything else.
const CSMDoc::Document& mDocument;
private: private:
@ -72,9 +68,8 @@ namespace CSVWorld
public: public:
Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete, Table (const CSMWorld::UniversalId& id, bool createAndDelete,
bool sorting, const CSMDoc::Document& document); bool sorting, CSMDoc::Document& document);
///< \param createAndDelete Allow creation and deletion of records. ///< \param createAndDelete Allow creation and deletion of records.
/// \param sorting Allow changing order of rows in the view via column headers. /// \param sorting Allow changing order of rows in the view via column headers.

View file

@ -24,7 +24,7 @@ CSVWorld::TableSubView::TableSubView (const CSMWorld::UniversalId& id, CSMDoc::D
new TableBottomBox (creatorFactory, document.getData(), document.getUndoStack(), id, this), 0); new TableBottomBox (creatorFactory, document.getData(), document.getUndoStack(), id, this), 0);
layout->insertWidget (0, mTable = layout->insertWidget (0, mTable =
new Table (id, document.getData(), document.getUndoStack(), mBottom->canCreateAndDelete(), sorting, document), 2); new Table (id, mBottom->canCreateAndDelete(), sorting, document), 2);
CSVFilter::FilterBox *filterBox = new CSVFilter::FilterBox (document.getData(), this); CSVFilter::FilterBox *filterBox = new CSVFilter::FilterBox (document.getData(), this);