Benchmark page was added
This commit is contained in:
@@ -27,6 +27,7 @@ set(PROJECT_SOURCES
|
||||
viewmodels/ordersviewmodel.h viewmodels/ordersviewmodel.cpp
|
||||
viewmodels/settingsviewmodel.h viewmodels/settingsviewmodel.cpp
|
||||
viewmodels/restsviewmodel.h viewmodels/restsviewmodel.cpp
|
||||
viewmodels/benchmarkviewmodel.h viewmodels/benchmarkviewmodel.cpp
|
||||
services/beerservice.h services/beerservice.cpp
|
||||
services/settingsservice.h services/settingsservice.cpp
|
||||
services/modelsregister.h services/modelsregister.cpp
|
||||
|
||||
2
main.cpp
2
main.cpp
@@ -14,6 +14,7 @@
|
||||
#include "viewmodels/storesviewmodel.h"
|
||||
#include "viewmodels/restsviewmodel.h"
|
||||
#include "viewmodels/settingsviewmodel.h"
|
||||
#include "viewmodels/benchmarkviewmodel.h"
|
||||
|
||||
#include "services/beerservice.h"
|
||||
#include "services/modelsregister.h"
|
||||
@@ -56,6 +57,7 @@ int main(int argc, char *argv[])
|
||||
qmlRegisterType<StoresViewModel>("ru.ded.beerlog", 1, 0, "StoresViewModel");
|
||||
qmlRegisterType<RestsViewModel>("ru.ded.beerlog", 1, 0, "RestsViewModel");
|
||||
qmlRegisterType<SettingsViewModel>("ru.ded.beerlog", 1, 0, "SettingsViewModel");
|
||||
qmlRegisterType<BenchmarkViewModel>("ru.ded.beerlog", 1, 0, "BenchmarkViewModel");
|
||||
|
||||
engine.load(url);
|
||||
|
||||
|
||||
96
qml/Views/BenchmarkView.qml
Normal file
96
qml/Views/BenchmarkView.qml
Normal file
@@ -0,0 +1,96 @@
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
|
||||
import ru.ded.beerlog 1.0
|
||||
|
||||
Page {
|
||||
|
||||
title: qsTr("Benchmark")
|
||||
|
||||
Column {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 10
|
||||
|
||||
ItemDelegate {
|
||||
width: parent.width
|
||||
|
||||
text: qsTr("Items count")
|
||||
|
||||
TextField {
|
||||
id: itemsCountField
|
||||
|
||||
anchors.right: parent.right
|
||||
|
||||
validator: IntValidator {
|
||||
bottom: 0
|
||||
top: 100000
|
||||
}
|
||||
|
||||
height: parent.height
|
||||
|
||||
inputMethodHints: Qt.ImhPreferNumbers
|
||||
}
|
||||
}
|
||||
|
||||
ItemDelegate {
|
||||
width: parent.width
|
||||
|
||||
text: qsTr("Submit time")
|
||||
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.right: parent.right
|
||||
text: benchmark.submitTime
|
||||
}
|
||||
}
|
||||
|
||||
ItemDelegate {
|
||||
width: parent.width
|
||||
|
||||
text: qsTr("Receive time")
|
||||
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.right: parent.right
|
||||
text: benchmark.receiveTime
|
||||
}
|
||||
}
|
||||
|
||||
ItemDelegate {
|
||||
width: parent.width
|
||||
|
||||
text: qsTr("Remove time")
|
||||
|
||||
Label {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.right: parent.right
|
||||
text: benchmark.removeTime
|
||||
}
|
||||
}
|
||||
|
||||
ItemDelegate {
|
||||
id: startButton
|
||||
|
||||
width: parent.width
|
||||
|
||||
text: qsTr("Start benchmark")
|
||||
enabled: !benchmark.inProgress
|
||||
|
||||
onClicked: benchmark.startBenchmark()
|
||||
|
||||
states: State {
|
||||
when: benchmark.inProgress
|
||||
PropertyChanges {
|
||||
target: startButton
|
||||
text: qsTr("In progress")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BenchmarkViewModel {
|
||||
id: benchmark
|
||||
|
||||
itemsCount: Number(itemsCountField.text)
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,7 @@ ApplicationWindow {
|
||||
"orders": () => { stackView.openPage("Views/OrdersView.qml") },
|
||||
"rests": () => { stackView.openPage("Views/RestsView.qml") },
|
||||
"settings": () => { stackView.openPage("Views/SettingsView.qml") },
|
||||
"benchmark": () => { stackView.openPage("Views/BenchmarkView.qml") },
|
||||
"quit": () => { Qt.quit() }
|
||||
}
|
||||
|
||||
@@ -108,6 +109,10 @@ ApplicationWindow {
|
||||
title: qsTr("Settings")
|
||||
action: "settings"
|
||||
}
|
||||
ListElement {
|
||||
title: qsTr("Benchmark")
|
||||
action: "benchmark"
|
||||
}
|
||||
ListElement {
|
||||
title: qsTr("Quit")
|
||||
action: "quit"
|
||||
|
||||
@@ -7,5 +7,6 @@
|
||||
<file>Views/SettingsView.qml</file>
|
||||
<file>Views/ProductsView.qml</file>
|
||||
<file>Views/RestsView.qml</file>
|
||||
<file>Views/BenchmarkView.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
150
viewmodels/benchmarkviewmodel.cpp
Normal file
150
viewmodels/benchmarkviewmodel.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
#include "benchmarkviewmodel.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QEventLoop>
|
||||
|
||||
#include "models/basemodel.h"
|
||||
|
||||
BenchmarkViewModel::BenchmarkViewModel(QObject *parent) : QObject{parent}
|
||||
{
|
||||
}
|
||||
|
||||
void BenchmarkViewModel::startBenchmark()
|
||||
{
|
||||
setInProgress(true);
|
||||
submitBenchmark();
|
||||
receiveAndDeleteBenchmark();
|
||||
setInProgress(false);
|
||||
}
|
||||
|
||||
int BenchmarkViewModel::itemsCount() const
|
||||
{
|
||||
return m_itemsCount;
|
||||
}
|
||||
|
||||
void BenchmarkViewModel::setItemsCount(int newItemsCount)
|
||||
{
|
||||
if (m_itemsCount == newItemsCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_itemsCount = newItemsCount;
|
||||
emit itemsCountChanged();
|
||||
}
|
||||
|
||||
quint64 BenchmarkViewModel::submitTime() const
|
||||
{
|
||||
return m_submitTime;
|
||||
}
|
||||
|
||||
void BenchmarkViewModel::setSubmitTime(quint64 newSubmitTime)
|
||||
{
|
||||
if (m_submitTime == newSubmitTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_submitTime = newSubmitTime;
|
||||
emit submitTimeChanged();
|
||||
}
|
||||
|
||||
quint64 BenchmarkViewModel::receiveTime() const
|
||||
{
|
||||
return m_receiveTime;
|
||||
}
|
||||
|
||||
void BenchmarkViewModel::setReceiveTime(quint64 newReceiveTime)
|
||||
{
|
||||
if (m_receiveTime == newReceiveTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_receiveTime = newReceiveTime;
|
||||
emit receiveTimeChanged();
|
||||
}
|
||||
|
||||
quint64 BenchmarkViewModel::removeTime() const
|
||||
{
|
||||
return m_removeTime;
|
||||
}
|
||||
|
||||
void BenchmarkViewModel::setRemoveTime(quint64 newRemoveTime)
|
||||
{
|
||||
if (m_removeTime == newRemoveTime) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_removeTime = newRemoveTime;
|
||||
emit removeTimeChanged();
|
||||
}
|
||||
|
||||
void BenchmarkViewModel::submitBenchmark()
|
||||
{
|
||||
BaseModel benchModel("benchmark");
|
||||
|
||||
QEventLoop loop;
|
||||
int callCount = m_itemsCount;
|
||||
connect(&benchModel, &BaseModel::dataChanged, this, [&loop, &callCount] {
|
||||
if (--callCount == 0) {
|
||||
loop.quit();
|
||||
}
|
||||
});
|
||||
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
for (int i = 0; i < m_itemsCount; ++i) {
|
||||
benchModel.submitItem(QVariantMap {{ "name", QString("Item %1").arg(i) }});
|
||||
}
|
||||
|
||||
loop.exec();
|
||||
setSubmitTime(timer.elapsed());
|
||||
}
|
||||
|
||||
void BenchmarkViewModel::receiveAndDeleteBenchmark()
|
||||
{
|
||||
QEventLoop loop;
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
BaseModel benchModel("benchmark");
|
||||
connect(&benchModel, &BaseModel::dataChanged, this, [&loop]() {
|
||||
loop.quit();
|
||||
});
|
||||
|
||||
loop.exec();
|
||||
setReceiveTime(timer.elapsed());
|
||||
|
||||
disconnect(&benchModel, &BaseModel::dataChanged, this, nullptr);
|
||||
|
||||
QStringList itemIdList;
|
||||
for (const QVariant &item : benchModel.items()) {
|
||||
itemIdList << item.toMap().value("id").toString();
|
||||
}
|
||||
int callCount = itemIdList.count();
|
||||
connect(&benchModel, &BaseModel::dataChanged, this, [&loop, &callCount]() {
|
||||
if (--callCount == 0) {
|
||||
loop.quit();
|
||||
}
|
||||
});
|
||||
|
||||
timer.restart();
|
||||
for (const QString &itemId : itemIdList) {
|
||||
benchModel.deleteItem(itemId);
|
||||
}
|
||||
|
||||
loop.exec();
|
||||
setRemoveTime(timer.elapsed());
|
||||
}
|
||||
|
||||
bool BenchmarkViewModel::inProgress() const
|
||||
{
|
||||
return m_inProgress;
|
||||
}
|
||||
|
||||
void BenchmarkViewModel::setInProgress(bool newInProgress)
|
||||
{
|
||||
if (m_inProgress == newInProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_inProgress = newInProgress;
|
||||
emit inProgressChanged();
|
||||
}
|
||||
54
viewmodels/benchmarkviewmodel.h
Normal file
54
viewmodels/benchmarkviewmodel.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef BENCHMARKVIEWMODEL_H
|
||||
#define BENCHMARKVIEWMODEL_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class BenchmarkViewModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int itemsCount READ itemsCount WRITE setItemsCount NOTIFY itemsCountChanged)
|
||||
Q_PROPERTY(quint64 submitTime READ submitTime WRITE setSubmitTime NOTIFY submitTimeChanged)
|
||||
Q_PROPERTY(quint64 receiveTime READ receiveTime WRITE setReceiveTime NOTIFY receiveTimeChanged)
|
||||
Q_PROPERTY(quint64 removeTime READ removeTime WRITE setRemoveTime NOTIFY removeTimeChanged)
|
||||
Q_PROPERTY(bool inProgress READ inProgress WRITE setInProgress NOTIFY inProgressChanged)
|
||||
|
||||
public:
|
||||
explicit BenchmarkViewModel(QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE void startBenchmark();
|
||||
|
||||
int itemsCount() const;
|
||||
void setItemsCount(int newItemsCount);
|
||||
|
||||
quint64 submitTime() const;
|
||||
void setSubmitTime(quint64 newSubmitTime);
|
||||
|
||||
quint64 receiveTime() const;
|
||||
void setReceiveTime(quint64 newReceiveTime);
|
||||
|
||||
quint64 removeTime() const;
|
||||
void setRemoveTime(quint64 newRemoveTime);
|
||||
|
||||
bool inProgress() const;
|
||||
void setInProgress(bool newInProgress);
|
||||
|
||||
signals:
|
||||
void itemsCountChanged();
|
||||
void submitTimeChanged();
|
||||
void receiveTimeChanged();
|
||||
void removeTimeChanged();
|
||||
void inProgressChanged();
|
||||
|
||||
private:
|
||||
void submitBenchmark();
|
||||
void receiveAndDeleteBenchmark();
|
||||
|
||||
int m_itemsCount = 0;
|
||||
quint64 m_submitTime = 0;
|
||||
quint64 m_receiveTime = 0;
|
||||
quint64 m_removeTime = 0;
|
||||
bool m_inProgress = false;
|
||||
};
|
||||
|
||||
#endif // BENCHMARKVIEWMODEL_H
|
||||
Reference in New Issue
Block a user