Skip to content

Commit

Permalink
Wobbly: select a new preset when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
cantabile committed Aug 18, 2015
1 parent 344e3f3 commit 192459d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
72 changes: 45 additions & 27 deletions src/wobbly/WobblyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3752,8 +3752,13 @@ void WobblyWindow::presetNew() {
try {
project->addPreset(preset_name.toStdString());

QStringList presets = presets_model->stringList();
QString selected = presets[getSelectedPreset()];

updatePresets();

setSelectedPreset(presets.indexOf(selected));

preset_combo->setCurrentText(preset_name);

presetChanged(preset_name);
Expand Down Expand Up @@ -3787,6 +3792,9 @@ void WobblyWindow::presetRename() {

updatePresets();

int index = presets_model->stringList().indexOf(preset_name);
setSelectedPreset(index);

preset_combo->setCurrentText(preset_name);

updateCustomListsEditor();
Expand Down Expand Up @@ -3827,29 +3835,18 @@ void WobblyWindow::presetDelete() {

updatePresets();

setSelectedPreset(selected_preset);

if (preset_combo->count()) {
index = std::min(index, preset_combo->count() - 1);
preset_combo->setCurrentIndex(index);
}
presetChanged(preset_combo->currentText());

if (preset_in_use) {
auto selection = sections_table->selectedRanges();

updateSectionsEditor();

sections_table->clearSelection();
for (int i = 0; i < selection.size(); i++)
sections_table->setRangeSelected(selection[i], true);


selection = cl_table->selectedRanges();

updateCustomListsEditor();

cl_table->clearSelection();
for (int i = 0; i < selection.size(); i++)
cl_table->setRangeSelected(selection[i], true);
}
}

Expand Down Expand Up @@ -4200,27 +4197,46 @@ void WobblyWindow::cancelRange() {
}


int WobblyWindow::getSelectedPreset() const {
return selected_preset;
}


void WobblyWindow::setSelectedPreset(int index) {
QStringList presets = presets_model->stringList();

if (index >= presets.size())
index = presets.size() - 1;

selected_preset = index;

selected_preset_label->setText("Selected preset: " + (selected_preset > -1 ? presets[selected_preset] : ""));
}


void WobblyWindow::selectPreviousPreset() {
if (!project)
return;

QStringList presets = presets_model->stringList();

int index = getSelectedPreset();

if (presets.size() == 0) {
selected_preset = -1;
index = -1;
} else if (presets.size() == 1) {
selected_preset = 0;
index = 0;
} else {
if (selected_preset == -1) {
selected_preset = presets.size() - 1;
if (index == -1) {
index = presets.size() - 1;
} else {
if (selected_preset == 0)
selected_preset = presets.size();
selected_preset--;
if (index == 0)
index = presets.size();
index--;
}
}

selected_preset_label->setText("Selected preset: " + (selected_preset > -1 ? presets[selected_preset] : ""));
setSelectedPreset(index);
}


Expand All @@ -4230,19 +4246,21 @@ void WobblyWindow::selectNextPreset() {

QStringList presets = presets_model->stringList();

int index = getSelectedPreset();

if (presets.size() == 0) {
selected_preset = -1;
index = -1;
} else if (presets.size() == 1) {
selected_preset = 0;
index = 0;
} else {
if (selected_preset == -1) {
selected_preset = 0;
if (index == -1) {
index = 0;
} else {
selected_preset = (selected_preset + 1) % presets.size();
index = (index + 1) % presets.size();
}
}

selected_preset_label->setText("Selected preset: " + (selected_preset > -1 ? presets[selected_preset] : ""));
setSelectedPreset(index);
}


Expand Down
2 changes: 2 additions & 0 deletions src/wobbly/WobblyWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ class WobblyWindow : public QMainWindow {
void finishRange();
void cancelRange();

int getSelectedPreset() const;
void setSelectedPreset(int index);
void selectPreviousPreset();
void selectNextPreset();
void selectPreviousCustomList();
Expand Down

0 comments on commit 192459d

Please sign in to comment.