Browse Source

Added means to edit entries in the Qt interface

fixes #1
tags/0.8.0
tastytea 1 year ago
parent
commit
f6e0b97e77
Signed by: tastytea <tastytea@tastytea.de> GPG Key ID: CFC39497F1B26E07
4 changed files with 116 additions and 26 deletions
  1. +1
    -1
      CMakeLists.txt
  2. +68
    -17
      src/interface_qt.cpp
  3. +14
    -8
      src/interface_qt.hpp
  4. +33
    -0
      src/whyblocked.ui

+ 1
- 1
CMakeLists.txt View File

@@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.6)
project (whyblocked
VERSION 0.7.8
VERSION 0.8.0
LANGUAGES CXX
)


+ 68
- 17
src/interface_qt.cpp View File

@@ -77,6 +77,39 @@ void MainWindow::add()
dialog->show();
}

void MainWindow::edit()
{
if (tableview->selectionModel()->selectedRows().count() != 1)
{
QMessageBox::warning(this, tr("Invalid selection"),
tr("Please select only 1 entry to edit."));
return;
}

DialogAdd *dialog = new DialogAdd(this);
dialog->setWindowTitle(tr("Edit entry"));

Dialogdata data;
QModelIndex index = tableview->selectionModel()->selectedRows().first();
data.user = index.sibling(index.row(), 0).data().toString().toStdString();
result_details details;
database::details(data.user, details);
if (std::get<0>(details) == true)
{
data.blocked = 1;
}
else
{
data.blocked = 0;
}
data.reason = std::get<1>(details);
data.receipts = std::get<2>(details);

dialog->set_data(data);
dialog->setProperty("edit", true);
dialog->show();
}

void MainWindow::remove()
{
QItemSelectionModel *selection = tableview->selectionModel();
@@ -147,7 +180,7 @@ DialogAdd::DialogAdd(QMainWindow *parent)
setupUi(this);
}

const dialogdata DialogAdd::get_data()
const Dialogdata DialogAdd::get_data() const
{
std::vector<string> receipts;
for (int row = 0; row <= list_receipts->count() - 1; ++row)
@@ -155,10 +188,27 @@ const dialogdata DialogAdd::get_data()
receipts.push_back(list_receipts->item(row)->text().toStdString());
}

return std::make_tuple(text_user->text().toStdString(),
radio_blocked->isChecked(),
text_reason->text().toStdString(),
receipts);
Dialogdata data;
data.user = text_user->text().toStdString();
data.blocked = radio_blocked->isChecked();
data.reason = text_reason->text().toStdString();
data.receipts = receipts;

return data;
}

const void DialogAdd::set_data(const Dialogdata &data)
{
text_user->setText(QString::fromStdString(data.user));
radio_blocked->setChecked(data.blocked);
radio_silcenced->setChecked(!data.blocked);
text_reason->setText(QString::fromStdString(data.reason));
for (const string &receipt : data.receipts)
{
QListWidgetItem *item = new QListWidgetItem(QString::fromStdString(receipt));
item->setFlags(item->flags() | Qt::ItemIsEditable);
list_receipts->insertItem(list_receipts->count(), item);
}
}

void DialogAdd::add_receipt()
@@ -179,26 +229,27 @@ void DialogAdd::remove_receipt()

void DialogAdd::accept()
{
auto data = get_data();
const string user = std::get<0>(data);
const int blocked = static_cast<int>(std::get<1>(data));
const string reason = std::get<2>(data);
if (property("edit").toBool())
{
_parent->remove();
}
Dialogdata data = get_data();

if (user.empty())
if (data.user.empty())
{
return;
}
database::add_block(user, blocked, reason);
_parent->add_row(QString::fromStdString(user),
blocked,
QString::fromStdString(reason));
for (const string &receipt : std::get<3>(data))
database::add_block(data.user, data.blocked, data.reason);
_parent->add_row(QString::fromStdString(data.user),
data.blocked,
QString::fromStdString(data.reason));
for (const string &receipt : data.receipts)
{
database::add_receipt(user, receipt);
database::add_receipt(data.user, receipt);
}

_parent->statusBar()->showMessage(tr("Added %1 to database.")
.arg(QString::fromStdString(user)));
.arg(QString::fromStdString(data.user)));

delete this;
}

+ 14
- 8
src/interface_qt.hpp View File

@@ -18,8 +18,6 @@
#define INTERFACE_QT_HPP

#include <string>
#include <tuple>
#include <list>
#include <QMainWindow>
#include <QStandardItemModel>
#include <QDialog>
@@ -27,10 +25,14 @@
#include "ui_whyblocked_add.h"

using std::string;
using dialogdata = std::tuple<const string,
const bool,
const string,
const std::vector<string>>;

struct Dialogdata
{
string user;
bool blocked;
string reason;
std::vector<string> receipts;
};

class MainWindow : public QMainWindow, private Ui::MainWindow
{
@@ -40,6 +42,9 @@ public:
explicit MainWindow(QMainWindow *parent = nullptr);
void add_row(const QString &user, const int &blocked, const QString &reason);

public slots:
void remove();

private:
const string urls_to_hyperlinks(const string &text);

@@ -47,7 +52,7 @@ private:

private slots:
void add();
void remove();
void edit();
void about();
void show_details(QModelIndex index);
void populate_tableview();
@@ -60,9 +65,10 @@ class DialogAdd : public QDialog, private Ui::DialogAdd

public:
explicit DialogAdd(QMainWindow *parent = nullptr);
const void set_data(const Dialogdata &data);

private:
const dialogdata get_data();
const Dialogdata get_data() const;

MainWindow *_parent;


+ 33
- 0
src/whyblocked.ui View File

@@ -97,6 +97,7 @@
<bool>false</bool>
</attribute>
<addaction name="action_add"/>
<addaction name="action_edit"/>
<addaction name="action_remove"/>
<addaction name="action_reload"/>
<addaction name="action_about"/>
@@ -116,6 +117,7 @@
<string>&amp;Database</string>
</property>
<addaction name="action_add"/>
<addaction name="action_edit"/>
<addaction name="action_remove"/>
<addaction name="action_reload"/>
<addaction name="action_quit"/>
@@ -201,6 +203,20 @@
<string>Ctrl+Q</string>
</property>
</action>
<action name="action_edit">
<property name="icon">
<iconset theme="edit-redo"/>
</property>
<property name="text">
<string>&amp;Edit</string>
</property>
<property name="toolTip">
<string>Edit entry</string>
</property>
<property name="shortcut">
<string>Ctrl+E</string>
</property>
</action>
</widget>
<resources/>
<connections>
@@ -316,6 +332,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>action_edit</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>edit()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>299</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>add()</slot>
@@ -323,5 +355,6 @@
<slot>populate_tableview()</slot>
<slot>about()</slot>
<slot>show_details(QModelIndex)</slot>
<slot>edit()</slot>
</slots>
</ui>

Loading…
Cancel
Save