1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-19 16:39:41 +00:00

subview does not store row number anymore

This commit is contained in:
Marek Kochanowicz 2014-06-09 11:37:48 +02:00
parent 29231b8fc9
commit 6f5935edb3

View file

@ -379,14 +379,15 @@ void CSVWorld::EditWidget::remake(int row)
const QModelIndex& parent = mTable->index(row, i); const QModelIndex& parent = mTable->index(row, i);
if (parent.data().isValid() && mTable->hasChildren(parent)) if (parent.data().isValid() && mTable->hasChildren(parent))
{ {
/*
qDebug()<<row; qDebug()<<row;
qDebug()<<i; qDebug()<<i;
qDebug()<<"nested!"; qDebug()<<"nested!";
QTableView* table = new QTableView(this); QTableView* table = new QTableView(this);
table->setModel(mTable); table->setModel(mTable);
table->setRootIndex(mTable->index(row, i)); table->setRootIndex(mTable->index(row, i));
*/
} }
//TODO
} else } else
{ {
mDispatcher.makeDelegate (display); mDispatcher.makeDelegate (display);
@ -410,9 +411,7 @@ void CSVWorld::EditWidget::remake(int row)
unlockedLayout->addWidget (editor, unlocked, 1); unlockedLayout->addWidget (editor, unlocked, 1);
++unlocked; ++unlocked;
} }
} else { }
qDebug()<<"No edit widget";
}
} }
} }
} }
@ -441,7 +440,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
{ {
connect(mTable, SIGNAL(dataChanged (const QModelIndex&, const QModelIndex&)), this, SLOT(dataChanged(const QModelIndex&))); connect(mTable, SIGNAL(dataChanged (const QModelIndex&, const QModelIndex&)), this, SLOT(dataChanged(const QModelIndex&)));
mCurrentId(id.getId()); mCurrentId = id.getId();
QWidget *mainWidget = new QWidget(this); QWidget *mainWidget = new QWidget(this);
QHBoxLayout *buttonsLayout = new QHBoxLayout; QHBoxLayout *buttonsLayout = new QHBoxLayout;
@ -491,7 +490,7 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
mMainLayout = new QVBoxLayout(mainWidget); mMainLayout = new QVBoxLayout(mainWidget);
mEditWidget = new EditWidget(mainWidget, mCurrentId, mTable, mUndoStack, false); mEditWidget = new EditWidget(mainWidget, mTable->getModelIndex(mCurrentId, 0).row(), mTable, mUndoStack, false);
connect(mEditWidget, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)), connect(mEditWidget, SIGNAL(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)),
this, SLOT(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*))); this, SLOT(tableMimeDataDropped(QWidget*, const QModelIndex&, const CSMWorld::UniversalId&, const CSMDoc::Document*)));
@ -512,14 +511,14 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, CSM
deleteButton->setDisabled(true); deleteButton->setDisabled(true);
} }
dataChanged(getModelIndex(mCurrentId, 0)); dataChanged(mTable->getModelIndex(mCurrentId, 0));
mMainLayout->addLayout(buttonsLayout); mMainLayout->addLayout(buttonsLayout);
setWidget(mainWidget); setWidget(mainWidget);
} }
void CSVWorld::DialogueSubView::prevId() void CSVWorld::DialogueSubView::prevId()
{ {
int new Row = getModelIndex(mCurrentId, 0).row() - 1; int newRow = mTable->getModelIndex(mCurrentId, 0).row() - 1;
if (newRow < 0) if (newRow < 0)
{ {
@ -540,7 +539,7 @@ void CSVWorld::DialogueSubView::prevId()
mEditWidget->remake(newRow); mEditWidget->remake(newRow);
setUniversalId(CSMWorld::UniversalId (static_cast<CSMWorld::UniversalId::Type> (mTable->data (mTable->index (newRow, 2)).toInt()), setUniversalId(CSMWorld::UniversalId (static_cast<CSMWorld::UniversalId::Type> (mTable->data (mTable->index (newRow, 2)).toInt()),
mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData())); mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData()));
mRow = newRow; mCurrentId = std::string(mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData());
mEditWidget->setDisabled(mLocked); mEditWidget->setDisabled(mLocked);
return; return;
} }
@ -550,7 +549,7 @@ void CSVWorld::DialogueSubView::prevId()
void CSVWorld::DialogueSubView::nextId() void CSVWorld::DialogueSubView::nextId()
{ {
int newRow = mRow + 1; int newRow = mTable->getModelIndex(mCurrentId, 0).row() + 1;
if (newRow >= mTable->rowCount()) if (newRow >= mTable->rowCount())
{ {
@ -571,7 +570,7 @@ void CSVWorld::DialogueSubView::nextId()
{ {
mEditWidget->remake(newRow); mEditWidget->remake(newRow);
setUniversalId(CSMWorld::UniversalId (static_cast<CSMWorld::UniversalId::Type> (mTable->data (mTable->index (newRow, 2)).toInt()), setUniversalId(CSMWorld::UniversalId (static_cast<CSMWorld::UniversalId::Type> (mTable->data (mTable->index (newRow, 2)).toInt()),
mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData())); mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData()));
mCurrentId = std::string(mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData()); mCurrentId = std::string(mTable->data (mTable->index (newRow, 0)).toString().toUtf8().constData());
mEditWidget->setDisabled(mLocked); mEditWidget->setDisabled(mLocked);
return; return;
@ -583,8 +582,10 @@ void CSVWorld::DialogueSubView::nextId()
void CSVWorld::DialogueSubView::setEditLock (bool locked) void CSVWorld::DialogueSubView::setEditLock (bool locked)
{ {
mLocked = locked; mLocked = locked;
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (mRow, 1)).toInt()); QModelIndex index(mTable->getModelIndex(mCurrentId, 0));
if (state == CSMWorld::RecordBase::State_Deleted || state == CSMWorld::RecordBase::State_Erased)
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (index.row(), 1)).toInt());
if (state == CSMWorld::RecordBase::State_Deleted)
{ {
mEditWidget->setDisabled(true); mEditWidget->setDisabled(true);
} else } else
@ -595,10 +596,12 @@ void CSVWorld::DialogueSubView::setEditLock (bool locked)
void CSVWorld::DialogueSubView::dataChanged(const QModelIndex & index) void CSVWorld::DialogueSubView::dataChanged(const QModelIndex & index)
{ {
if (index.row() == mRow) QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
if (!currentIndex.isValid() && index.row() == currentIndex.row())
{ {
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (mRow, 1)).toInt()); CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (currentIndex.row(), 1)).toInt());
if (state == CSMWorld::RecordBase::State_Deleted || state == CSMWorld::RecordBase::State_Erased) if (state == CSMWorld::RecordBase::State_Deleted)
{ {
mEditWidget->setDisabled(true); mEditWidget->setDisabled(true);
} else } else
@ -621,15 +624,24 @@ void CSVWorld::DialogueSubView::tableMimeDataDropped(QWidget* editor,
void CSVWorld::DialogueSubView::revertRecord() void CSVWorld::DialogueSubView::revertRecord()
{ {
int rows = mTable->rowCount(); const int rows = mTable->rowCount();
if (!mLocked && mTable->columnCount() > 0 && mRow < mTable->rowCount() ) QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
if (!currentIndex.isValid())
{
return;
}
const int currentRow = currentIndex.row();
if (!mLocked && mTable->columnCount() > 0 && currentRow < mTable->rowCount() )
{ {
CSMWorld::RecordBase::State state = CSMWorld::RecordBase::State state =
static_cast<CSMWorld::RecordBase::State> (mTable->data (mTable->index (mRow, 1)).toInt()); static_cast<CSMWorld::RecordBase::State> (mTable->data (mTable->index (currentRow, 1)).toInt());
if (state!=CSMWorld::RecordBase::State_BaseOnly) if (state!=CSMWorld::RecordBase::State_BaseOnly)
{ {
mUndoStack.push(new CSMWorld::RevertCommand(*mTable, mTable->data(mTable->index (mRow, 0)).toString().toUtf8().constData())); mUndoStack.push(new CSMWorld::RevertCommand(*mTable, mCurrentId));
} }
if (rows != mTable->rowCount()) if (rows != mTable->rowCount())
{ {
@ -638,11 +650,11 @@ void CSVWorld::DialogueSubView::revertRecord()
mEditWidget->setDisabled(true); //closing the editor is other option mEditWidget->setDisabled(true); //closing the editor is other option
return; return;
} }
if (mRow >= mTable->rowCount()) if (currentIndex.row() >= mTable->rowCount())
{ {
prevId(); prevId();
} else { } else {
dataChanged(mTable->index(mRow, 0)); dataChanged(currentIndex);
} }
} }
} }
@ -650,19 +662,20 @@ void CSVWorld::DialogueSubView::revertRecord()
void CSVWorld::DialogueSubView::deleteRecord() void CSVWorld::DialogueSubView::deleteRecord()
{ {
int rows = mTable->rowCount(); const int rows = mTable->rowCount();
QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
//easier than disabling the button //easier than disabling the button
CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (mRow, 1)).toInt()); CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State>(mTable->data (mTable->index (currentIndex.row(), 1)).toInt());
bool deledetedOrErased = (state == CSMWorld::RecordBase::State_Deleted || state == CSMWorld::RecordBase::State_Erased); bool deledetedOrErased = (state == CSMWorld::RecordBase::State_Deleted);
if (!mLocked && if (!mLocked &&
mTable->columnCount() > 0 && mTable->columnCount() > 0 &&
!deledetedOrErased && !deledetedOrErased &&
mRow < rows && currentIndex.row() < rows &&
mBottom->canCreateAndDelete()) mBottom->canCreateAndDelete())
{ {
mUndoStack.push(new CSMWorld::DeleteCommand(*mTable, mTable->data(mTable->index (mRow, 0)).toString().toUtf8().constData())); mUndoStack.push(new CSMWorld::DeleteCommand(*mTable, mCurrentId));
if (rows != mTable->rowCount()) if (rows != mTable->rowCount())
{ {
if (mTable->rowCount() == 0) if (mTable->rowCount() == 0)
@ -670,11 +683,11 @@ void CSVWorld::DialogueSubView::deleteRecord()
mEditWidget->setDisabled(true); //closing the editor is other option mEditWidget->setDisabled(true); //closing the editor is other option
return; return;
} }
if (mRow >= mTable->rowCount()) if (currentIndex.row() >= mTable->rowCount())
{ {
prevId(); prevId();
} else { } else {
dataChanged(mTable->index(mRow, 0)); dataChanged(currentIndex);
} }
} }
} }
@ -682,29 +695,35 @@ void CSVWorld::DialogueSubView::deleteRecord()
void CSVWorld::DialogueSubView::requestFocus (const std::string& id) void CSVWorld::DialogueSubView::requestFocus (const std::string& id)
{ {
mRow = mTable->getModelIndex (id, 0).row(); mCurrentId = std::string(id);
mEditWidget->remake(mRow); mEditWidget->remake(mTable->getModelIndex (id, 0).row());
} }
void CSVWorld::DialogueSubView::cloneRequest () void CSVWorld::DialogueSubView::cloneRequest ()
{ {
mBottom->cloneRequest(mTable->data(mTable->index (mRow, 0)).toString().toUtf8().constData(), mBottom->cloneRequest(mCurrentId, static_cast<CSMWorld::UniversalId::Type>(mTable->data(mTable->getModelIndex(mCurrentId, 2)).toInt()));
static_cast<CSMWorld::UniversalId::Type>(mTable->data(mTable->index(mRow, 2)).toInt()));
} }
void CSVWorld::DialogueSubView::showPreview () void CSVWorld::DialogueSubView::showPreview ()
{ {
if (mTable->hasPreview() && mRow < mTable->rowCount()) QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
if (currentIndex.isValid() &&
mTable->hasPreview() &&
currentIndex.row() < mTable->rowCount())
{ {
emit focusId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Preview, mTable->data(mTable->index (mRow, 0)).toString().toUtf8().constData()), ""); emit focusId(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Preview, mCurrentId), "");
} }
} }
void CSVWorld::DialogueSubView::viewRecord() void CSVWorld::DialogueSubView::viewRecord()
{ {
if (mRow < mTable->rowCount()) QModelIndex currentIndex(mTable->getModelIndex(mCurrentId, 0));
if (currentIndex.isValid() &&
currentIndex.row() < mTable->rowCount())
{ {
std::pair<CSMWorld::UniversalId, std::string> params = mTable->view (mRow); std::pair<CSMWorld::UniversalId, std::string> params = mTable->view (currentIndex.row());
if (params.first.getType()!=CSMWorld::UniversalId::Type_None) if (params.first.getType()!=CSMWorld::UniversalId::Type_None)
emit focusId (params.first, params.second); emit focusId (params.first, params.second);