working edit/delete items

This commit is contained in:
mappu 2017-05-21 17:53:40 +12:00
parent 37f9307db1
commit 4f1c48b55d
2 changed files with 70 additions and 5 deletions

View File

@ -17,7 +17,7 @@
<iconset resource="resources.qrc">
<normaloff>:/rsrc/database_lightning.png</normaloff>:/rsrc/database_lightning.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
@ -30,6 +30,9 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QPlainTextEdit" name="contentArea">
<property name="frameShape">
@ -37,10 +40,62 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ItemWindow</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>184</x>
<y>330</y>
</hint>
<hint type="destinationlabel">
<x>184</x>
<y>176</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ItemWindow</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>184</x>
<y>330</y>
</hint>
<hint type="destinationlabel">
<x>184</x>
<y>176</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -270,7 +270,7 @@ void MainWindow::on_actionClear_selection_triggered()
}
#define GET_ITM_TOP_BROWSE_BDB \
QTreeWidgetItem* itm = lastContextSelection; \
QTreeWidgetItem* itm = ui->bucketTree->currentItem(); \
if (itm == nullptr) { \
return; \
} \
@ -300,7 +300,18 @@ void MainWindow::on_bucketData_doubleClicked(const QModelIndex &index)
auto iw = new ItemWindow();
iw->ContentArea()->setPlainText(QString::fromUtf8(content));
iw->setWindowTitle(key);
connect(iw, &ItemWindow::finished, iw, &ItemWindow::deleteLater);
connect(iw, &ItemWindow::finished, iw, [=](int exitCode){
if (exitCode == ItemWindow::Accepted) {
QString err;
if (! bdb->setItem(browse, key.toUtf8(), iw->ContentArea()->toPlainText().toUtf8(), err)) {
QMessageBox qmb;
qmb.setText(tr("Error saving item content: %1").arg(err));
qmb.exec();
}
}
iw->deleteLater();
});
iw->show();
},
[=](QString error) {
@ -370,7 +381,6 @@ void MainWindow::on_AddDataButton_clicked()
}
void MainWindow::on_DeleteDataButton_clicked()
{
GET_ITM_TOP_BROWSE_BDB;