Qt interface: Make it possible to add receipts (fixes #2)

develop 0.7.2
tastytea 2018-10-14 01:26:22 +02:00
parent c9d138e2d7
commit c1e7f22157
No known key found for this signature in database
GPG Key ID: CFC39497F1B26E07
4 changed files with 136 additions and 30 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.6)
project (whyblocked
VERSION 0.7.1
VERSION 0.7.2
LANGUAGES CXX
)

View File

@ -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<const string, const bool, const string> DialogAdd::get_data()
const dialogdata DialogAdd::get_data()
{
std::vector<string> 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[])

View File

@ -19,6 +19,7 @@
#include <string>
#include <tuple>
#include <list>
#include <QMainWindow>
#include <QStandardItemModel>
#include <QDialog>
@ -26,6 +27,10 @@
#include "ui_whyblocked_add.h"
using std::string;
using dialogdata = std::tuple<const string,
const bool,
const string,
const std::vector<string>>;
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<const string, const bool, const string> get_data();
const dialogdata get_data();
private slots:
void add_receipt();
void remove_receipt();
};
#endif // INTERFACE_QT_HPP

View File

@ -6,23 +6,57 @@
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>170</height>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="locale">
<locale language="English" country="UnitedKingdom"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="layout_grid" rowstretch="0,0,0,0,0">
<item row="0" column="0">
<widget class="QLabel" name="label_user">
<layout class="QGridLayout" name="layout_grid" rowstretch="0,0,0,0,0,0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="4" column="0">
<widget class="QLabel" name="label_receipts">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Memory aids, proof</string>
</property>
<property name="text">
<string>User/Instance</string>
<string>Receipts</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="buddy">
<cstring>text_user</cstring>
<cstring>list_receipts</cstring>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="button_receipt_add">
<property name="toolTip">
<string>Add receipt</string>
</property>
<property name="text">
<string>Add</string>
</property>
<property name="icon">
<iconset theme="add"/>
</property>
</widget>
</item>
@ -48,22 +82,6 @@
<item row="0" column="1">
<widget class="QLineEdit" name="text_user"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_blocked">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Blocked/Silenced</string>
</property>
<property name="buddy">
<cstring>radio_blocked</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="radio_silcenced">
<property name="sizePolicy">
@ -90,7 +108,7 @@
<item row="3" column="1">
<widget class="QLineEdit" name="text_reason"/>
</item>
<item row="4" column="1">
<item row="7" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -100,6 +118,52 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_blocked">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Blocked/Silenced</string>
</property>
<property name="buddy">
<cstring>radio_blocked</cstring>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_user">
<property name="text">
<string>User/Instance</string>
</property>
<property name="buddy">
<cstring>text_user</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="button_receipt_remove">
<property name="toolTip">
<string>Remove receipt</string>
</property>
<property name="text">
<string>Remove</string>
</property>
<property name="icon">
<iconset theme="remove"/>
</property>
</widget>
</item>
<item row="4" column="1" rowspan="3">
<widget class="QListWidget" name="list_receipts">
<property name="editTriggers">
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -109,6 +173,9 @@
<tabstop>radio_blocked</tabstop>
<tabstop>radio_silcenced</tabstop>
<tabstop>text_reason</tabstop>
<tabstop>button_receipt_add</tabstop>
<tabstop>button_receipt_remove</tabstop>
<tabstop>list_receipts</tabstop>
</tabstops>
<resources/>
<connections>
@ -120,7 +187,7 @@
<hints>
<hint type="sourcelabel">
<x>227</x>
<y>147</y>
<y>256</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
@ -136,7 +203,7 @@
<hints>
<hint type="sourcelabel">
<x>290</x>
<y>153</y>
<y>262</y>
</hint>
<hint type="destinationlabel">
<x>286</x>