|
|
|
@ -2,7 +2,6 @@
|
|
|
|
|
#include "table.hpp"
|
|
|
|
|
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QMenu>
|
|
|
|
@ -10,6 +9,8 @@
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QtCore/qnamespace.h>
|
|
|
|
|
|
|
|
|
|
#include "../../model/doc/document.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../../model/world/data.hpp"
|
|
|
|
|
#include "../../model/world/commands.hpp"
|
|
|
|
|
#include "../../model/world/idtableproxymodel.hpp"
|
|
|
|
@ -35,8 +36,21 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event)
|
|
|
|
|
if (selectedRows.size()==1)
|
|
|
|
|
{
|
|
|
|
|
menu.addAction (mEditAction);
|
|
|
|
|
|
|
|
|
|
if (mCreateAction)
|
|
|
|
|
menu.addAction(mCloneAction);
|
|
|
|
|
|
|
|
|
|
if (mModel->getViewing()!=CSMWorld::IdTable::Viewing_None)
|
|
|
|
|
{
|
|
|
|
|
int row = selectedRows.begin()->row();
|
|
|
|
|
|
|
|
|
|
row = mProxyModel->mapToSource (mProxyModel->index (row, 0)).row();
|
|
|
|
|
|
|
|
|
|
CSMWorld::UniversalId id = mModel->view (row).first;
|
|
|
|
|
|
|
|
|
|
if (!mDocument.getData().getCells().getRecord (id.getId()).isDeleted())
|
|
|
|
|
menu.addAction (mViewAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mCreateAction)
|
|
|
|
@ -162,11 +176,12 @@ std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const
|
|
|
|
|
return deletableIds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack,
|
|
|
|
|
bool createAndDelete, bool sorting, const CSMDoc::Document& document)
|
|
|
|
|
: mUndoStack (undoStack), mCreateAction (0), mCloneAction(0), mEditLock (false), mRecordStatusDisplay (0), mDocument(document)
|
|
|
|
|
CSVWorld::Table::Table (const CSMWorld::UniversalId& id,
|
|
|
|
|
bool createAndDelete, bool sorting, CSMDoc::Document& document)
|
|
|
|
|
: 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->setSourceModel (mModel);
|
|
|
|
@ -190,7 +205,7 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q
|
|
|
|
|
mModel->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
|
|
|
|
|
|
|
|
|
|
CommandDelegate *delegate = CommandDelegateFactoryCollection::get().makeDelegate (display,
|
|
|
|
|
undoStack, this);
|
|
|
|
|
mDocument.getUndoStack(), this);
|
|
|
|
|
|
|
|
|
|
mDelegates.push_back (delegate);
|
|
|
|
|
setItemDelegateForColumn (i, delegate);
|
|
|
|
@ -230,6 +245,10 @@ CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, Q
|
|
|
|
|
connect (mMoveDownAction, SIGNAL (triggered()), this, SLOT (moveDownRecord()));
|
|
|
|
|
addAction (mMoveDownAction);
|
|
|
|
|
|
|
|
|
|
mViewAction = new QAction (tr ("View"), this);
|
|
|
|
|
connect (mViewAction, SIGNAL (triggered()), this, SLOT (viewRecord()));
|
|
|
|
|
addAction (mViewAction);
|
|
|
|
|
|
|
|
|
|
connect (mProxyModel, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
|
|
|
|
|
this, SLOT (tableSizeUpdate()));
|
|
|
|
|
|
|
|
|
@ -268,13 +287,13 @@ void CSVWorld::Table::revertRecord()
|
|
|
|
|
if (revertableIds.size()>0)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
mUndoStack.push (new CSMWorld::RevertCommand (*mModel, *iter));
|
|
|
|
|
mDocument.getUndoStack().push (new CSMWorld::RevertCommand (*mModel, *iter));
|
|
|
|
|
|
|
|
|
|
if (revertableIds.size()>1)
|
|
|
|
|
mUndoStack.endMacro();
|
|
|
|
|
mDocument.getUndoStack().endMacro();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -288,13 +307,13 @@ void CSVWorld::Table::deleteRecord()
|
|
|
|
|
if (deletableIds.size()>0)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
mUndoStack.push (new CSMWorld::DeleteCommand (*mModel, *iter));
|
|
|
|
|
mDocument.getUndoStack().push (new CSMWorld::DeleteCommand (*mModel, *iter));
|
|
|
|
|
|
|
|
|
|
if (deletableIds.size()>1)
|
|
|
|
|
mUndoStack.endMacro();
|
|
|
|
|
mDocument.getUndoStack().endMacro();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -306,7 +325,7 @@ void CSVWorld::Table::editRecord()
|
|
|
|
|
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
|
|
|
|
|
|
|
|
|
if (selectedRows.size()==1)
|
|
|
|
|
emit editRequest (selectedRows.begin()->row());
|
|
|
|
|
emit editRequest (getUniversalId (selectedRows.begin()->row()), "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -347,7 +366,7 @@ void CSVWorld::Table::moveUpRecord()
|
|
|
|
|
for (int i=1; i<row2-row; ++i)
|
|
|
|
|
newOrder[i] = i;
|
|
|
|
|
|
|
|
|
|
mUndoStack.push (new CSMWorld::ReorderRowsCommand (*mModel, row, newOrder));
|
|
|
|
|
mDocument.getUndoStack().push (new CSMWorld::ReorderRowsCommand (*mModel, row, newOrder));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -376,11 +395,28 @@ void CSVWorld::Table::moveDownRecord()
|
|
|
|
|
for (int i=1; i<row2-row; ++i)
|
|
|
|
|
newOrder[i] = i;
|
|
|
|
|
|
|
|
|
|
mUndoStack.push (new CSMWorld::ReorderRowsCommand (*mModel, row, newOrder));
|
|
|
|
|
mDocument.getUndoStack().push (new CSMWorld::ReorderRowsCommand (*mModel, row, newOrder));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::Table::viewRecord()
|
|
|
|
|
{
|
|
|
|
|
QModelIndexList selectedRows = selectionModel()->selectedRows();
|
|
|
|
|
|
|
|
|
|
if (selectedRows.size()==1)
|
|
|
|
|
{
|
|
|
|
|
int row =selectedRows.begin()->row();
|
|
|
|
|
|
|
|
|
|
row = mProxyModel->mapToSource (mProxyModel->index (row, 0)).row();
|
|
|
|
|
|
|
|
|
|
std::pair<CSMWorld::UniversalId, std::string> params = mModel->view (row);
|
|
|
|
|
|
|
|
|
|
if (params.first.getType()!=CSMWorld::UniversalId::Type_None)
|
|
|
|
|
emit editRequest (params.first, params.second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::Table::updateEditorSetting (const QString &settingName, const QString &settingValue)
|
|
|
|
|
{
|
|
|
|
|
int columns = mModel->columnCount();
|
|
|
|
@ -517,7 +553,7 @@ void CSVWorld::Table::dropEvent(QDropEvent *event)
|
|
|
|
|
std::auto_ptr<CSMWorld::ModifyCommand> command (new CSMWorld::ModifyCommand
|
|
|
|
|
(*mProxyModel, index, QVariant (QString::fromUtf8 (record.getId().c_str()))));
|
|
|
|
|
|
|
|
|
|
mUndoStack.push (command.release());
|
|
|
|
|
mDocument.getUndoStack().push (command.release());
|
|
|
|
|
}
|
|
|
|
|
} //TODO handle drops from different document
|
|
|
|
|
}
|
|
|
|
|