mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-13 17:09:05 -05:00
Fixed empty list bug in keybindings section
This commit is contained in:
@@ -41,6 +41,7 @@ private:
|
||||
std::string truncateString(std::string& s);
|
||||
void replaceChars(std::string& src, const std::string& from,
|
||||
const std::string& to);
|
||||
bool isLineEmpty(int index);
|
||||
|
||||
Ui::keybindings *ui;
|
||||
QWidget* _parent;
|
||||
@@ -50,6 +51,14 @@ private:
|
||||
std::vector<int> _mapModKeyComboBoxIndexToKeyValue;
|
||||
std::vector<int> _mapKeyComboBoxIndexToKeyValue;
|
||||
bool _editModeNewItem = false;
|
||||
const openspace::Profile::Keybinding kBlank = {
|
||||
{openspace::Key::Unknown, openspace::KeyModifier::NoModifier},
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
""
|
||||
};
|
||||
};
|
||||
|
||||
#endif // KEYBINDINGS_H
|
||||
|
||||
@@ -43,6 +43,7 @@ private:
|
||||
openspace::Profile* _imported;
|
||||
std::vector<openspace::Profile::Module> _data;
|
||||
bool _editModeNewItem = false;
|
||||
const openspace::Profile::Module kBlank = {"", "", ""};
|
||||
};
|
||||
|
||||
#endif // OSMODULES_H
|
||||
|
||||
@@ -51,11 +51,11 @@ QString keybindings::createOneLineSummary(openspace::Profile::Keybinding k) {
|
||||
|
||||
int keymod = static_cast<int>(k.key.modifier);
|
||||
if (keymod != static_cast<int>(openspace::KeyModifier::NoModifier)) {
|
||||
summary += openspace::KeyModifierNames.at(keymod) + "+";
|
||||
summary += openspace::KeyModifierNames.at(keymod) + " ";
|
||||
}
|
||||
int keyname = static_cast<int>(k.key.key);
|
||||
|
||||
summary += openspace::KeyNames.at(keyname) + " : ";
|
||||
summary += openspace::KeyNames.at(keyname) + " ";
|
||||
summary += truncateString(k.name) + " (";
|
||||
summary += truncateString(k.documentation) + ") @ ";
|
||||
summary += truncateString(k.guiPath) + " ";
|
||||
@@ -123,17 +123,31 @@ int keybindings::indexInKeyMapping(std::vector<int>& mapVector, int keyInt) {
|
||||
return std::distance(mapVector.begin(), it);
|
||||
}
|
||||
|
||||
bool keybindings::isLineEmpty(int index) {
|
||||
bool isEmpty = true;
|
||||
if (ui->list->item(index)->text().compare("") != 0) {
|
||||
isEmpty = false;
|
||||
}
|
||||
if ((_data.size() > 0) && (_data.at(0).name.compare("") != 0)) {
|
||||
isEmpty = false;
|
||||
}
|
||||
return isEmpty;
|
||||
}
|
||||
|
||||
void keybindings::listItemAdded(void) {
|
||||
//Add new line at bottom of props list
|
||||
_data.push_back({
|
||||
{openspace::Key::Unknown, openspace::KeyModifier::NoModifier},
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
true,
|
||||
""
|
||||
});
|
||||
ui->list->addItem(new QListWidgetItem(" (Enter details below and click 'Save')"));
|
||||
int currentListSize = ui->list->count();
|
||||
|
||||
if ((currentListSize == 1) && (isLineEmpty(0))) {
|
||||
//Special case where list is "empty" but really has one line that is blank.
|
||||
// This is done because QListWidget does not seem to like having its sole
|
||||
// remaining item being removed.
|
||||
_data.at(0) = kBlank;
|
||||
ui->list->item(0)->setText(" (Enter details below & click 'Save')");
|
||||
}
|
||||
else {
|
||||
_data.push_back(kBlank);
|
||||
ui->list->addItem(new QListWidgetItem(" (Enter details below and click 'Save')"));
|
||||
}
|
||||
|
||||
//Scroll down to that blank line highlighted
|
||||
ui->list->setCurrentRow(ui->list->count() - 1);
|
||||
@@ -218,22 +232,33 @@ void keybindings::listItemCancelSave(void) {
|
||||
|
||||
void keybindings::listItemRemove(void) {
|
||||
if (ui->list->count() > 0) {
|
||||
int index = ui->list->currentRow();
|
||||
if (index >= 0 && index < ui->list->count()) {
|
||||
ui->list->takeItem(index);
|
||||
if (_data.size() > 0) {
|
||||
_data.erase(_data.begin() + index);
|
||||
if (ui->list->count() == 1) {
|
||||
//Special case where last remaining item is being removed (QListWidget does
|
||||
// not like the final item being removed so instead clear it & leave it)
|
||||
_data.at(0) = kBlank;
|
||||
ui->list->item(0)->setText("");
|
||||
}
|
||||
else {
|
||||
int index = ui->list->currentRow();
|
||||
if (index >= 0 && index < ui->list->count()) {
|
||||
ui->list->takeItem(index);
|
||||
if (_data.size() > 0) {
|
||||
_data.erase(_data.begin() + index);
|
||||
}
|
||||
}
|
||||
}
|
||||
ui->list->clearSelection();
|
||||
transitionFromEditMode();
|
||||
}
|
||||
ui->list->clearSelection();
|
||||
transitionFromEditMode();
|
||||
}
|
||||
|
||||
void keybindings::transitionToEditMode(void) {
|
||||
ui->list->setDisabled(true);
|
||||
ui->button_add->setDisabled(true);
|
||||
ui->button_remove->setDisabled(true);
|
||||
ui->button_save->setDisabled(true);
|
||||
ui->button_cancel->setDisabled(true);
|
||||
ui->buttonBox->setDisabled(true);
|
||||
|
||||
editBoxDisabled(false);
|
||||
}
|
||||
@@ -242,6 +267,9 @@ void keybindings::transitionFromEditMode(void) {
|
||||
ui->list->setDisabled(false);
|
||||
ui->button_add->setDisabled(false);
|
||||
ui->button_remove->setDisabled(false);
|
||||
ui->button_save->setDisabled(false);
|
||||
ui->button_cancel->setDisabled(false);
|
||||
ui->buttonBox->setDisabled(false);
|
||||
|
||||
editBoxDisabled(true);
|
||||
ui->label_key->setText("<font color='black'>Key</font>");
|
||||
@@ -267,6 +295,10 @@ void keybindings::editBoxDisabled(bool disabled) {
|
||||
}
|
||||
|
||||
void keybindings::parseSelections() {
|
||||
//Handle case with only one remaining but empty line
|
||||
if ((_data.size() == 1) && (_data.at(0).name.compare("") == 0)) {
|
||||
_data.clear();
|
||||
}
|
||||
_imported->setKeybindings(_data);
|
||||
accept();
|
||||
}
|
||||
|
||||
@@ -77,11 +77,11 @@ void osmodules::listItemAdded(void) {
|
||||
//Special case where list is "empty" but really has one line that is blank.
|
||||
// This is done because QListWidget does not seem to like having its sole
|
||||
// remaining item being removed.
|
||||
_data.at(0) = {"", "", ""};
|
||||
_data.at(0) = kBlank;
|
||||
ui->list->item(0)->setText(" (Enter details below & click 'Save')");
|
||||
}
|
||||
else {
|
||||
_data.push_back({"", "", ""});
|
||||
_data.push_back(kBlank);
|
||||
ui->list->addItem(new QListWidgetItem(" (Enter details below & click 'Save')"));
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ void osmodules::listItemRemove(void) {
|
||||
if (ui->list->count() == 1) {
|
||||
//Special case where last remaining item is being removed (QListWidget does
|
||||
// not like the final item being removed so instead clear it & leave it)
|
||||
_data.at(0) = {"", "", ""};
|
||||
_data.at(0) = kBlank;
|
||||
ui->list->item(0)->setText("");
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user