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,14 +168,14 @@ void CStringEditor::UpdateStatusBar()
void CStringEditor::SetActiveLanguage(ELanguage Language) void CStringEditor::SetActiveLanguage(ELanguage Language)
{ {
if (mCurrentLanguage != Language) if (mCurrentLanguage == Language)
{ return;
mCurrentLanguage = Language; mCurrentLanguage = Language;
mpListModel->SetPreviewLanguage(Language); mpListModel->SetPreviewLanguage(Language);
UpdateUI(); UpdateUI();
SaveSettings(); 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,8 +256,8 @@ 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())
{ {
@ -277,12 +278,12 @@ 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()); IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, kIndex.row());
UndoStack().push(pCommand); UndoStack().push(pCommand);
} }
}
void CStringEditor::OnLanguageChanged(int LanguageIndex) void CStringEditor::OnLanguageChanged(int LanguageIndex)
{ {
@ -300,29 +301,27 @@ 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);
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Edit String Name"), mpStringTable, false);
mpStringTable->SetStringName(mCurrentStringIndex, std::move(NewName)); mpStringTable->SetStringName(mCurrentStringIndex, std::move(NewName));
mIsEditingStringName = true; mIsEditingStringName = true;
UndoStack().push(pCommand); 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);
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>(tr("Edit String"), mpStringTable, false);
mpStringTable->SetString(mCurrentLanguage, mCurrentStringIndex, std::move(NewText)); mpStringTable->SetString(mCurrentLanguage, mCurrentStringIndex, std::move(NewText));
mIsEditingStringData = true; mIsEditingStringData = true;
UndoStack().push(pCommand); 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,8 +344,9 @@ 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")); UndoStack().beginMacro(tr("Remove String"));
const size_t Index = mCurrentStringIndex; const size_t Index = mCurrentStringIndex;
@ -364,14 +364,14 @@ void CStringEditor::OnRemoveString()
UndoStack().push(pCommand); UndoStack().push(pCommand);
UndoStack().endMacro(); 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() ); ASSERT(StringIndex >= 0 && StringIndex < static_cast<int>(mpStringTable->NumStrings()));
ASSERT(NewIndex >= 0 && NewIndex < static_cast<int>(mpStringTable->NumStrings()));
UndoStack().beginMacro(tr("Move String")); UndoStack().beginMacro(tr("Move String"));
// Move string // Move string
@ -384,18 +384,17 @@ void CStringEditor::OnMoveString(int StringIndex, int NewIndex)
UndoStack().push(pCommand); UndoStack().push(pCommand);
UndoStack().endMacro(); UndoStack().endMacro();
} }
}
void CStringEditor::IncrementStringIndex() void CStringEditor::IncrementStringIndex()
{ {
uint NewIndex = mCurrentStringIndex + 1; const uint32 NewIndex = mCurrentStringIndex + 1;
if (NewIndex >= mpStringTable->NumStrings())
return;
if (NewIndex < mpStringTable->NumStrings())
{
IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, NewIndex); IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, NewIndex);
UndoStack().push(pCommand); UndoStack().push(pCommand);
} }
}
void CStringEditor::DecrementStringIndex() void CStringEditor::DecrementStringIndex()
{ {