- fixed a bug that always deleted the first entry instead of the selected oone

This commit is contained in:
Dorian Zedler 2020-12-15 11:01:19 +01:00
parent 19a3601581
commit f860b3397b
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
7 changed files with 37 additions and 35 deletions

View file

@ -1,4 +1,4 @@
QT += quick bluetooth quickcontrols2
QT += gui quick bluetooth quickcontrols2
CONFIG += c++11
TARGET = ItsblueLedDisplayController

@ -1 +1 @@
Subproject commit d75f55a3a16a833599cd93e1fb22f2500a94dcf5
Subproject commit c72dc564e144315032f1d0d1c132aafdb2392c8c

View file

@ -20,15 +20,18 @@ QVariant LedDisplayTextModel::data(const QModelIndex &index, int role) const
}
QVariant LedDisplayTextModel::data(int row, int role) const {
if (row < rowCount()) {
if (row >= 0 && row < rowCount()) {
if(this->texts[row].contains(role)) {
if(role == IndexRole)
return row;
QVariant value = this->texts[row][role];
value.convert(this->roleDataTypes[LedDisplayTextModelRole(role)]);
return value;
}
else if(role == IndexRole) {
return row;
}
}
else {
qDebug() << "[WARING] Row " << row << "is larger than row count " << rowCount();
}
return QVariant();
}
@ -115,6 +118,7 @@ void LedDisplayTextModel::remove(int row)
if (row < 0 || row >= this->rowCount())
return;
qDebug() << "Removing row: " << row;
beginRemoveRows(QModelIndex(), row, row);
this->texts.removeAt(row);
endRemoveRows();

View file

@ -69,11 +69,8 @@ Dialog {
}
function edit() {
reset()
nameTextField.value = backend.bleClient.currentDevice.name
open()
}

View file

@ -30,7 +30,7 @@ ListView {
width: control.width
onClicked: {
popup.edit(model)
popup.edit(control.model, model)
}
}
@ -71,10 +71,5 @@ ListView {
Material.theme: control.Material.theme
Material.accent: control.Material.accent
onDiscarded: {
control.model.remove(editingModel.index)
popup.close()
}
}
}

View file

@ -10,6 +10,7 @@ Dialog {
property bool editing
property var editingModel
property var editingModelData
parent: Overlay.overlay
@ -25,15 +26,15 @@ Dialog {
onAccepted: {
if(editing) {
editingModel.active = activeSwitch.checked
editingModel.text = textTextField.value
editingModel.runtime = runtimeSpinBox.value
editingModel.color = colorColorPicker.value
editingModel.alignment = alignmentComboBox.currentIndex
editingModel.scroll = scrollSwitch.checked
editingModel.scrollDirection = scrollDirectionComboBox.currentIndex
editingModel.scrollSpeed = scrollSpeedSpinBox.value
editingModel.scrollCount = scrollCountSpinBox.value
editingModelData.active = activeSwitch.checked
editingModelData.text = textTextField.value
editingModelData.runtime = runtimeSpinBox.value
editingModelData.color = colorColorPicker.value
editingModelData.alignment = alignmentComboBox.currentIndex
editingModelData.scroll = scrollSwitch.checked
editingModelData.scrollDirection = scrollDirectionComboBox.currentIndex
editingModelData.scrollSpeed = scrollSpeedSpinBox.value
editingModelData.scrollCount = scrollCountSpinBox.value
}
else {
editingModel.append(textTextField.value,
@ -49,6 +50,11 @@ Dialog {
}
}
onDiscarded: {
editingModel.remove(popup.editingModelData.index)
popup.close()
}
contentItem: Flickable {
implicitHeight: dataFieldsGridLayout.height
@ -163,21 +169,22 @@ Dialog {
}
}
function edit(model) {
function edit(model, modelData) {
editingModel = model
editingModelData = modelData
editing = true
reset()
activeSwitch.checked = editingModel.active
textTextField.value = editingModel.text
runtimeSpinBox.value = editingModel.runtime
colorColorPicker.value = editingModel.color
alignmentComboBox.currentIndex = editingModel.alignment
scrollSwitch.checked = editingModel.scroll
scrollDirectionComboBox.currentIndex = editingModel.scrollDirection
scrollSpeedSpinBox.value = editingModel.scrollSpeed
scrollCountSpinBox.value = editingModel.scrollCount
activeSwitch.checked = editingModelData.active
textTextField.value = editingModelData.text
runtimeSpinBox.value = editingModelData.runtime
colorColorPicker.value = editingModelData.color
alignmentComboBox.currentIndex = editingModelData.alignment
scrollSwitch.checked = editingModelData.scroll
scrollDirectionComboBox.currentIndex = editingModelData.scrollDirection
scrollSpeedSpinBox.value = editingModelData.scrollSpeed
scrollCountSpinBox.value = editingModelData.scrollCount
open()
}

@ -1 +0,0 @@
Subproject commit 76e457593e889885fd410fdbcdd659706a1eceb8