From a8c26ec0c11a5252de2e75fd26d9d83ef1afc13e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 27 Jun 2015 14:42:22 +0200 Subject: [PATCH] moved most of the code for next/prev buttons from DialogueSubView to RecordBUttonBar --- apps/opencs/view/world/dialoguesubview.cpp | 88 ++++------------------ apps/opencs/view/world/dialoguesubview.hpp | 6 +- apps/opencs/view/world/recordbuttonbar.cpp | 28 ++++++- apps/opencs/view/world/recordbuttonbar.hpp | 8 +- 4 files changed, 47 insertions(+), 83 deletions(-) diff --git a/apps/opencs/view/world/dialoguesubview.cpp b/apps/opencs/view/world/dialoguesubview.cpp index ffb606497..cf9d69f02 100644 --- a/apps/opencs/view/world/dialoguesubview.cpp +++ b/apps/opencs/view/world/dialoguesubview.cpp @@ -722,10 +722,10 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id, getMainLayout().addWidget (mBottom); // connections - connect (mButtons, SIGNAL (nextId()), this, SLOT (nextId())); - connect (mButtons, SIGNAL (prevId()), this, SLOT (prevId())); connect (mButtons, SIGNAL (showPreview()), this, SLOT (showPreview())); connect (mButtons, SIGNAL (viewRecord()), this, SLOT (viewRecord())); + connect (mButtons, SIGNAL (switchToRow (int)), this, SLOT (switchToRow (int))); + connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)), mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&))); } @@ -736,78 +736,6 @@ void CSVWorld::DialogueSubView::setEditLock (bool locked) mButtons->setEditLock (locked); } -void CSVWorld::DialogueSubView::prevId() -{ - int newRow = getTable().getModelIndex (getCurrentId(), 0).row() - 1; - - if (newRow < 0) - { - return; - } - while (newRow >= 0) - { - QModelIndex newIndex (getTable().index(newRow, 0)); - - if (!newIndex.isValid()) - { - return; - } - - CSMWorld::RecordBase::State state = static_cast (getTable().data (getTable().index (newRow, 1)).toInt()); - if (!(state == CSMWorld::RecordBase::State_Deleted || state == CSMWorld::RecordBase::State_Erased)) - { - getEditWidget().remake (newRow); - - setUniversalId(CSMWorld::UniversalId (static_cast (getTable().data (getTable().index (newRow, 2)).toInt()), - getTable().data (getTable().index (newRow, 0)).toString().toUtf8().constData())); - - changeCurrentId(std::string (getTable().data (getTable().index (newRow, 0)).toString().toUtf8().constData())); - - getEditWidget().setDisabled (isLocked()); - - return; - } - --newRow; - } -} - -void CSVWorld::DialogueSubView::nextId () -{ - int newRow = getTable().getModelIndex (getCurrentId(), 0).row() + 1; - - if (newRow >= getTable().rowCount()) - { - return; - } - - while (newRow < getTable().rowCount()) - { - QModelIndex newIndex (getTable().index(newRow, 0)); - - if (!newIndex.isValid()) - { - return; - } - - CSMWorld::RecordBase::State state = static_cast (getTable().data (getTable().index (newRow, 1)).toInt()); - if (!(state == CSMWorld::RecordBase::State_Deleted)) - { - getEditWidget().remake(newRow); - - setUniversalId(CSMWorld::UniversalId (static_cast (getTable().data (getTable().index (newRow, 2)).toInt()), - getTable().data (getTable().index (newRow, 0)).toString().toUtf8().constData())); - - changeCurrentId(std::string (getTable().data (getTable().index (newRow, 0)).toString().toUtf8().constData())); - - getEditWidget().setDisabled (isLocked()); - - return; - } - ++newRow; - } -} - - void CSVWorld::DialogueSubView::showPreview () { QModelIndex currentIndex (getTable().getModelIndex (getCurrentId(), 0)); @@ -833,3 +761,15 @@ void CSVWorld::DialogueSubView::viewRecord () emit focusId (params.first, params.second); } } + +void CSVWorld::DialogueSubView::switchToRow (int row) +{ + getEditWidget().remake (row); + + setUniversalId (CSMWorld::UniversalId (static_cast (getTable().data (getTable().index (row, 2)).toInt()), + getTable().data (getTable().index (row, 0)).toString().toUtf8().constData())); + + changeCurrentId(std::string (getTable().data (getTable().index (row, 0)).toString().toUtf8().constData())); + + getEditWidget().setDisabled (isLocked()); +} diff --git a/apps/opencs/view/world/dialoguesubview.hpp b/apps/opencs/view/world/dialoguesubview.hpp index 63b25d06e..ff70a37d3 100644 --- a/apps/opencs/view/world/dialoguesubview.hpp +++ b/apps/opencs/view/world/dialoguesubview.hpp @@ -236,13 +236,11 @@ namespace CSVWorld private slots: - void nextId(); - - void prevId(); - void showPreview(); void viewRecord(); + + void switchToRow (int row); }; } diff --git a/apps/opencs/view/world/recordbuttonbar.cpp b/apps/opencs/view/world/recordbuttonbar.cpp index 93a6a5823..375ab68c3 100644 --- a/apps/opencs/view/world/recordbuttonbar.cpp +++ b/apps/opencs/view/world/recordbuttonbar.cpp @@ -94,8 +94,8 @@ CSVWorld::RecordButtonBar::RecordButtonBar (const CSMWorld::UniversalId& id, connect (mCloneButton, SIGNAL (clicked()), this, SLOT (cloneRequest())); } - connect (nextButton, SIGNAL (clicked()), this, SIGNAL (nextId())); - connect (prevButton, SIGNAL (clicked()), this, SIGNAL (prevId())); + connect (nextButton, SIGNAL (clicked()), this, SLOT (nextId())); + connect (prevButton, SIGNAL (clicked()), this, SLOT (prevId())); if (mCommandDispatcher) { @@ -133,3 +133,27 @@ void CSVWorld::RecordButtonBar::cloneRequest() } } } + +void CSVWorld::RecordButtonBar::nextId() +{ + int newRow = mTable.getModelIndex (mId.getId(), 0).row() + 1; + + if (newRow >= mTable.rowCount()) + { + return; + } + + emit switchToRow (newRow); +} + +void CSVWorld::RecordButtonBar::prevId() +{ + int newRow = mTable.getModelIndex (mId.getId(), 0).row() - 1; + + if (newRow < 0) + { + return; + } + + emit switchToRow (newRow); +} diff --git a/apps/opencs/view/world/recordbuttonbar.hpp b/apps/opencs/view/world/recordbuttonbar.hpp index 95b567594..6a5fadca5 100644 --- a/apps/opencs/view/world/recordbuttonbar.hpp +++ b/apps/opencs/view/world/recordbuttonbar.hpp @@ -60,6 +60,10 @@ namespace CSVWorld private slots: void cloneRequest(); + + void nextId(); + + void prevId(); signals: @@ -67,9 +71,7 @@ namespace CSVWorld void viewRecord(); - void nextId(); - - void prevId(); + void switchToRow (int row); }; }