CStringEditor: Unindent some code

This commit is contained in:
Lioncash 2020-07-10 11:22:34 -04:00
parent 0b33933a16
commit a5d9f41559
1 changed files with 72 additions and 73 deletions

View File

@ -168,13 +168,13 @@ void CStringEditor::UpdateStatusBar()
void CStringEditor::SetActiveLanguage(ELanguage Language) void CStringEditor::SetActiveLanguage(ELanguage Language)
{ {
if (mCurrentLanguage != Language) if (mCurrentLanguage == Language)
{ return;
mCurrentLanguage = Language;
mpListModel->SetPreviewLanguage(Language); mCurrentLanguage = Language;
UpdateUI(); mpListModel->SetPreviewLanguage(Language);
SaveSettings(); UpdateUI();
} SaveSettings();
} }
void CStringEditor::SetActiveString(int StringIndex) void CStringEditor::SetActiveString(int StringIndex)
@ -204,7 +204,7 @@ void CStringEditor::LoadSettings()
void CStringEditor::SaveSettings() void CStringEditor::SaveSettings()
{ {
QSettings Settings; QSettings Settings;
Settings.setValue(gkpLanguageSetting, (int) mCurrentLanguage); Settings.setValue(gkpLanguageSetting, static_cast<int>(mCurrentLanguage));
} }
/** Slots */ /** Slots */
@ -220,10 +220,11 @@ void CStringEditor::UpdateUI()
// Update selection in string list // Update selection in string list
QItemSelectionModel* pSelectionModel = mpUI->StringNameListView->selectionModel(); QItemSelectionModel* pSelectionModel = mpUI->StringNameListView->selectionModel();
QModelIndex OldStringIndex = pSelectionModel->hasSelection() ? const QModelIndex OldStringIndex = pSelectionModel->hasSelection()
pSelectionModel->currentIndex() : QModelIndex(); ? pSelectionModel->currentIndex()
: QModelIndex();
QModelIndex NewStringIndex = mpUI->StringNameListView->model()->index(mCurrentStringIndex,0); const QModelIndex NewStringIndex = mpUI->StringNameListView->model()->index(mCurrentStringIndex,0);
if (OldStringIndex != NewStringIndex) if (OldStringIndex != NewStringIndex)
{ {
@ -255,20 +256,20 @@ void CStringEditor::UpdateUI()
} }
// Update string name/data fields // Update string name/data fields
QString StringName = TO_QSTRING( mpStringTable->StringNameByIndex(mCurrentStringIndex) ); const QString StringName = TO_QSTRING(mpStringTable->StringNameByIndex(mCurrentStringIndex));
QString StringData = TO_QSTRING( mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex) ); const QString StringData = TO_QSTRING(mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex));
if (StringName != mpUI->StringNameLineEdit->text()) if (StringName != mpUI->StringNameLineEdit->text())
{ {
mpUI->StringNameLineEdit->blockSignals(true); mpUI->StringNameLineEdit->blockSignals(true);
mpUI->StringNameLineEdit->setText( StringName ); mpUI->StringNameLineEdit->setText(StringName);
mpUI->StringNameLineEdit->blockSignals(false); mpUI->StringNameLineEdit->blockSignals(false);
} }
if (StringData != mpUI->StringTextEdit->toPlainText()) if (StringData != mpUI->StringTextEdit->toPlainText())
{ {
mpUI->StringTextEdit->blockSignals(true); mpUI->StringTextEdit->blockSignals(true);
mpUI->StringTextEdit->setPlainText( StringData ); mpUI->StringTextEdit->setPlainText(StringData);
mpUI->StringTextEdit->blockSignals(false); mpUI->StringTextEdit->blockSignals(false);
} }
@ -277,11 +278,11 @@ void CStringEditor::UpdateUI()
void CStringEditor::OnStringSelected(const QModelIndex& kIndex) void CStringEditor::OnStringSelected(const QModelIndex& kIndex)
{ {
if (mCurrentStringIndex != kIndex.row()) if (mCurrentStringIndex == static_cast<uint32>(kIndex.row()))
{ return;
IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, kIndex.row());
UndoStack().push(pCommand); IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, kIndex.row());
} UndoStack().push(pCommand);
} }
void CStringEditor::OnLanguageChanged(int LanguageIndex) void CStringEditor::OnLanguageChanged(int LanguageIndex)
@ -298,30 +299,28 @@ void CStringEditor::OnLanguageChanged(int LanguageIndex)
void CStringEditor::OnStringNameEdited() void CStringEditor::OnStringNameEdited()
{ {
TString NewName = TO_TSTRING( mpUI->StringNameLineEdit->text() ); TString NewName = TO_TSTRING(mpUI->StringNameLineEdit->text());
if (mpStringTable->StringNameByIndex(mCurrentStringIndex) != NewName) if (mpStringTable->StringNameByIndex(mCurrentStringIndex) == NewName)
{ return;
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Edit String Name"), mpStringTable, false);
mpStringTable->SetStringName(mCurrentStringIndex, std::move(NewName)); IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Edit String Name"), mpStringTable, false);
mIsEditingStringName = true; mpStringTable->SetStringName(mCurrentStringIndex, std::move(NewName));
UndoStack().push(pCommand); mIsEditingStringName = true;
} UndoStack().push(pCommand);
} }
void CStringEditor::OnStringTextEdited() void CStringEditor::OnStringTextEdited()
{ {
TString NewText = TO_TSTRING(mpUI->StringTextEdit->toPlainText()); TString NewText = TO_TSTRING(mpUI->StringTextEdit->toPlainText());
if (mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex) != NewText) if (mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex) == NewText)
{ return;
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Edit String"), mpStringTable, false);
mpStringTable->SetString(mCurrentLanguage, mCurrentStringIndex, std::move(NewText)); IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Edit String"), mpStringTable, false);
mIsEditingStringData = true; mpStringTable->SetString(mCurrentLanguage, mCurrentStringIndex, std::move(NewText));
UndoStack().push(pCommand); mIsEditingStringData = true;
} UndoStack().push(pCommand);
} }
void CStringEditor::OnAddString() void CStringEditor::OnAddString()
@ -330,7 +329,7 @@ void CStringEditor::OnAddString()
// Add string // Add string
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Add String"), mpStringTable, true); IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Add String"), mpStringTable, true);
uint Index = mCurrentStringIndex + 1; const uint32 Index = mCurrentStringIndex + 1;
mpStringTable->AddString(Index); mpStringTable->AddString(Index);
UndoStack().push(pCommand); UndoStack().push(pCommand);
@ -345,56 +344,56 @@ void CStringEditor::OnAddString()
void CStringEditor::OnRemoveString() void CStringEditor::OnRemoveString()
{ {
if (mpUI->StringNameListView->selectionModel()->hasSelection()) if (!mpUI->StringNameListView->selectionModel()->hasSelection())
{ return;
UndoStack().beginMacro(tr("Remove String"));
const size_t Index = mCurrentStringIndex;
// Change selection to a new string. UndoStack().beginMacro(tr("Remove String"));
// Do this before actually removing the string so that if the action is undone, the const size_t Index = mCurrentStringIndex;
// editor will not attempt to re-select the string before it gets readded to the table.
const size_t NewStringCount = mpStringTable->NumStrings() - 1;
const size_t NewIndex = (Index >= NewStringCount ? NewStringCount - 1 : Index);
IUndoCommand* pCommand = new CSetStringIndexCommand(this, Index, NewIndex);
UndoStack().push(pCommand);
// Remove the string // Change selection to a new string.
pCommand = new TSerializeUndoCommand<CStringTable>(tr("Remove String"), mpStringTable, true); // Do this before actually removing the string so that if the action is undone, the
mpStringTable->RemoveString(Index); // editor will not attempt to re-select the string before it gets readded to the table.
UndoStack().push(pCommand); const size_t NewStringCount = mpStringTable->NumStrings() - 1;
UndoStack().endMacro(); const size_t NewIndex = (Index >= NewStringCount ? NewStringCount - 1 : Index);
} IUndoCommand* pCommand = new CSetStringIndexCommand(this, Index, NewIndex);
UndoStack().push(pCommand);
// Remove the string
pCommand = new TSerializeUndoCommand<CStringTable>(tr("Remove String"), mpStringTable, true);
mpStringTable->RemoveString(Index);
UndoStack().push(pCommand);
UndoStack().endMacro();
} }
void CStringEditor::OnMoveString(int StringIndex, int NewIndex) void CStringEditor::OnMoveString(int StringIndex, int NewIndex)
{ {
if (StringIndex != NewIndex) if (StringIndex == NewIndex)
{ return;
ASSERT( StringIndex >= 0 && StringIndex < (int) mpStringTable->NumStrings() );
ASSERT( NewIndex >= 0 && NewIndex < (int) mpStringTable->NumStrings() );
UndoStack().beginMacro(tr("Move String"));
// Move string ASSERT(StringIndex >= 0 && StringIndex < static_cast<int>(mpStringTable->NumStrings()));
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Move String"), mpStringTable, true); ASSERT(NewIndex >= 0 && NewIndex < static_cast<int>(mpStringTable->NumStrings()));
mpStringTable->MoveString(StringIndex, NewIndex); UndoStack().beginMacro(tr("Move String"));
UndoStack().push(pCommand);
// Select new string index // Move string
pCommand = new CSetStringIndexCommand(this, StringIndex, NewIndex); IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Move String"), mpStringTable, true);
UndoStack().push(pCommand); mpStringTable->MoveString(StringIndex, NewIndex);
UndoStack().endMacro(); UndoStack().push(pCommand);
}
// Select new string index
pCommand = new CSetStringIndexCommand(this, StringIndex, NewIndex);
UndoStack().push(pCommand);
UndoStack().endMacro();
} }
void CStringEditor::IncrementStringIndex() void CStringEditor::IncrementStringIndex()
{ {
uint NewIndex = mCurrentStringIndex + 1; const uint32 NewIndex = mCurrentStringIndex + 1;
if (NewIndex < mpStringTable->NumStrings()) if (NewIndex >= mpStringTable->NumStrings())
{ return;
IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, NewIndex);
UndoStack().push(pCommand); IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, NewIndex);
} UndoStack().push(pCommand);
} }
void CStringEditor::DecrementStringIndex() void CStringEditor::DecrementStringIndex()