Merge branch 'feature/biddingRoundControl' into develop
This commit is contained in:
@ -36,6 +36,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
|||||||
views/itemdetailmapper.h views/itemdetailmapper.cpp
|
views/itemdetailmapper.h views/itemdetailmapper.cpp
|
||||||
widgets/comboboxdelegate.h widgets/comboboxdelegate.cpp
|
widgets/comboboxdelegate.h widgets/comboboxdelegate.cpp
|
||||||
widgets/spinboxdelegate.h widgets/spinboxdelegate.cpp
|
widgets/spinboxdelegate.h widgets/spinboxdelegate.cpp
|
||||||
|
widgets/biddingroundcontrol.h widgets/biddingroundcontrol.cpp
|
||||||
)
|
)
|
||||||
# Define target properties for Android with Qt 6 as:
|
# Define target properties for Android with Qt 6 as:
|
||||||
# set_property(TARGET ${TARGET_APP} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
# set_property(TARGET ${TARGET_APP} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
#include "model/generalsortfiltermodel.h"
|
#include "model/generalsortfiltermodel.h"
|
||||||
#include "model/metadata.h"
|
#include "model/metadata.h"
|
||||||
#include "model/tablemodel.h"
|
#include "model/tablemodel.h"
|
||||||
|
#include "widgets/biddingroundcontrol.h"
|
||||||
#include "widgets/comboboxdelegate.h"
|
#include "widgets/comboboxdelegate.h"
|
||||||
#include "widgets/spinboxdelegate.h"
|
#include "widgets/spinboxdelegate.h"
|
||||||
|
|
||||||
@ -70,6 +71,8 @@ MainWindow::MainWindow(QWidget* parent)
|
|||||||
|
|
||||||
onSelectionChanged(QItemSelection(), QItemSelection());
|
onSelectionChanged(QItemSelection(), QItemSelection());
|
||||||
onCurrentChanged(QModelIndex(), QModelIndex());
|
onCurrentChanged(QModelIndex(), QModelIndex());
|
||||||
|
|
||||||
|
setupEventTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() { delete ui; }
|
MainWindow::~MainWindow() { delete ui; }
|
||||||
@ -176,11 +179,6 @@ void MainWindow::on_actionCheck_for_update_triggered() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_pushButton_clicked() {
|
|
||||||
const QString prefix("Backend provided by: ");
|
|
||||||
ui->label->setText(prefix + m_core->toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::openNewItemDialog() {
|
void MainWindow::openNewItemDialog() {
|
||||||
showStatusMessage(tr("Invoked 'Edit|New Item'"));
|
showStatusMessage(tr("Invoked 'Edit|New Item'"));
|
||||||
m_newItemDialog->show();
|
m_newItemDialog->show();
|
||||||
@ -300,24 +298,9 @@ void MainWindow::findItems() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::fetchItems() {
|
void MainWindow::fetchCurrentBiddings() {
|
||||||
showStatusMessage(tr("Invoked 'Server|Fetch items'"));
|
showStatusMessage(tr("Invoked 'Server|Fetch current biddings'"));
|
||||||
emit m_core->fetchItemsFromServer();
|
emit m_core->sendGetRequest(GetBiddingsOfHighestRound);
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::postItems() {
|
|
||||||
showStatusMessage(tr("Invoked 'Server|Post items'"));
|
|
||||||
const QModelIndex currentIndex = ui->tableView->currentIndex();
|
|
||||||
const QByteArray jsonData = m_proxyModel->jsonDataForServer(currentIndex);
|
|
||||||
emit m_core->postItemToServer(jsonData);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::deleteItem() {
|
|
||||||
showStatusMessage(tr("Invoked 'Server|Delete items'"));
|
|
||||||
const QModelIndex currentIndex = ui->tableView->currentIndex();
|
|
||||||
// const QByteArray jsonData = m_proxyModel->jsonDataForServer(currentIndex);
|
|
||||||
const QString currentId = m_proxyModel->getUuid(currentIndex);
|
|
||||||
emit m_core->deleteItemFromServer(currentId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::execSettingsDialog() {
|
void MainWindow::execSettingsDialog() {
|
||||||
@ -522,25 +505,12 @@ void MainWindow::createEditActions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createServerActions() {
|
void MainWindow::createServerActions() {
|
||||||
m_fetchItemsAct = make_unique<QAction>(tr("&Fetch item(s)"), this);
|
m_fetchCurrentBiddingsAct = make_unique<QAction>(tr("&Fetch biddings"), this);
|
||||||
m_fetchItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Down));
|
m_fetchCurrentBiddingsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Down));
|
||||||
m_fetchItemsAct->setStatusTip(tr("Fetches all item on configured server"));
|
m_fetchCurrentBiddingsAct->setStatusTip(tr("Fetches all biddings of the current round"));
|
||||||
connect(m_fetchItemsAct.get(), &QAction::triggered, this, &MainWindow::fetchItems);
|
connect(m_fetchCurrentBiddingsAct.get(), &QAction::triggered, this,
|
||||||
ui->menu_Server->addAction(m_fetchItemsAct.get());
|
&MainWindow::fetchCurrentBiddings);
|
||||||
|
ui->menu_Server->addAction(m_fetchCurrentBiddingsAct.get());
|
||||||
m_postItemsAct = make_unique<QAction>(tr("&Post item(s)"), this);
|
|
||||||
m_postItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Up));
|
|
||||||
// m_postItemsAct->setStatusTip(tr("Posts the selected items on configured server"));
|
|
||||||
m_postItemsAct->setStatusTip(tr("Posts the current item on configured server"));
|
|
||||||
connect(m_postItemsAct.get(), &QAction::triggered, this, &MainWindow::postItems);
|
|
||||||
ui->menu_Server->addAction(m_postItemsAct.get());
|
|
||||||
|
|
||||||
m_deleteItemsAct = make_unique<QAction>(tr("&Delete item"), this);
|
|
||||||
m_deleteItemsAct->setShortcut(QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Backspace));
|
|
||||||
// m_deleteItemsAct->setStatusTip(tr("Deletes the selected items on configured server"));
|
|
||||||
m_deleteItemsAct->setStatusTip(tr("Deletes the current item on configured server"));
|
|
||||||
connect(m_deleteItemsAct.get(), &QAction::triggered, this, &MainWindow::deleteItem);
|
|
||||||
ui->menu_Server->addAction(m_deleteItemsAct.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createToolsActions() {
|
void MainWindow::createToolsActions() {
|
||||||
@ -569,3 +539,20 @@ void MainWindow::createGuiDialogs() {
|
|||||||
m_editItemDialog = make_unique<EditItemDialog>(ui->tableView, this);
|
m_editItemDialog = make_unique<EditItemDialog>(ui->tableView, this);
|
||||||
m_editItemDialog->createContent();
|
m_editItemDialog->createContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupEventTab() {
|
||||||
|
QWidget* containerWidget = new QWidget();
|
||||||
|
QVBoxLayout* containerLayout = new QVBoxLayout(containerWidget);
|
||||||
|
m_biddingRoundControl = make_unique<BiddingRoundControl>();
|
||||||
|
containerLayout->addWidget(m_biddingRoundControl.get());
|
||||||
|
|
||||||
|
/// requests
|
||||||
|
connect(m_biddingRoundControl.get(), &BiddingRoundControl::sendGetRequest, m_core.get(),
|
||||||
|
&GenericCore::sendGetRequest);
|
||||||
|
|
||||||
|
/// responses
|
||||||
|
connect(m_core.get(), &GenericCore::currentBiddingRoundChanged, m_biddingRoundControl.get(),
|
||||||
|
&BiddingRoundControl::onCurrentBiddingRoundChanged);
|
||||||
|
|
||||||
|
ui->tabWidget->insertTab(0, containerWidget, "Event (&1)");
|
||||||
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ class TableModel;
|
|||||||
class GeneralSortFilterModel;
|
class GeneralSortFilterModel;
|
||||||
class NewItemDialog;
|
class NewItemDialog;
|
||||||
class EditItemDialog;
|
class EditItemDialog;
|
||||||
|
class BiddingRoundControl;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -44,8 +45,6 @@ class MainWindow : public QMainWindow {
|
|||||||
void onAboutClicked();
|
void onAboutClicked();
|
||||||
void on_actionCheck_for_update_triggered();
|
void on_actionCheck_for_update_triggered();
|
||||||
|
|
||||||
void on_pushButton_clicked();
|
|
||||||
|
|
||||||
/// slots for menu actions
|
/// slots for menu actions
|
||||||
void openNewItemDialog();
|
void openNewItemDialog();
|
||||||
void openEditItemDialog();
|
void openEditItemDialog();
|
||||||
@ -64,9 +63,7 @@ class MainWindow : public QMainWindow {
|
|||||||
void findItems();
|
void findItems();
|
||||||
|
|
||||||
/// 'Server' slots
|
/// 'Server' slots
|
||||||
void fetchItems();
|
void fetchCurrentBiddings();
|
||||||
void postItems();
|
|
||||||
void deleteItem();
|
|
||||||
|
|
||||||
/// 'Tools' slots
|
/// 'Tools' slots
|
||||||
void execSettingsDialog();
|
void execSettingsDialog();
|
||||||
@ -78,7 +75,7 @@ class MainWindow : public QMainWindow {
|
|||||||
shared_ptr<GeneralSortFilterModel> m_proxyModel;
|
shared_ptr<GeneralSortFilterModel> m_proxyModel;
|
||||||
QUndoStack* m_modelUndoStack;
|
QUndoStack* m_modelUndoStack;
|
||||||
unique_ptr<QUndoView> m_modelUndoView;
|
unique_ptr<QUndoView> m_modelUndoView;
|
||||||
|
unique_ptr<BiddingRoundControl> m_biddingRoundControl;
|
||||||
/// File actions
|
/// File actions
|
||||||
unique_ptr<QAction> m_newFileAct;
|
unique_ptr<QAction> m_newFileAct;
|
||||||
unique_ptr<QAction> m_openAct;
|
unique_ptr<QAction> m_openAct;
|
||||||
@ -98,9 +95,7 @@ class MainWindow : public QMainWindow {
|
|||||||
unique_ptr<QAction> m_deleteItemAct;
|
unique_ptr<QAction> m_deleteItemAct;
|
||||||
unique_ptr<QAction> m_findItemAct;
|
unique_ptr<QAction> m_findItemAct;
|
||||||
/// Server actions
|
/// Server actions
|
||||||
unique_ptr<QAction> m_fetchItemsAct;
|
unique_ptr<QAction> m_fetchCurrentBiddingsAct;
|
||||||
unique_ptr<QAction> m_postItemsAct;
|
|
||||||
unique_ptr<QAction> m_deleteItemsAct;
|
|
||||||
|
|
||||||
/// View actions
|
/// View actions
|
||||||
unique_ptr<QAction> m_showModelUndoViewAct;
|
unique_ptr<QAction> m_showModelUndoViewAct;
|
||||||
@ -119,5 +114,7 @@ class MainWindow : public QMainWindow {
|
|||||||
void createToolsActions();
|
void createToolsActions();
|
||||||
void createHelpMenu();
|
void createHelpMenu();
|
||||||
void createGuiDialogs();
|
void createGuiDialogs();
|
||||||
|
|
||||||
|
void setupEventTab();
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@ -14,22 +14,22 @@
|
|||||||
<string>GenericQtClient</string>
|
<string>GenericQtClient</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item>
|
<item row="0" column="0">
|
||||||
<widget class="QTableView" name="tableView"/>
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
</item>
|
<property name="currentIndex">
|
||||||
<item>
|
<number>0</number>
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Push the button!</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pushButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Button</string>
|
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QWidget" name="tab_user">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Mitglieder (&2)</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTableView" name="tableView"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
67
UIs/BeetRoundWidgets/widgets/biddingroundcontrol.cpp
Normal file
67
UIs/BeetRoundWidgets/widgets/biddingroundcontrol.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include "biddingroundcontrol.h"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
BiddingRoundControl::BiddingRoundControl(QWidget* parent)
|
||||||
|
: QWidget{parent} {
|
||||||
|
m_layout = new QHBoxLayout(this);
|
||||||
|
m_title = new QLabel("Bidding round control:");
|
||||||
|
m_status = new QLabel("(No round started yet.)");
|
||||||
|
|
||||||
|
m_newRoundButton = new QPushButton("Start new round");
|
||||||
|
m_restartRoundButton = new QPushButton("Restart last round");
|
||||||
|
m_stopRoundButton = new QPushButton("Stop round");
|
||||||
|
m_refreshRoundButton = new QPushButton("Refresh");
|
||||||
|
|
||||||
|
m_newRoundButton->setEnabled(false);
|
||||||
|
m_restartRoundButton->setEnabled(false);
|
||||||
|
m_stopRoundButton->setEnabled(false);
|
||||||
|
|
||||||
|
m_layout->addWidget(m_title);
|
||||||
|
m_layout->addWidget(m_status);
|
||||||
|
m_layout->addWidget(m_newRoundButton);
|
||||||
|
m_layout->addWidget(m_restartRoundButton);
|
||||||
|
m_layout->addWidget(m_stopRoundButton);
|
||||||
|
m_layout->addWidget(m_refreshRoundButton);
|
||||||
|
|
||||||
|
connect(m_newRoundButton, &QPushButton::clicked, this,
|
||||||
|
&BiddingRoundControl::onStartNewRoundTriggered);
|
||||||
|
connect(m_restartRoundButton, &QPushButton::clicked, this,
|
||||||
|
&BiddingRoundControl::onRestartLastRoundTriggered);
|
||||||
|
connect(m_stopRoundButton, &QPushButton::clicked, this,
|
||||||
|
&BiddingRoundControl::onStopCurrentRoundTriggered);
|
||||||
|
connect(m_refreshRoundButton, &QPushButton::clicked, this,
|
||||||
|
&BiddingRoundControl::onRefreshCurrentRoundTriggered);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BiddingRoundControl::onRefreshCurrentRoundTriggered() {
|
||||||
|
emit sendGetRequest(GetCurrentBiddingRound);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BiddingRoundControl::onStartNewRoundTriggered() { emit sendGetRequest(StartNewBiddingRound); }
|
||||||
|
|
||||||
|
void BiddingRoundControl::onRestartLastRoundTriggered() {
|
||||||
|
emit sendGetRequest(RestartLastBiddingRound);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BiddingRoundControl::onStopCurrentRoundTriggered() {
|
||||||
|
emit sendGetRequest(StopCurrentBiddingRound);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BiddingRoundControl::onCurrentBiddingRoundChanged(int roundNumber, bool isActive) {
|
||||||
|
QString text = QString::number(roundNumber);
|
||||||
|
if (isActive) {
|
||||||
|
text.append(" (active)");
|
||||||
|
m_newRoundButton->setEnabled(false);
|
||||||
|
m_restartRoundButton->setEnabled(false);
|
||||||
|
m_stopRoundButton->setEnabled(true);
|
||||||
|
} else {
|
||||||
|
text.append(" (stopped)");
|
||||||
|
m_newRoundButton->setEnabled(true);
|
||||||
|
m_restartRoundButton->setEnabled(roundNumber > 0);
|
||||||
|
m_stopRoundButton->setEnabled(false);
|
||||||
|
}
|
||||||
|
m_status->setText(text);
|
||||||
|
}
|
||||||
39
UIs/BeetRoundWidgets/widgets/biddingroundcontrol.h
Normal file
39
UIs/BeetRoundWidgets/widgets/biddingroundcontrol.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef BIDDINGROUNDCONTROL_H
|
||||||
|
#define BIDDINGROUNDCONTROL_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
#include "model/metadata.h"
|
||||||
|
|
||||||
|
class QPushButton;
|
||||||
|
class QLabel;
|
||||||
|
class QHBoxLayout;
|
||||||
|
class BiddingRoundControl : public QWidget {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit BiddingRoundControl(QWidget* parent = nullptr);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sendGetRequest(GetRequestTypes type, QVariant data = QVariant());
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/// button slots
|
||||||
|
void onRefreshCurrentRoundTriggered();
|
||||||
|
void onStartNewRoundTriggered();
|
||||||
|
void onRestartLastRoundTriggered();
|
||||||
|
void onStopCurrentRoundTriggered();
|
||||||
|
|
||||||
|
/// event slots
|
||||||
|
void onCurrentBiddingRoundChanged(int roundNumber, bool isActive);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHBoxLayout* m_layout = nullptr;
|
||||||
|
QLabel* m_title = nullptr;
|
||||||
|
QLabel* m_status = nullptr;
|
||||||
|
|
||||||
|
QPushButton* m_newRoundButton = nullptr;
|
||||||
|
QPushButton* m_restartRoundButton = nullptr;
|
||||||
|
QPushButton* m_stopRoundButton = nullptr;
|
||||||
|
QPushButton* m_refreshRoundButton = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BIDDINGROUNDCONTROL_H
|
||||||
@ -2,9 +2,10 @@
|
|||||||
#define COMBOBOXDELEGATE_H
|
#define COMBOBOXDELEGATE_H
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
class QStringListModel;
|
class QStringListModel;
|
||||||
|
|
||||||
class ComboboxDelegate : public QStyledItemDelegate {
|
class ComboboxDelegate : public QStyledItemDelegate {
|
||||||
|
// TODO move source code files into subfolder "widgets/delegate"
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ComboboxDelegate(const QStringList items, QObject* parent = nullptr);
|
explicit ComboboxDelegate(const QStringList items, QObject* parent = nullptr);
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
class SpinboxDelegate : public QStyledItemDelegate {
|
class SpinboxDelegate : public QStyledItemDelegate {
|
||||||
|
// TODO move source code files into subfolder "widgets/delegate"
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SpinboxDelegate(QObject* parent = nullptr);
|
explicit SpinboxDelegate(QObject* parent = nullptr);
|
||||||
|
|||||||
@ -23,19 +23,20 @@ add_library(${TARGET_APP} STATIC
|
|||||||
genericcore.h
|
genericcore.h
|
||||||
${TS_FILES}
|
${TS_FILES}
|
||||||
constants.h
|
constants.h
|
||||||
|
structs.h
|
||||||
data/settingshandler.h data/settingshandler.cpp
|
data/settingshandler.h data/settingshandler.cpp
|
||||||
|
data/filehandler.h data/filehandler.cpp
|
||||||
|
formats/jsonparser.h formats/jsonparser.cpp
|
||||||
|
formats/csvparser.h formats/csvparser.cpp
|
||||||
|
model/metadata.h
|
||||||
model/tablemodel.h model/tablemodel.cpp
|
model/tablemodel.h model/tablemodel.cpp
|
||||||
model/modelitem.h model/modelitem.cpp
|
model/modelitem.h model/modelitem.cpp
|
||||||
formats/jsonparser.h formats/jsonparser.cpp
|
model/generalsortfiltermodel.h model/generalsortfiltermodel.cpp
|
||||||
model/commands/insertrowscommand.h model/commands/insertrowscommand.cpp
|
model/commands/insertrowscommand.h model/commands/insertrowscommand.cpp
|
||||||
model/commands/removerowscommand.h model/commands/removerowscommand.cpp
|
model/commands/removerowscommand.h model/commands/removerowscommand.cpp
|
||||||
model/commands/edititemcommand.h model/commands/edititemcommand.cpp
|
model/commands/edititemcommand.h model/commands/edititemcommand.cpp
|
||||||
data/filehandler.h data/filehandler.cpp
|
|
||||||
model/metadata.h
|
|
||||||
formats/csvparser.h formats/csvparser.cpp
|
|
||||||
model/generalsortfiltermodel.h model/generalsortfiltermodel.cpp
|
|
||||||
network/servercommunicator.h network/servercommunicator.cpp
|
|
||||||
network/apiroutes.h
|
network/apiroutes.h
|
||||||
|
network/servercommunicator.h network/servercommunicator.cpp
|
||||||
# 3rd party libraries
|
# 3rd party libraries
|
||||||
../3rdParty/rapidcsv/src/rapidcsv.h
|
../3rdParty/rapidcsv/src/rapidcsv.h
|
||||||
)
|
)
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QtGui/QUndoStack>
|
||||||
|
|
||||||
#include "../../ApplicationConfig.h"
|
#include "../../ApplicationConfig.h"
|
||||||
#include "CoreConfig.h"
|
#include "CoreConfig.h"
|
||||||
@ -19,8 +20,6 @@
|
|||||||
#include "model/tablemodel.h"
|
#include "model/tablemodel.h"
|
||||||
#include "network/servercommunicator.h"
|
#include "network/servercommunicator.h"
|
||||||
|
|
||||||
#include <QtGui/QUndoStack>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
GenericCore::GenericCore() {
|
GenericCore::GenericCore() {
|
||||||
@ -155,36 +154,9 @@ bool GenericCore::isSyncServerSetup() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericCore::onSendItemTriggered(const QByteArray& jsonData) {
|
void GenericCore::onBiddingsChanged(int round, QList<bidding> biddings) {
|
||||||
m_serverCommunicator->postItems(jsonData);
|
qInfo() << "onBiddingsChanged: round:" << round << "- biddings:" << biddings.count();
|
||||||
}
|
// NEXT merge biddings into model
|
||||||
|
|
||||||
void GenericCore::onItemsFetched(const QByteArray jsonData) {
|
|
||||||
emit displayStatusMessage("New items fetched.");
|
|
||||||
// TODO ? check compability of JSON structure beforehand?
|
|
||||||
// NEXT check if item already exists and apply changes (UUID,...) ? ;
|
|
||||||
m_mainModel->appendItems(jsonData);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenericCore::onItemsFetchFailure(const QString errorString) {
|
|
||||||
emit displayStatusMessage(QString("Error: %1").arg(errorString));
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenericCore::onPostRequestSuccessful(const QByteArray responseData) {
|
|
||||||
const QString message = m_mainModel->updateItemsFromJson(responseData);
|
|
||||||
emit displayStatusMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenericCore::onPostRequestFailure(const QString errorString) {
|
|
||||||
emit displayStatusMessage(QString("Error: %1").arg(errorString));
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenericCore::onDeleteRequestSuccessful(const QByteArray responseData) {
|
|
||||||
qWarning() << "TODO: Process success response!!!";
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenericCore::onDeleteRequestFailure(const QString errorString) {
|
|
||||||
qWarning() << "TODO: Process error response!!!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericCore::setupModels() {
|
void GenericCore::setupModels() {
|
||||||
@ -246,27 +218,6 @@ QString GenericCore::getMaintenanceToolFilePath() const {
|
|||||||
|
|
||||||
void GenericCore::setupServerConfiguration() {
|
void GenericCore::setupServerConfiguration() {
|
||||||
m_serverCommunicator = make_unique<ServerCommunicator>(this);
|
m_serverCommunicator = make_unique<ServerCommunicator>(this);
|
||||||
/// request connections
|
|
||||||
connect(this, &GenericCore::fetchItemsFromServer, m_serverCommunicator.get(),
|
|
||||||
&ServerCommunicator::fetchItems);
|
|
||||||
connect(this, &GenericCore::postItemToServer, this, &GenericCore::onSendItemTriggered);
|
|
||||||
connect(this, &GenericCore::deleteItemFromServer, m_serverCommunicator.get(),
|
|
||||||
&ServerCommunicator::deleteItem);
|
|
||||||
|
|
||||||
/// response connections
|
|
||||||
connect(m_serverCommunicator.get(), &ServerCommunicator::itemsFetched, this,
|
|
||||||
&GenericCore::onItemsFetched);
|
|
||||||
connect(m_serverCommunicator.get(), &ServerCommunicator::itemsFetchFailure, this,
|
|
||||||
&GenericCore::onItemsFetchFailure);
|
|
||||||
connect(m_serverCommunicator.get(), &ServerCommunicator::postRequestSuccessful, this,
|
|
||||||
&GenericCore::onPostRequestSuccessful);
|
|
||||||
connect(m_serverCommunicator.get(), &ServerCommunicator::postRequestFailure, this,
|
|
||||||
&GenericCore::onPostRequestFailure);
|
|
||||||
connect(m_serverCommunicator.get(), &ServerCommunicator::deleteRequestSuccessful, this,
|
|
||||||
&GenericCore::onDeleteRequestSuccessful);
|
|
||||||
connect(m_serverCommunicator.get(), &ServerCommunicator::deleteRequestFailure, this,
|
|
||||||
&GenericCore::onDeleteRequestFailure);
|
|
||||||
|
|
||||||
applyServerConfiguration();
|
applyServerConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,10 @@
|
|||||||
#define GENERICCORE_H
|
#define GENERICCORE_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include "model/metadata.h"
|
||||||
|
#include "structs.h"
|
||||||
|
|
||||||
class QUndoStack;
|
class QUndoStack;
|
||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
@ -38,16 +42,18 @@ class GenericCore : public QObject {
|
|||||||
bool isSyncServerSetup() const;
|
bool isSyncServerSetup() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onSendItemTriggered(const QByteArray& jsonData);
|
void onBiddingsChanged(int round, QList<bidding> biddings);
|
||||||
void onItemsFetched(const QByteArray jsonData);
|
|
||||||
void onItemsFetchFailure(const QString errorString);
|
|
||||||
void onPostRequestSuccessful(const QByteArray responseData);
|
|
||||||
void onPostRequestFailure(const QString errorString);
|
|
||||||
void onDeleteRequestSuccessful(const QByteArray responseData);
|
|
||||||
void onDeleteRequestFailure(const QString errorString);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void displayStatusMessage(QString message);
|
void displayStatusMessage(QString message);
|
||||||
|
|
||||||
|
/// *** server communication ***
|
||||||
|
/// request signals
|
||||||
|
void sendGetRequest(GetRequestTypes type, QVariant data = QVariant());
|
||||||
|
/// response signals
|
||||||
|
void currentBiddingRoundChanged(int round, bool isRunning);
|
||||||
|
|
||||||
|
/// deprecated signals
|
||||||
void fetchItemsFromServer();
|
void fetchItemsFromServer();
|
||||||
void postItemToServer(const QByteArray& jsonData);
|
void postItemToServer(const QByteArray& jsonData);
|
||||||
void deleteItemFromServer(const QString& id);
|
void deleteItemFromServer(const QString& id);
|
||||||
|
|||||||
@ -82,6 +82,16 @@ static const QString ITEM_KEY_STRING = "item";
|
|||||||
/// file naming
|
/// file naming
|
||||||
static const QString ITEMS_FILE_NAME = ITEMS_KEY_STRING + ".json";
|
static const QString ITEMS_FILE_NAME = ITEMS_KEY_STRING + ".json";
|
||||||
|
|
||||||
|
/// server communication
|
||||||
|
enum GetRequestTypes {
|
||||||
|
GetCurrentBiddingRound,
|
||||||
|
StartNewBiddingRound,
|
||||||
|
RestartLastBiddingRound,
|
||||||
|
StopCurrentBiddingRound,
|
||||||
|
GetBiddingsOfSpecificRound,
|
||||||
|
GetBiddingsOfHighestRound
|
||||||
|
};
|
||||||
|
|
||||||
/// functions
|
/// functions
|
||||||
static UserRoles GET_ROLE_FOR_COLUMN(const int column) {
|
static UserRoles GET_ROLE_FOR_COLUMN(const int column) {
|
||||||
switch (column) {
|
switch (column) {
|
||||||
|
|||||||
@ -9,4 +9,12 @@ static const QString apiPrefix = "/api/";
|
|||||||
|
|
||||||
static const QString ROUTE_ITEMS = apiPrefix + "items";
|
static const QString ROUTE_ITEMS = apiPrefix + "items";
|
||||||
|
|
||||||
|
static const QString ROUTE_BIDDINGROUNDS = apiPrefix + "bidding_rounds";
|
||||||
|
static const QString ROUTE_CURRENT_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/get_current";
|
||||||
|
static const QString ROUTE_START_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/start_new";
|
||||||
|
static const QString ROUTE_RESTART_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/restart";
|
||||||
|
static const QString ROUTE_STOP_BIDDINGROUND = ROUTE_BIDDINGROUNDS + "/stop";
|
||||||
|
|
||||||
|
static const QString ROUTE_GET_BIDDINGS_OF_SPECIFIC_ROUND = apiPrefix + "biddings_of_round";
|
||||||
|
static const QString ROUTE_GET_BIDDINGS_OF_HIGHEST_ROUND = apiPrefix + "biddings_of_highest_round";
|
||||||
#endif // APIROUTES_H
|
#endif // APIROUTES_H
|
||||||
|
|||||||
@ -1,21 +1,29 @@
|
|||||||
#include "servercommunicator.h"
|
#include "servercommunicator.h"
|
||||||
#include "apiroutes.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QRestAccessManager>
|
||||||
#include <QRestReply>
|
#include <QRestReply>
|
||||||
|
|
||||||
|
#include "../genericcore.h"
|
||||||
|
#include "../structs.h"
|
||||||
|
#include "apiroutes.h"
|
||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
ServerCommunicator::ServerCommunicator(QObject* parent)
|
ServerCommunicator::ServerCommunicator(GenericCore* core)
|
||||||
: QObject{parent} {
|
: m_core(core)
|
||||||
|
, QObject{core} {
|
||||||
m_netManager.setAutoDeleteReplies(true);
|
m_netManager.setAutoDeleteReplies(true);
|
||||||
m_restManager = std::make_shared<QRestAccessManager>(&m_netManager);
|
m_restManager = std::make_shared<QRestAccessManager>(&m_netManager);
|
||||||
m_serviceApi = std::make_shared<QNetworkRequestFactory>();
|
m_serviceApi = std::make_shared<QNetworkRequestFactory>();
|
||||||
|
|
||||||
|
connect(m_core, &GenericCore::sendGetRequest, this,
|
||||||
|
&ServerCommunicator::onSendGetRequestTriggered);
|
||||||
|
connect(this, &ServerCommunicator::biddingsChanged, m_core, &GenericCore::onBiddingsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerCommunicator::sslSupported() {
|
bool ServerCommunicator::sslSupported() const {
|
||||||
#if QT_CONFIG(ssl)
|
#if QT_CONFIG(ssl)
|
||||||
return QSslSocket::supportsSsl();
|
return QSslSocket::supportsSsl();
|
||||||
#else
|
#else
|
||||||
@ -104,3 +112,108 @@ void ServerCommunicator::setServerConfiguration(const QString url,
|
|||||||
m_email = email;
|
m_email = email;
|
||||||
m_password = password;
|
m_password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerCommunicator::onSendGetRequestTriggered(const GetRequestTypes type,
|
||||||
|
QVariant data = QVariant()) {
|
||||||
|
QString path;
|
||||||
|
switch (type) {
|
||||||
|
case GetCurrentBiddingRound:
|
||||||
|
path = ROUTE_CURRENT_BIDDINGROUND;
|
||||||
|
break;
|
||||||
|
case StartNewBiddingRound:
|
||||||
|
path = ROUTE_START_BIDDINGROUND;
|
||||||
|
break;
|
||||||
|
case RestartLastBiddingRound:
|
||||||
|
path = ROUTE_RESTART_BIDDINGROUND;
|
||||||
|
break;
|
||||||
|
case StopCurrentBiddingRound:
|
||||||
|
path = ROUTE_STOP_BIDDINGROUND;
|
||||||
|
break;
|
||||||
|
case GetBiddingsOfSpecificRound:
|
||||||
|
path = ROUTE_GET_BIDDINGS_OF_SPECIFIC_ROUND + "/" + data.toString();
|
||||||
|
break;
|
||||||
|
case GetBiddingsOfHighestRound:
|
||||||
|
path = ROUTE_GET_BIDDINGS_OF_HIGHEST_ROUND;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qWarning() << "No route found for GetRequestType:" << type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO move into default case of switch statement?
|
||||||
|
if (path.isEmpty()) {
|
||||||
|
qDebug() << "Empty path -> Not sending a request.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QNetworkRequest request = m_serviceApi->createRequest(path);
|
||||||
|
|
||||||
|
m_restManager->get(request, this, [this, type](QRestReply& reply) {
|
||||||
|
if (reply.isSuccess()) {
|
||||||
|
qInfo() << "Request successful.";
|
||||||
|
const QJsonDocument doc = reply.readJson().value();
|
||||||
|
onGetReplySuccessful(type, doc);
|
||||||
|
} else {
|
||||||
|
if (reply.hasError()) {
|
||||||
|
const QString errorString = reply.errorString();
|
||||||
|
qWarning() << "Network error:" << errorString;
|
||||||
|
onGetReplyFailure(type, errorString);
|
||||||
|
} else {
|
||||||
|
int statusCode = reply.httpStatus();
|
||||||
|
qWarning() << "Request not successful:" << statusCode;
|
||||||
|
onGetReplyFailure(type, QString("HTTP status code: %1").arg(statusCode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerCommunicator::onGetReplySuccessful(const GetRequestTypes type, const QJsonDocument doc) {
|
||||||
|
switch (type) {
|
||||||
|
case GetCurrentBiddingRound:
|
||||||
|
case StartNewBiddingRound:
|
||||||
|
case RestartLastBiddingRound:
|
||||||
|
case StopCurrentBiddingRound:
|
||||||
|
currentBiddingRoundChangedReply(doc);
|
||||||
|
break;
|
||||||
|
case GetBiddingsOfSpecificRound:
|
||||||
|
case GetBiddingsOfHighestRound:
|
||||||
|
currentBiddingsReply(doc);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qWarning() << "Can't match request type:" << type;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerCommunicator::onGetReplyFailure(const GetRequestTypes type, const QString errorString) {
|
||||||
|
const QString message =
|
||||||
|
QString("Request of type %1 returned: %2").arg(QString::number(type), errorString);
|
||||||
|
m_core->displayStatusMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerCommunicator::currentBiddingRoundChangedReply(const QJsonDocument jsonDoc) {
|
||||||
|
qInfo() << "Current bidding round received.";
|
||||||
|
const QJsonObject rootObject = jsonDoc["data"].toObject();
|
||||||
|
const int roundNumber = rootObject["round_number"].toInt();
|
||||||
|
const bool stopped = rootObject["stopped"].toBool();
|
||||||
|
const bool isActive = !stopped;
|
||||||
|
|
||||||
|
// NOTE ?use ServerCommunicator::currentBiddingRoundChanged signal instead of emiting a signal of
|
||||||
|
// the core directly?
|
||||||
|
emit m_core->currentBiddingRoundChanged(roundNumber, isActive);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerCommunicator::currentBiddingsReply(const QJsonDocument jsonDoc) {
|
||||||
|
qCritical() << "currentBiddingsReply:" << jsonDoc;
|
||||||
|
|
||||||
|
// NEXT extract biddings from jsonDoc
|
||||||
|
const int roundNumber = 0;
|
||||||
|
const bidding dummyBidding{.userId = QUuid(),
|
||||||
|
.biddingRound = 0,
|
||||||
|
.amount = 123,
|
||||||
|
.depotWishOne = "one",
|
||||||
|
.depotWishTwo = "two"};
|
||||||
|
const QList<bidding> biddings{dummyBidding};
|
||||||
|
|
||||||
|
emit biddingsChanged(roundNumber, biddings);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,17 +1,23 @@
|
|||||||
#ifndef SERVERCOMMUNICATOR_H
|
#ifndef SERVERCOMMUNICATOR_H
|
||||||
#define SERVERCOMMUNICATOR_H
|
#define SERVERCOMMUNICATOR_H
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkRequestFactory>
|
#include <QNetworkRequestFactory>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QRestAccessManager>
|
#include <QRestAccessManager>
|
||||||
|
|
||||||
|
#include "../model/metadata.h"
|
||||||
|
|
||||||
|
class bidding;
|
||||||
|
class GenericCore;
|
||||||
|
|
||||||
class ServerCommunicator : public QObject {
|
class ServerCommunicator : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ServerCommunicator(QObject* parent = nullptr);
|
explicit ServerCommunicator(GenericCore* core);
|
||||||
|
|
||||||
bool sslSupported();
|
bool sslSupported() const;
|
||||||
|
|
||||||
QUrl url() const;
|
QUrl url() const;
|
||||||
void setUrl(const QUrl& url);
|
void setUrl(const QUrl& url);
|
||||||
@ -19,6 +25,10 @@ class ServerCommunicator : public QObject {
|
|||||||
void setServerConfiguration(const QString url, const QString email, const QString password);
|
void setServerConfiguration(const QString url, const QString email, const QString password);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void onSendGetRequestTriggered(const GetRequestTypes type, QVariant data);
|
||||||
|
void onGetReplySuccessful(const GetRequestTypes type, const QJsonDocument doc);
|
||||||
|
void onGetReplyFailure(const GetRequestTypes type, const QString errorString);
|
||||||
|
|
||||||
void fetchItems();
|
void fetchItems();
|
||||||
void postItems(const QByteArray& jsonData);
|
void postItems(const QByteArray& jsonData);
|
||||||
void deleteItem(const QString& id);
|
void deleteItem(const QString& id);
|
||||||
@ -33,7 +43,12 @@ class ServerCommunicator : public QObject {
|
|||||||
void deleteRequestSuccessful(const QByteArray responseData);
|
void deleteRequestSuccessful(const QByteArray responseData);
|
||||||
void deleteRequestFailure(const QString errorString);
|
void deleteRequestFailure(const QString errorString);
|
||||||
|
|
||||||
|
void currentBiddingRoundChanged(int round, bool isRunning);
|
||||||
|
void biddingsChanged(int round, QList<bidding> biddings);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
GenericCore* m_core = nullptr;
|
||||||
|
|
||||||
QNetworkAccessManager m_netManager;
|
QNetworkAccessManager m_netManager;
|
||||||
std::shared_ptr<QRestAccessManager> m_restManager;
|
std::shared_ptr<QRestAccessManager> m_restManager;
|
||||||
std::shared_ptr<QNetworkRequestFactory> m_serviceApi;
|
std::shared_ptr<QNetworkRequestFactory> m_serviceApi;
|
||||||
@ -41,6 +56,10 @@ class ServerCommunicator : public QObject {
|
|||||||
QString m_email;
|
QString m_email;
|
||||||
QString m_password;
|
QString m_password;
|
||||||
// QString m_authToken;
|
// QString m_authToken;
|
||||||
|
|
||||||
|
/// reply parser
|
||||||
|
void currentBiddingRoundChangedReply(const QJsonDocument jsonDoc);
|
||||||
|
void currentBiddingsReply(const QJsonDocument jsonDoc);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERVERCOMMUNICATOR_H
|
#endif // SERVERCOMMUNICATOR_H
|
||||||
|
|||||||
14
libs/BeetRoundCore/structs.h
Normal file
14
libs/BeetRoundCore/structs.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef STRUCTS_H
|
||||||
|
#define STRUCTS_H
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
struct bidding {
|
||||||
|
QUuid userId;
|
||||||
|
int biddingRound;
|
||||||
|
int amount;
|
||||||
|
QString depotWishOne;
|
||||||
|
QString depotWishTwo;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STRUCTS_H
|
||||||
Reference in New Issue
Block a user