From c1e7f22157f386a7b78f015e26fa314c09ecdebb Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 14 Oct 2018 01:26:22 +0200 Subject: [PATCH] Qt interface: Make it possible to add receipts (fixes #2) --- CMakeLists.txt | 2 +- src/interface_qt.cpp | 34 +++++++++++- src/interface_qt.hpp | 11 +++- src/whyblocked_add.ui | 119 +++++++++++++++++++++++++++++++++--------- 4 files changed, 136 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1c1276..6dce8af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.6) project (whyblocked - VERSION 0.7.1 + VERSION 0.7.2 LANGUAGES CXX ) diff --git a/src/interface_qt.cpp b/src/interface_qt.cpp index c0064e3..88a8867 100644 --- a/src/interface_qt.cpp +++ b/src/interface_qt.cpp @@ -97,6 +97,10 @@ void MainWindow::add() add_row(QString::fromStdString(user), blocked, QString::fromStdString(reason)); + for (const string &receipt : std::get<3>(data)) + { + add_url(user, receipt); + } statusBar()->showMessage(tr("Added %1 to database.") .arg(QString::fromStdString(user))); @@ -116,6 +120,7 @@ void MainWindow::remove() .arg(QString::fromStdString(user))); _model->removeRow(row.row()); } + label_receipts->clear(); } else { @@ -168,13 +173,38 @@ const string MainWindow::urls_to_hyperlinks(const string &text) DialogAdd::DialogAdd(QMainWindow *parent) : QDialog(parent) { setupUi(this); + connect(button_receipt_add, &QPushButton::clicked, this, &DialogAdd::add_receipt); + connect(button_receipt_remove, &QPushButton::clicked, this, &DialogAdd::remove_receipt); } -const std::tuple DialogAdd::get_data() +const dialogdata DialogAdd::get_data() { + std::vector receipts; + for (int row = 0; row <= list_receipts->count() - 1; ++row) + { + receipts.push_back(list_receipts->item(row)->text().toStdString()); + } + return std::make_tuple(text_user->text().toStdString(), radio_blocked->isChecked(), - text_reason->text().toStdString()); + text_reason->text().toStdString(), + receipts); +} + +void DialogAdd::add_receipt() +{ + QListWidgetItem *item = new QListWidgetItem("Test"); + item->setFlags(item->flags() | Qt::ItemIsEditable); + list_receipts->insertItem(list_receipts->count(), item); + list_receipts->editItem(item); +} + +void DialogAdd::remove_receipt() +{ + for (auto item :list_receipts->selectedItems()) + { + delete item; + } } int main(int argc, char *argv[]) diff --git a/src/interface_qt.hpp b/src/interface_qt.hpp index 034f3e4..784aeab 100644 --- a/src/interface_qt.hpp +++ b/src/interface_qt.hpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,10 @@ #include "ui_whyblocked_add.h" using std::string; +using dialogdata = std::tuple>; class MainWindow : public QMainWindow, private Ui::MainWindow { @@ -54,7 +59,11 @@ class DialogAdd : public QDialog, private Ui::DialogAdd public: explicit DialogAdd(QMainWindow *parent = nullptr); - const std::tuple get_data(); + const dialogdata get_data(); + +private slots: + void add_receipt(); + void remove_receipt(); }; #endif // INTERFACE_QT_HPP diff --git a/src/whyblocked_add.ui b/src/whyblocked_add.ui index 229522d..838af6b 100644 --- a/src/whyblocked_add.ui +++ b/src/whyblocked_add.ui @@ -6,23 +6,57 @@ 0 0 - 300 - 170 + 400 + 300 Dialog + + + - - - + + + QLayout::SetDefaultConstraint + + + 6 + + + + + + 0 + 0 + + + + Memory aids, proof + - User/Instance + Receipts + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - text_user + list_receipts + + + + + + + Add receipt + + + Add + + + @@ -48,22 +82,6 @@ - - - - - 0 - 0 - - - - Blocked/Silenced - - - radio_blocked - - - @@ -90,7 +108,7 @@ - + Qt::Horizontal @@ -100,6 +118,52 @@ + + + + + 0 + 0 + + + + Blocked/Silenced + + + radio_blocked + + + + + + + User/Instance + + + text_user + + + + + + + Remove receipt + + + Remove + + + + + + + + + + QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked + + + @@ -109,6 +173,9 @@ radio_blocked radio_silcenced text_reason + button_receipt_add + button_receipt_remove + list_receipts @@ -120,7 +187,7 @@ 227 - 147 + 256 157 @@ -136,7 +203,7 @@ 290 - 153 + 262 286