initial port for Cevo game in C++ (libs)
This commit is contained in:
commit
8436242032
375 files changed
+46282
No files matched your search
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/ApplicationInfo.h"
|
||||
#include "Cevo/FormBase.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class FormAbout;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
// Equivalent of FormAbout.pas's TFormAbout.
|
||||
class FormAbout : public FormBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FormAbout(QWidget *parent = nullptr);
|
||||
~FormAbout() override;
|
||||
|
||||
const ApplicationInfo *applicationInfo() const { return m_applicationInfo; }
|
||||
void setApplicationInfo(const ApplicationInfo *value) { m_applicationInfo = value; }
|
||||
|
||||
void updateInterface();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void onHomePageClicked();
|
||||
|
||||
private:
|
||||
Ui::FormAbout *ui;
|
||||
const ApplicationInfo *m_applicationInfo = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/FormBase.h"
|
||||
#include "Cevo/Item.h"
|
||||
|
||||
#include <QVector>
|
||||
|
||||
class QLabel;
|
||||
class QWidget;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class FormItem;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
// Equivalent of FormItem.pas's TFormItem: builds one label+control pair per
|
||||
// ItemField on the fly, based on each field's DataType.
|
||||
class FormItem : public FormBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FormItem(QWidget *parent = nullptr);
|
||||
~FormItem() override;
|
||||
|
||||
Item *item() const { return m_item; }
|
||||
void setItem(Item *value);
|
||||
|
||||
void updateInterface();
|
||||
|
||||
private slots:
|
||||
void onOkClicked();
|
||||
void onControlChanged();
|
||||
|
||||
private:
|
||||
void initControls();
|
||||
void loadData(Item *item);
|
||||
void saveData(Item *item);
|
||||
|
||||
Ui::FormItem *ui;
|
||||
Item *m_item = nullptr;
|
||||
QVector<QWidget *> m_dataControls;
|
||||
QVector<QLabel *> m_dataLabels;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,163 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/FormBase.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QElapsedTimer>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class QCloseEvent;
|
||||
class QTimer;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class FormJobProgress;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
class Job;
|
||||
class FormJobProgress;
|
||||
|
||||
// Equivalent of JobProgressView.pas's TProgress. Safe to update from the
|
||||
// job's worker thread: setters only touch this object's own data (never
|
||||
// read back from another thread) and emit `changed()`, which Qt delivers
|
||||
// as a queued call to FormJobProgress's slot since that object lives on
|
||||
// the main thread - no mutex needed, unlike the original's TCriticalSection.
|
||||
// Push-based: unlike the original (where only SetValue invoked OnChange,
|
||||
// and SetMax/SetText only ever reached the UI via the 100ms poll timer),
|
||||
// all three setters emit `changed()` here for immediate, lag-free updates.
|
||||
class JobProgress : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QObject::QObject;
|
||||
|
||||
int value() const { return m_value; }
|
||||
int max() const { return m_max; }
|
||||
QString text() const { return m_text; }
|
||||
|
||||
void setMax(int value);
|
||||
void setText(const QString &text);
|
||||
void setValue(int value);
|
||||
void increment();
|
||||
void reset();
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
private:
|
||||
int m_value = 0;
|
||||
int m_max = 100;
|
||||
QString m_text;
|
||||
};
|
||||
|
||||
// Equivalent of JobProgressView.pas's TJob.
|
||||
class Job {
|
||||
public:
|
||||
explicit Job(FormJobProgress *owner);
|
||||
|
||||
QString title;
|
||||
std::function<void(Job &)> method;
|
||||
bool noThreaded = false;
|
||||
// Kept for interface fidelity with TJob.WaitFor, which the original
|
||||
// itself never reads anywhere either (write-only field upstream too).
|
||||
bool waitFor = false;
|
||||
bool finished = false;
|
||||
QString resultString;
|
||||
QDateTime startTime;
|
||||
QDateTime endTime;
|
||||
JobProgress progress;
|
||||
|
||||
// Appends to the owning dialog's log, marshalling to the main thread
|
||||
// if called from the job's worker thread (equivalent of TJob.AddLogItem).
|
||||
void addLogItem(const QString &text);
|
||||
|
||||
bool isTerminateRequested() const { return m_terminateRequested; }
|
||||
void requestTerminate() { m_terminateRequested = true; }
|
||||
|
||||
private:
|
||||
FormJobProgress *m_owner;
|
||||
bool m_terminateRequested = false;
|
||||
};
|
||||
|
||||
// Equivalent of JobProgressView.pas's TFormJobProgressView + TJobProgressView
|
||||
// merged into one dialog (Qt's QDialog already is the "component that owns
|
||||
// the form" the original split across two classes for Lazarus-IDE-palette
|
||||
// reasons - RegisterComponents('Common', [TJobProgressView]) has no Qt
|
||||
// equivalent). NOT ported: the OwnerDraw/OnOwnerDraw hook (lets a caller
|
||||
// suppress the dialog and draw its own progress UI instead) - grepping the
|
||||
// whole perso/cevo tree found no actual consumer of TJobProgressView at
|
||||
// all, so this is dead infrastructure; drop it and simply don't call
|
||||
// start() if you want fully custom progress UI.
|
||||
class FormJobProgress : public FormBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FormJobProgress(QWidget *parent = nullptr);
|
||||
~FormJobProgress() override;
|
||||
|
||||
bool autoClose() const { return m_autoClose; }
|
||||
void setAutoClose(bool value) { m_autoClose = value; }
|
||||
|
||||
// Delay, in ms, before the dialog actually shows itself once start() is
|
||||
// running (0 shows immediately). Equivalent of TJobProgressView.ShowDelay.
|
||||
int showDelay() const { return m_showDelay; }
|
||||
void setShowDelay(int value) { m_showDelay = value; }
|
||||
|
||||
// Equivalent of TJobProgressView.AddJob. Ownership stays with this
|
||||
// dialog; the returned pointer stays valid until clear() or destruction.
|
||||
Job *addJob(const QString &title, std::function<void(Job &)> method, bool noThreaded = false,
|
||||
bool waitFor = false);
|
||||
|
||||
void clear();
|
||||
|
||||
// Equivalent of TJobProgressView.Start: runs every added job in order,
|
||||
// blocking the caller until all jobs finish or stop() is called, while
|
||||
// pumping the Qt event loop (via Threading.h's runInThread()) so the
|
||||
// dialog stays responsive - matches the original's
|
||||
// Application.ProcessMessages-pumping wait loop.
|
||||
void start();
|
||||
|
||||
// Equivalent of TJobProgressView.Stop / the Terminate property setter:
|
||||
// cooperatively asks the current (and all pending) jobs to stop.
|
||||
void stop();
|
||||
bool isTerminateRequested() const { return m_terminateRequested; }
|
||||
|
||||
signals:
|
||||
void jobFinished(Job *job);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void onTimerUpdate();
|
||||
|
||||
private:
|
||||
void reloadJobList();
|
||||
void updateProgress();
|
||||
void updateHeight();
|
||||
void appendLog(const QString &text);
|
||||
|
||||
friend class Job;
|
||||
|
||||
Ui::FormJobProgress *ui;
|
||||
QTimer *m_updateTimer;
|
||||
std::vector<std::unique_ptr<Job>> m_jobs;
|
||||
int m_currentJobIndex = -1;
|
||||
Job *m_currentJob = nullptr;
|
||||
bool m_finished = false;
|
||||
bool m_autoClose = true;
|
||||
int m_showDelay = 0;
|
||||
bool m_terminateRequested = false;
|
||||
QDateTime m_totalStartTime;
|
||||
QElapsedTimer m_partElapsed;
|
||||
QStringList m_log;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/FormBase.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QPointer>
|
||||
|
||||
class QObject;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class FormKeyShortcuts;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
// Equivalent of FormKeyShortcuts.pas's TFormKeyShortcuts: lists every
|
||||
// QAction found (recursively) under a set of source objects, with its
|
||||
// shortcut, double-click/Enter to trigger it. Column sorting uses
|
||||
// QTreeWidget's native header-click sorting - no ListViewSort port needed.
|
||||
class FormKeyShortcuts : public FormBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FormKeyShortcuts(QWidget *parent = nullptr);
|
||||
~FormKeyShortcuts() override;
|
||||
|
||||
// Equivalent of LoadFromComponent: objects whose QAction children (found
|
||||
// recursively) should be listed.
|
||||
void setSourceObjects(const QList<QObject *> &objects) { m_sourceObjects = objects; }
|
||||
void setMainWindow(QWidget *window) { m_mainWindow = window; }
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void onExecuteSelected();
|
||||
|
||||
private:
|
||||
void reload();
|
||||
|
||||
Ui::FormKeyShortcuts *ui;
|
||||
QList<QObject *> m_sourceObjects;
|
||||
QPointer<QWidget> m_mainWindow;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/FormBase.h"
|
||||
#include "Cevo/Item.h"
|
||||
|
||||
class QAction;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class FormList;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
// Equivalent of FormList.pas's TFormList: add/modify/remove/clone items of
|
||||
// a BaseItemList, with columns derived from the list's ItemFields.
|
||||
class FormList : public FormBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FormList(QWidget *parent = nullptr);
|
||||
~FormList() override;
|
||||
|
||||
BaseItemList *list() const { return m_list; }
|
||||
void setList(BaseItemList *value);
|
||||
|
||||
int minItemCount = 0;
|
||||
int maxItemCount = -1; // -1: unlimited
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void onAdd();
|
||||
void onModify();
|
||||
void onRemove();
|
||||
void onClone();
|
||||
void onSelectAll();
|
||||
void onSelectionChanged();
|
||||
|
||||
private:
|
||||
void updateColumns();
|
||||
void updateList();
|
||||
void updateInterface();
|
||||
|
||||
Ui::FormList *ui;
|
||||
BaseItemList *m_list = nullptr;
|
||||
QAction *m_actionAdd = nullptr;
|
||||
QAction *m_actionModify = nullptr;
|
||||
QAction *m_actionRemove = nullptr;
|
||||
QAction *m_actionClone = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/FormBase.h"
|
||||
#include "Cevo/TestCase.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class FormTest;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
// Equivalent of FormTest.pas's TFormTest.
|
||||
class FormTest : public FormBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FormTest(QWidget *parent = nullptr);
|
||||
~FormTest() override;
|
||||
|
||||
TestCase *testCase() const { return m_testCase; }
|
||||
void setTestCase(TestCase *value) { m_testCase = value; }
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void onRunClicked();
|
||||
|
||||
private:
|
||||
Ui::FormTest *ui;
|
||||
TestCase *m_testCase = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cevo/FormBase.h"
|
||||
#include "Cevo/TestCase.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class FormTests;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
// Equivalent of FormTests.pas's TFormTests.
|
||||
class FormTests : public FormBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FormTests(QWidget *parent = nullptr);
|
||||
~FormTests() override;
|
||||
|
||||
TestCases *testCases() const { return m_testCases; }
|
||||
void setTestCases(TestCases *value);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void onRunClicked();
|
||||
void onRunSelected();
|
||||
void onShowSelected();
|
||||
void onSelectionChanged();
|
||||
|
||||
private:
|
||||
void reloadList();
|
||||
void updateInterface();
|
||||
|
||||
Ui::FormTests *ui;
|
||||
TestCases *m_testCases = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "Cevo/FormAbout.h"
|
||||
#include "ui_FormAbout.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
FormAbout::FormAbout(QWidget *parent) : FormBase(parent), ui(new Ui::FormAbout)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->buttonHomePage, &QPushButton::clicked, this, &FormAbout::onHomePageClicked);
|
||||
}
|
||||
|
||||
FormAbout::~FormAbout()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FormAbout::showEvent(QShowEvent *event)
|
||||
{
|
||||
FormBase::showEvent(event);
|
||||
if (m_applicationInfo) {
|
||||
ui->labelAppName->setText(m_applicationInfo->appName);
|
||||
ui->labelContent->setText(tr("Version") + ": " + m_applicationInfo->version() + '\n' + tr("Release date") +
|
||||
": " + m_applicationInfo->releaseDate.toString() + '\n' + tr("License") + ": " +
|
||||
m_applicationInfo->license);
|
||||
ui->labelDescription->setText(m_applicationInfo->description);
|
||||
ui->imageLogo->setPixmap(m_applicationInfo->icon);
|
||||
}
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void FormAbout::updateInterface()
|
||||
{
|
||||
ui->buttonHomePage->setEnabled(m_applicationInfo != nullptr);
|
||||
}
|
||||
|
||||
void FormAbout::onHomePageClicked()
|
||||
{
|
||||
QDesktopServices::openUrl(QUrl(m_applicationInfo->homePage));
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FormAbout</class>
|
||||
<widget class="QDialog" name="FormAbout">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>480</width>
|
||||
<height>280</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>About</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="topLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="imageLogo">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>48</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelAppName">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>20</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Title</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelDescription">
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelContent">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttonLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonHomePage">
|
||||
<property name="text">
|
||||
<string>Home page</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="buttonSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonClose">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonClose</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>FormAbout</receiver>
|
||||
<slot>accept()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -0,0 +1,203 @@
|
||||
#include "Cevo/FormItem.h"
|
||||
#include "Cevo/ColorButton.h"
|
||||
#include "ui_FormItem.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QFormLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
FormItem::FormItem(QWidget *parent) : FormBase(parent), ui(new Ui::FormItem)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->buttonOk, &QPushButton::clicked, this, &FormItem::onOkClicked);
|
||||
}
|
||||
|
||||
FormItem::~FormItem()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FormItem::setItem(Item *value)
|
||||
{
|
||||
if (m_item == value)
|
||||
return;
|
||||
m_item = value;
|
||||
if (m_item) {
|
||||
initControls();
|
||||
loadData(m_item);
|
||||
setWindowTitle(m_item->className());
|
||||
} else {
|
||||
qDeleteAll(m_dataControls);
|
||||
qDeleteAll(m_dataLabels);
|
||||
m_dataControls.clear();
|
||||
m_dataLabels.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void FormItem::initControls()
|
||||
{
|
||||
auto *layout = qobject_cast<QFormLayout *>(ui->scrollBoxContents->layout());
|
||||
qDeleteAll(m_dataControls);
|
||||
qDeleteAll(m_dataLabels);
|
||||
m_dataControls.clear();
|
||||
m_dataLabels.clear();
|
||||
|
||||
const ItemFields fields = m_item->getFields();
|
||||
for (const ItemField &field : fields) {
|
||||
auto *label = new QLabel(field.name + ':', ui->scrollBoxContents);
|
||||
QWidget *control = nullptr;
|
||||
|
||||
switch (field.dataType) {
|
||||
case DataType::Integer: {
|
||||
auto *spin = new QSpinBox(ui->scrollBoxContents);
|
||||
spin->setMaximum(std::numeric_limits<int>::max());
|
||||
control = spin;
|
||||
break;
|
||||
}
|
||||
case DataType::String:
|
||||
control = new QLineEdit(ui->scrollBoxContents);
|
||||
break;
|
||||
case DataType::Color:
|
||||
control = new ColorButton(ui->scrollBoxContents);
|
||||
break;
|
||||
case DataType::Enumeration: {
|
||||
auto *combo = new QComboBox(ui->scrollBoxContents);
|
||||
connect(combo, &QComboBox::currentIndexChanged, this, &FormItem::onControlChanged);
|
||||
control = combo;
|
||||
break;
|
||||
}
|
||||
case DataType::Reference:
|
||||
control = new QComboBox(ui->scrollBoxContents);
|
||||
break;
|
||||
case DataType::Boolean:
|
||||
control = new QCheckBox(ui->scrollBoxContents);
|
||||
break;
|
||||
default:
|
||||
throw std::invalid_argument(("Unsupported field value data type " + dataTypeStr(field.dataType)).toStdString());
|
||||
}
|
||||
|
||||
layout->addRow(label, control);
|
||||
m_dataLabels.append(label);
|
||||
m_dataControls.append(control);
|
||||
}
|
||||
}
|
||||
|
||||
void FormItem::loadData(Item *item)
|
||||
{
|
||||
const ItemFields fields = item->getFields();
|
||||
for (int i = 0; i < fields.count(); ++i) {
|
||||
const ItemField &field = fields.at(i);
|
||||
QWidget *control = m_dataControls.at(i);
|
||||
switch (field.dataType) {
|
||||
case DataType::Integer:
|
||||
qobject_cast<QSpinBox *>(control)->setValue(item->getValueInt(field.index));
|
||||
break;
|
||||
case DataType::String:
|
||||
qobject_cast<QLineEdit *>(control)->setText(item->getValueString(field.index));
|
||||
break;
|
||||
case DataType::Color:
|
||||
qobject_cast<ColorButton *>(control)->setColor(item->getValueColor(field.index));
|
||||
break;
|
||||
case DataType::Boolean:
|
||||
qobject_cast<QCheckBox *>(control)->setChecked(item->getValueBool(field.index));
|
||||
break;
|
||||
case DataType::Enumeration: {
|
||||
auto *combo = qobject_cast<QComboBox *>(control);
|
||||
const QSignalBlocker blocker(combo);
|
||||
combo->clear();
|
||||
combo->addItems(field.enumStates);
|
||||
combo->setCurrentIndex(item->getValueEnum(field.index));
|
||||
break;
|
||||
}
|
||||
case DataType::Reference: {
|
||||
auto *combo = qobject_cast<QComboBox *>(control);
|
||||
const QSignalBlocker blocker(combo);
|
||||
combo->clear();
|
||||
BaseItemList *referenceList = item->getReferenceList(field.index);
|
||||
if (referenceList) {
|
||||
for (int j = 0; j < referenceList->count(); ++j) {
|
||||
Item *refItem = referenceList->at(j);
|
||||
combo->addItem(refItem->name, QVariant::fromValue(static_cast<Item *>(refItem)));
|
||||
}
|
||||
}
|
||||
Item *referenceItem = item->getValueReference(field.index);
|
||||
combo->setCurrentIndex(combo->findData(QVariant::fromValue(referenceItem)));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw std::invalid_argument(("Unsupported field value data type " + dataTypeStr(field.dataType)).toStdString());
|
||||
}
|
||||
}
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void FormItem::saveData(Item *item)
|
||||
{
|
||||
const ItemFields fields = item->getFields();
|
||||
for (int i = 0; i < fields.count(); ++i) {
|
||||
const ItemField &field = fields.at(i);
|
||||
QWidget *control = m_dataControls.at(i);
|
||||
switch (field.dataType) {
|
||||
case DataType::Integer:
|
||||
item->setValueInt(field.index, qobject_cast<QSpinBox *>(control)->value());
|
||||
break;
|
||||
case DataType::String:
|
||||
item->setValueString(field.index, qobject_cast<QLineEdit *>(control)->text());
|
||||
break;
|
||||
case DataType::Color:
|
||||
item->setValueColor(field.index, qobject_cast<ColorButton *>(control)->color());
|
||||
break;
|
||||
case DataType::Boolean:
|
||||
item->setValueBool(field.index, qobject_cast<QCheckBox *>(control)->isChecked());
|
||||
break;
|
||||
case DataType::Enumeration:
|
||||
item->setValueEnum(field.index, qobject_cast<QComboBox *>(control)->currentIndex());
|
||||
break;
|
||||
case DataType::Reference: {
|
||||
auto *combo = qobject_cast<QComboBox *>(control);
|
||||
const int index = combo->currentIndex();
|
||||
item->setValueReference(field.index, index >= 0 ? combo->currentData().value<Item *>() : nullptr);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw std::invalid_argument(("Unsupported field value data type " + dataTypeStr(field.dataType)).toStdString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FormItem::updateInterface()
|
||||
{
|
||||
const ItemFields fields = m_item->getFields();
|
||||
for (int i = 0; i < fields.count(); ++i) {
|
||||
const ItemField &field = fields.at(i);
|
||||
bool visible = field.visibleIfIndex <= 0;
|
||||
if (field.visibleIfIndex > 0) {
|
||||
const ItemField &controlField = fields.at(field.visibleIfIndex);
|
||||
if (controlField.dataType == DataType::Enumeration)
|
||||
visible = qobject_cast<QComboBox *>(m_dataControls.at(field.visibleIfIndex))->currentIndex() > 0;
|
||||
}
|
||||
m_dataControls.at(i)->setVisible(visible);
|
||||
m_dataLabels.at(i)->setVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
void FormItem::onControlChanged()
|
||||
{
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void FormItem::onOkClicked()
|
||||
{
|
||||
saveData(m_item);
|
||||
accept();
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FormItem</class>
|
||||
<widget class="QDialog" name="FormItem">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>480</width>
|
||||
<height>380</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Item</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollBox1">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollBoxContents">
|
||||
<layout class="QFormLayout" name="fieldsLayout"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttonLayout">
|
||||
<item>
|
||||
<spacer name="buttonSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonOk">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonCancel">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonCancel</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>FormItem</receiver>
|
||||
<slot>reject()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -0,0 +1,306 @@
|
||||
#include "Cevo/FormJobProgress.h"
|
||||
#include "Cevo/Threading.h"
|
||||
#include "ui_FormJobProgress.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QCoreApplication>
|
||||
#include <QListWidgetItem>
|
||||
#include <QStyle>
|
||||
#include <QTimer>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
namespace {
|
||||
constexpr int UpdateIntervalMs = 100;
|
||||
constexpr int EstimatedTimeShowThreshold = 4;
|
||||
constexpr int EstimatedTimeShowThresholdTotal = 1;
|
||||
|
||||
QString formatDuration(qint64 milliseconds)
|
||||
{
|
||||
if (milliseconds < 0)
|
||||
milliseconds = 0;
|
||||
const qint64 totalSeconds = milliseconds / 1000;
|
||||
return QStringLiteral("%1:%2:%3")
|
||||
.arg(totalSeconds / 3600, 2, 10, QLatin1Char('0'))
|
||||
.arg((totalSeconds % 3600) / 60, 2, 10, QLatin1Char('0'))
|
||||
.arg(totalSeconds % 60, 2, 10, QLatin1Char('0'));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void JobProgress::setMax(int value)
|
||||
{
|
||||
m_max = std::max(value, 1);
|
||||
if (m_value >= m_max)
|
||||
m_value = m_max;
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void JobProgress::setText(const QString &text)
|
||||
{
|
||||
if (m_text == text)
|
||||
return;
|
||||
m_text = text;
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void JobProgress::setValue(int value)
|
||||
{
|
||||
if (value < m_max && value != m_value) {
|
||||
m_value = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
void JobProgress::increment()
|
||||
{
|
||||
setValue(m_value + 1);
|
||||
}
|
||||
|
||||
void JobProgress::reset()
|
||||
{
|
||||
// Matches the original: silent, does not emit changed().
|
||||
m_value = 0;
|
||||
}
|
||||
|
||||
Job::Job(FormJobProgress *owner) : m_owner(owner)
|
||||
{
|
||||
}
|
||||
|
||||
void Job::addLogItem(const QString &text)
|
||||
{
|
||||
synchronizeToMainThread([this, text] { m_owner->appendLog(text); });
|
||||
}
|
||||
|
||||
FormJobProgress::FormJobProgress(QWidget *parent) : FormBase(parent), ui(new Ui::FormJobProgress)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
m_updateTimer = new QTimer(this);
|
||||
connect(m_updateTimer, &QTimer::timeout, this, &FormJobProgress::onTimerUpdate);
|
||||
reloadJobList();
|
||||
}
|
||||
|
||||
FormJobProgress::~FormJobProgress()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
Job *FormJobProgress::addJob(const QString &title, std::function<void(Job &)> method, bool noThreaded,
|
||||
bool waitFor)
|
||||
{
|
||||
auto job = std::make_unique<Job>(this);
|
||||
job->title = title;
|
||||
job->method = std::move(method);
|
||||
job->noThreaded = noThreaded;
|
||||
job->waitFor = waitFor;
|
||||
job->progress.setMax(100);
|
||||
job->progress.reset();
|
||||
Job *raw = job.get();
|
||||
connect(&raw->progress, &JobProgress::changed, this, [this, raw] {
|
||||
if (raw == m_currentJob)
|
||||
updateProgress();
|
||||
});
|
||||
m_jobs.push_back(std::move(job));
|
||||
reloadJobList();
|
||||
return raw;
|
||||
}
|
||||
|
||||
void FormJobProgress::clear()
|
||||
{
|
||||
m_jobs.clear();
|
||||
m_log.clear();
|
||||
m_currentJob = nullptr;
|
||||
m_currentJobIndex = -1;
|
||||
reloadJobList();
|
||||
}
|
||||
|
||||
void FormJobProgress::start()
|
||||
{
|
||||
m_terminateRequested = false;
|
||||
m_finished = false;
|
||||
setWindowTitle(tr("Please wait..."));
|
||||
|
||||
m_log.clear();
|
||||
ui->memoLog->clear();
|
||||
ui->labelText->clear();
|
||||
ui->labelEstimatedTimePart->setVisible(false);
|
||||
ui->labelEstimatedTimeTotal->setVisible(false);
|
||||
|
||||
m_currentJob = nullptr;
|
||||
m_currentJobIndex = -1;
|
||||
|
||||
if (m_showDelay == 0) {
|
||||
m_updateTimer->start(UpdateIntervalMs);
|
||||
onTimerUpdate();
|
||||
} else {
|
||||
m_updateTimer->start(m_showDelay);
|
||||
}
|
||||
|
||||
m_totalStartTime = QDateTime::currentDateTime();
|
||||
ui->progressBarTotal->setValue(0);
|
||||
ui->progressBarTotal->setVisible(false);
|
||||
|
||||
std::size_t i = 0;
|
||||
while (i < m_jobs.size()) {
|
||||
Job *job = m_jobs[i].get();
|
||||
m_currentJobIndex = static_cast<int>(i);
|
||||
m_currentJob = job;
|
||||
job->startTime = QDateTime::currentDateTime();
|
||||
m_partElapsed.start();
|
||||
ui->labelEstimatedTimePart->setText(tr("Estimated time:"));
|
||||
ui->progressBarPart->setValue(0);
|
||||
ui->progressBarPart->setVisible(false);
|
||||
reloadJobList();
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
try {
|
||||
if (job->noThreaded)
|
||||
job->method(*job);
|
||||
else
|
||||
runInThread([job] { job->method(*job); });
|
||||
} catch (const std::exception &e) {
|
||||
// An uncaught exception on a worker QThread would otherwise
|
||||
// terminate the whole process - caught here and treated like
|
||||
// the original's Terminate-and-stop-iterating path (disclosed
|
||||
// safety fix, not just a literal port of the Pascal try/except).
|
||||
job->resultString = QString::fromUtf8(e.what());
|
||||
job->addLogItem(job->resultString);
|
||||
m_terminateRequested = true;
|
||||
}
|
||||
|
||||
ui->progressBarPart->hide();
|
||||
emit jobFinished(job);
|
||||
if (m_terminateRequested)
|
||||
break;
|
||||
job->endTime = QDateTime::currentDateTime();
|
||||
job->finished = true;
|
||||
++i;
|
||||
}
|
||||
|
||||
m_currentJob = nullptr;
|
||||
m_updateTimer->stop();
|
||||
ui->memoLog->setPlainText(m_log.join(QLatin1Char('\n')));
|
||||
if (m_log.isEmpty() && m_autoClose)
|
||||
hide();
|
||||
if (!isVisible())
|
||||
clear();
|
||||
setWindowTitle(tr("Finished"));
|
||||
m_finished = true;
|
||||
m_currentJobIndex = -1;
|
||||
reloadJobList();
|
||||
}
|
||||
|
||||
void FormJobProgress::stop()
|
||||
{
|
||||
m_terminateRequested = true;
|
||||
for (const auto &job : m_jobs)
|
||||
job->requestTerminate();
|
||||
}
|
||||
|
||||
void FormJobProgress::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if (m_finished) {
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
stop();
|
||||
setWindowTitle(tr("Please wait...") + tr("Termination"));
|
||||
}
|
||||
}
|
||||
|
||||
void FormJobProgress::onTimerUpdate()
|
||||
{
|
||||
updateProgress();
|
||||
if (!isVisible()) {
|
||||
m_updateTimer->setInterval(UpdateIntervalMs);
|
||||
show();
|
||||
}
|
||||
}
|
||||
|
||||
void FormJobProgress::reloadJobList()
|
||||
{
|
||||
ui->listViewJobs->clear();
|
||||
for (int i = 0; i < static_cast<int>(m_jobs.size()); ++i) {
|
||||
Job *job = m_jobs[static_cast<std::size_t>(i)].get();
|
||||
auto *item = new QListWidgetItem(job->title, ui->listViewJobs);
|
||||
if (i == m_currentJobIndex)
|
||||
item->setIcon(style()->standardIcon(QStyle::SP_ArrowRight));
|
||||
else if (job->finished)
|
||||
item->setIcon(style()->standardIcon(QStyle::SP_DialogApplyButton));
|
||||
}
|
||||
updateHeight();
|
||||
}
|
||||
|
||||
void FormJobProgress::updateProgress()
|
||||
{
|
||||
if (!m_currentJob)
|
||||
return;
|
||||
Job &job = *m_currentJob;
|
||||
|
||||
ui->progressBarPart->setMaximum(job.progress.max());
|
||||
ui->progressBarPart->setValue(job.progress.value());
|
||||
ui->labelText->setText(job.progress.text());
|
||||
if (job.progress.value() > 0)
|
||||
ui->progressBarPart->setVisible(true);
|
||||
|
||||
qint64 estimatedPartMs = 0;
|
||||
if (job.progress.value() >= EstimatedTimeShowThreshold) {
|
||||
estimatedPartMs = m_partElapsed.elapsed() * (job.progress.max() - job.progress.value()) / job.progress.value();
|
||||
ui->labelEstimatedTimePart->setText(tr("Estimated time: %1").arg(formatDuration(estimatedPartMs)));
|
||||
ui->labelEstimatedTimePart->setVisible(true);
|
||||
}
|
||||
|
||||
const int totalMax = static_cast<int>(m_jobs.size()) * 100;
|
||||
const int totalValue = m_currentJobIndex * 100 +
|
||||
(job.progress.max() > 0 ? (job.progress.value() * 100 / job.progress.max()) : 0);
|
||||
ui->progressBarTotal->setMaximum(totalMax);
|
||||
ui->progressBarTotal->setValue(totalValue);
|
||||
|
||||
if (totalValue >= EstimatedTimeShowThresholdTotal) {
|
||||
const qint64 elapsedTotalMs = m_totalStartTime.msecsTo(QDateTime::currentDateTime());
|
||||
const qint64 remainingMs = estimatedPartMs +
|
||||
(elapsedTotalMs + estimatedPartMs) * ((static_cast<int>(m_jobs.size()) - 1 - m_currentJobIndex) * 100) /
|
||||
std::max(1, (m_currentJobIndex + 1) * 100);
|
||||
if (remainingMs > 0) {
|
||||
ui->labelEstimatedTimeTotal->setText(tr("Total estimated time: %1").arg(formatDuration(remainingMs)));
|
||||
ui->labelEstimatedTimeTotal->setVisible(true);
|
||||
} else {
|
||||
ui->labelEstimatedTimeTotal->setVisible(false);
|
||||
}
|
||||
}
|
||||
updateHeight();
|
||||
}
|
||||
|
||||
void FormJobProgress::updateHeight()
|
||||
{
|
||||
// Unlike the original's manual pixel-math UpdateHeight(), this just
|
||||
// toggles widget visibility and lets Qt's own layout system (QVBoxLayout
|
||||
// skips hidden widgets automatically) + adjustSize() compute the actual
|
||||
// dialog size - a disclosed simplification, not a literal port.
|
||||
const bool hasJobs = !m_jobs.empty();
|
||||
ui->labelOperation->setVisible(hasJobs);
|
||||
ui->listViewJobs->setVisible(hasJobs);
|
||||
|
||||
const bool running = hasJobs && !m_finished;
|
||||
ui->labelEstimatedTimePart->setVisible(running && ui->labelEstimatedTimePart->isVisible());
|
||||
ui->progressBarPart->setVisible(running && ui->progressBarPart->isVisible());
|
||||
|
||||
const bool runningMultiple = running && m_jobs.size() > 1;
|
||||
ui->labelEstimatedTimeTotal->setVisible(runningMultiple && ui->labelEstimatedTimeTotal->isVisible());
|
||||
ui->progressBarTotal->setVisible(runningMultiple);
|
||||
|
||||
ui->labelText->setVisible(!ui->labelText->text().isEmpty());
|
||||
ui->memoLog->setVisible(!m_log.isEmpty());
|
||||
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void FormJobProgress::appendLog(const QString &text)
|
||||
{
|
||||
m_log.append(text);
|
||||
ui->memoLog->appendPlainText(text);
|
||||
updateHeight();
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FormJobProgress</class>
|
||||
<widget class="QDialog" name="FormJobProgress">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>540</width>
|
||||
<height>345</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Please wait...</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelOperation">
|
||||
<property name="text">
|
||||
<string>Operations:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelText">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listViewJobs"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelEstimatedTimePart">
|
||||
<property name="text">
|
||||
<string>Estimated time:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBarPart">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labelEstimatedTimeTotal">
|
||||
<property name="text">
|
||||
<string>Total estimated time:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBarTotal">
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="memoLog">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "Cevo/FormKeyShortcuts.h"
|
||||
#include "ui_FormKeyShortcuts.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
FormKeyShortcuts::FormKeyShortcuts(QWidget *parent) : FormBase(parent), ui(new Ui::FormKeyShortcuts)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->listView1, &QTreeWidget::itemDoubleClicked, this, &FormKeyShortcuts::onExecuteSelected);
|
||||
connect(ui->listView1, &QTreeWidget::customContextMenuRequested, this, [this](const QPoint &pos) {
|
||||
QMenu menu(this);
|
||||
menu.addAction(tr("Execute"), this, &FormKeyShortcuts::onExecuteSelected)
|
||||
->setEnabled(ui->listView1->currentItem() != nullptr);
|
||||
menu.exec(ui->listView1->viewport()->mapToGlobal(pos));
|
||||
});
|
||||
}
|
||||
|
||||
FormKeyShortcuts::~FormKeyShortcuts()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FormKeyShortcuts::showEvent(QShowEvent *event)
|
||||
{
|
||||
FormBase::showEvent(event);
|
||||
reload();
|
||||
}
|
||||
|
||||
void FormKeyShortcuts::reload()
|
||||
{
|
||||
ui->listView1->clear();
|
||||
for (QObject *source : std::as_const(m_sourceObjects)) {
|
||||
const QList<QAction *> actions = source->findChildren<QAction *>(QString(), Qt::FindChildrenRecursively);
|
||||
for (QAction *action : actions) {
|
||||
auto *row = new QTreeWidgetItem(ui->listView1);
|
||||
row->setText(0, action->text().remove('&'));
|
||||
QWidget *owner = qobject_cast<QWidget *>(action->parent());
|
||||
while (owner && owner->objectName().isEmpty() && owner->parentWidget())
|
||||
owner = owner->parentWidget();
|
||||
if (owner == m_mainWindow)
|
||||
row->setText(1, tr("Main window"));
|
||||
else if (owner)
|
||||
row->setText(1, !owner->windowTitle().isEmpty() ? owner->windowTitle() : owner->objectName());
|
||||
else
|
||||
row->setText(1, tr("Global"));
|
||||
row->setText(2, action->shortcut().toString(QKeySequence::NativeText));
|
||||
row->setData(0, Qt::UserRole, QVariant::fromValue(static_cast<void *>(action)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FormKeyShortcuts::onExecuteSelected()
|
||||
{
|
||||
QTreeWidgetItem *selected = ui->listView1->currentItem();
|
||||
if (!selected)
|
||||
return;
|
||||
auto *action = static_cast<QAction *>(selected->data(0, Qt::UserRole).value<void *>());
|
||||
action->trigger();
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FormKeyShortcuts</class>
|
||||
<widget class="QDialog" name="FormKeyShortcuts">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>360</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Key shortcuts</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="listView1">
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Action</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Window</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Shortcut</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttonLayout">
|
||||
<item>
|
||||
<spacer name="buttonSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonClose">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonClose</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>FormKeyShortcuts</receiver>
|
||||
<slot>accept()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -0,0 +1,188 @@
|
||||
#include "Cevo/FormList.h"
|
||||
#include "Cevo/FormItem.h"
|
||||
#include "ui_FormList.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QShortcut>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
FormList::FormList(QWidget *parent) : FormBase(parent), ui(new Ui::FormList)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_actionAdd = ui->toolBar1->addAction(tr("Add"), this, &FormList::onAdd);
|
||||
m_actionAdd->setShortcut(QKeySequence::New);
|
||||
m_actionModify = ui->toolBar1->addAction(tr("Modify"), this, &FormList::onModify);
|
||||
m_actionModify->setShortcut(Qt::Key_Return);
|
||||
m_actionRemove = ui->toolBar1->addAction(tr("Remove"), this, &FormList::onRemove);
|
||||
m_actionRemove->setShortcut(QKeySequence::Delete);
|
||||
m_actionClone = ui->toolBar1->addAction(tr("Clone"), this, &FormList::onClone);
|
||||
auto *selectAll = new QAction(tr("Select all"), this);
|
||||
selectAll->setShortcut(QKeySequence::SelectAll);
|
||||
connect(selectAll, &QAction::triggered, this, &FormList::onSelectAll);
|
||||
addAction(selectAll);
|
||||
for (QAction *action : { m_actionAdd, m_actionModify, m_actionRemove, m_actionClone })
|
||||
addAction(action); // also reachable via shortcut when the toolbar isn't focused
|
||||
|
||||
connect(ui->listView1, &QTreeWidget::itemDoubleClicked, this, &FormList::onModify);
|
||||
connect(ui->listView1, &QTreeWidget::itemSelectionChanged, this, &FormList::onSelectionChanged);
|
||||
connect(ui->listView1, &QTreeWidget::customContextMenuRequested, this, [this](const QPoint &pos) {
|
||||
QMenu menu(this);
|
||||
menu.addActions(ui->toolBar1->actions());
|
||||
menu.exec(ui->listView1->viewport()->mapToGlobal(pos));
|
||||
});
|
||||
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
FormList::~FormList()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FormList::setList(BaseItemList *value)
|
||||
{
|
||||
if (m_list == value)
|
||||
return;
|
||||
m_list = value;
|
||||
updateInterface();
|
||||
updateList();
|
||||
}
|
||||
|
||||
void FormList::showEvent(QShowEvent *event)
|
||||
{
|
||||
FormBase::showEvent(event);
|
||||
updateColumns();
|
||||
updateList();
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void FormList::updateColumns()
|
||||
{
|
||||
if (!m_list) {
|
||||
ui->listView1->setColumnCount(0);
|
||||
return;
|
||||
}
|
||||
const ItemFields fields = m_list->getItemFields();
|
||||
ui->listView1->setColumnCount(fields.count());
|
||||
for (int i = 0; i < fields.count(); ++i)
|
||||
ui->listView1->headerItem()->setText(i, fields.at(i).name);
|
||||
}
|
||||
|
||||
void FormList::updateList()
|
||||
{
|
||||
ui->listView1->clear();
|
||||
if (!m_list)
|
||||
return;
|
||||
const ItemFields fields = m_list->getItemFields();
|
||||
for (int i = 0; i < m_list->count(); ++i) {
|
||||
Item *item = m_list->at(i);
|
||||
auto *row = new QTreeWidgetItem(ui->listView1);
|
||||
for (int j = 0; j < fields.count(); ++j) {
|
||||
const ItemField &field = fields.at(j);
|
||||
if (field.dataType == DataType::Color)
|
||||
row->setBackground(j, item->getValueColor(field.index));
|
||||
else
|
||||
row->setText(j, item->getValueAsText(field.index));
|
||||
}
|
||||
row->setData(0, Qt::UserRole, QVariant::fromValue(item));
|
||||
}
|
||||
}
|
||||
|
||||
void FormList::updateInterface()
|
||||
{
|
||||
const QList<QTreeWidgetItem *> selected = ui->listView1->selectedItems();
|
||||
const int selCount = selected.count();
|
||||
const bool atCapacity = maxItemCount != -1 && m_list && m_list->count() >= maxItemCount;
|
||||
|
||||
m_actionRemove->setEnabled(m_list && !selected.isEmpty() && m_list->count() - selCount >= minItemCount);
|
||||
m_actionModify->setEnabled(m_list && !selected.isEmpty());
|
||||
m_actionAdd->setEnabled(m_list && !atCapacity);
|
||||
m_actionClone->setEnabled(m_list && !atCapacity);
|
||||
}
|
||||
|
||||
void FormList::onAdd()
|
||||
{
|
||||
if (!m_list || (maxItemCount != -1 && m_list->count() >= maxItemCount))
|
||||
return;
|
||||
Item *tempItem = m_list->createItem(m_list->getNextAvailableName(m_list->name()));
|
||||
FormItem dialog(this);
|
||||
dialog.setItem(tempItem);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
m_list->add(tempItem);
|
||||
updateList();
|
||||
updateInterface();
|
||||
} else {
|
||||
delete tempItem;
|
||||
}
|
||||
}
|
||||
|
||||
void FormList::onModify()
|
||||
{
|
||||
QTreeWidgetItem *selected = ui->listView1->currentItem();
|
||||
if (!selected)
|
||||
return;
|
||||
auto *item = static_cast<Item *>(selected->data(0, Qt::UserRole).value<Item *>());
|
||||
Item *tempItem = m_list->createItem();
|
||||
tempItem->assign(*item);
|
||||
FormItem dialog(this);
|
||||
dialog.setItem(tempItem);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
item->assign(*tempItem);
|
||||
updateList();
|
||||
updateInterface();
|
||||
}
|
||||
delete tempItem;
|
||||
}
|
||||
|
||||
void FormList::onClone()
|
||||
{
|
||||
QTreeWidgetItem *selected = ui->listView1->currentItem();
|
||||
if (!selected || (maxItemCount != -1 && m_list->count() >= maxItemCount))
|
||||
return;
|
||||
auto *sourceItem = static_cast<Item *>(selected->data(0, Qt::UserRole).value<Item *>());
|
||||
Item *tempItem = m_list->createItem();
|
||||
tempItem->assign(*sourceItem);
|
||||
tempItem->name = m_list->getNextAvailableName(tempItem->name);
|
||||
FormItem dialog(this);
|
||||
dialog.setItem(tempItem);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
m_list->add(tempItem);
|
||||
updateList();
|
||||
updateInterface();
|
||||
} else {
|
||||
delete tempItem;
|
||||
}
|
||||
}
|
||||
|
||||
void FormList::onRemove()
|
||||
{
|
||||
const QList<QTreeWidgetItem *> selected = ui->listView1->selectedItems();
|
||||
if (selected.isEmpty())
|
||||
return;
|
||||
if (QMessageBox::question(this, tr("Remove items"), tr("Do you want to remove selected items?")) !=
|
||||
QMessageBox::Yes)
|
||||
return;
|
||||
for (QTreeWidgetItem *row : selected) {
|
||||
if (m_list->count() <= minItemCount)
|
||||
break;
|
||||
m_list->remove(row->data(0, Qt::UserRole).value<Item *>());
|
||||
}
|
||||
updateList();
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void FormList::onSelectAll()
|
||||
{
|
||||
ui->listView1->selectAll();
|
||||
}
|
||||
|
||||
void FormList::onSelectionChanged()
|
||||
{
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FormList</class>
|
||||
<widget class="QDialog" name="FormList">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>List</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="listView1">
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolBar" name="toolBar1"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
</ui>
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "Cevo/FormTest.h"
|
||||
#include "ui_FormTest.h"
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
FormTest::FormTest(QWidget *parent) : FormBase(parent), ui(new Ui::FormTest)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->buttonRun, &QPushButton::clicked, this, &FormTest::onRunClicked);
|
||||
// Matches the original .lfm: ButtonClose's OnClick is also wired to the
|
||||
// run handler (so closing re-runs the test first) - kept as-is even
|
||||
// though it looks like it may have been unintentional in the source.
|
||||
connect(ui->buttonClose, &QPushButton::clicked, this, &FormTest::onRunClicked);
|
||||
}
|
||||
|
||||
FormTest::~FormTest()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FormTest::showEvent(QShowEvent *event)
|
||||
{
|
||||
FormBase::showEvent(event);
|
||||
if (m_testCase)
|
||||
ui->memoLog->setPlainText(m_testCase->log);
|
||||
}
|
||||
|
||||
void FormTest::onRunClicked()
|
||||
{
|
||||
if (m_testCase) {
|
||||
m_testCase->run();
|
||||
ui->memoLog->setPlainText(m_testCase->log);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FormTest</class>
|
||||
<widget class="QDialog" name="FormTest">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>420</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Test</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="memoLog">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttonLayout">
|
||||
<item>
|
||||
<spacer name="buttonSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonRun">
|
||||
<property name="text">
|
||||
<string>Run</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonClose">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonClose</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>FormTest</receiver>
|
||||
<slot>accept()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -0,0 +1,134 @@
|
||||
#include "Cevo/FormTests.h"
|
||||
#include "Cevo/FormTest.h"
|
||||
#include "ui_FormTests.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
namespace {
|
||||
TestCase *selectedTestCase(QTreeWidget *tree)
|
||||
{
|
||||
QTreeWidgetItem *item = tree->currentItem();
|
||||
if (!item)
|
||||
return nullptr;
|
||||
return static_cast<TestCase *>(item->data(0, Qt::UserRole).value<void *>());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
FormTests::FormTests(QWidget *parent) : FormBase(parent), ui(new Ui::FormTests)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->buttonRun, &QPushButton::clicked, this, &FormTests::onRunClicked);
|
||||
// Matches the original .lfm's ButtonClose OnClick=ButtonRunClick quirk.
|
||||
connect(ui->buttonClose, &QPushButton::clicked, this, &FormTests::onRunClicked);
|
||||
connect(ui->listViewTestCases, &QTreeWidget::itemSelectionChanged, this, &FormTests::onSelectionChanged);
|
||||
connect(ui->listViewTestCases, &QTreeWidget::itemDoubleClicked, this, &FormTests::onShowSelected);
|
||||
connect(ui->listViewTestCases, &QTreeWidget::customContextMenuRequested, this, [this](const QPoint &pos) {
|
||||
QMenu menu(this);
|
||||
QAction *show = menu.addAction(tr("Show"), this, &FormTests::onShowSelected);
|
||||
QAction *run = menu.addAction(tr("Run"), this, &FormTests::onRunSelected);
|
||||
const bool hasSelection = ui->listViewTestCases->currentItem() != nullptr;
|
||||
show->setEnabled(hasSelection);
|
||||
run->setEnabled(hasSelection);
|
||||
menu.exec(ui->listViewTestCases->viewport()->mapToGlobal(pos));
|
||||
});
|
||||
}
|
||||
|
||||
FormTests::~FormTests()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FormTests::setTestCases(TestCases *value)
|
||||
{
|
||||
if (m_testCases == value)
|
||||
return;
|
||||
m_testCases = value;
|
||||
reloadList();
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void FormTests::showEvent(QShowEvent *event)
|
||||
{
|
||||
FormBase::showEvent(event);
|
||||
reloadList();
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void FormTests::reloadList()
|
||||
{
|
||||
ui->listViewTestCases->clear();
|
||||
if (!m_testCases)
|
||||
return;
|
||||
for (int i = 0; i < m_testCases->count(); ++i) {
|
||||
TestCase *testCase = m_testCases->at(i);
|
||||
auto *item = new QTreeWidgetItem(ui->listViewTestCases);
|
||||
item->setText(0, testCase->name);
|
||||
item->setText(1, testResultText(testCase->testResult));
|
||||
item->setData(0, Qt::UserRole, QVariant::fromValue(static_cast<void *>(testCase)));
|
||||
}
|
||||
}
|
||||
|
||||
void FormTests::updateInterface()
|
||||
{
|
||||
const bool selected = ui->listViewTestCases->currentItem() != nullptr;
|
||||
ui->buttonRun->setEnabled(m_testCases != nullptr);
|
||||
Q_UNUSED(selected);
|
||||
|
||||
int passed = 0, failed = 0;
|
||||
if (m_testCases) {
|
||||
for (int i = 0; i < m_testCases->count(); ++i) {
|
||||
switch (m_testCases->at(i)->testResult) {
|
||||
case TestResult::Passed:
|
||||
++passed;
|
||||
break;
|
||||
case TestResult::Failed:
|
||||
++failed;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ui->labelResult->setText(tr("Passed") + ' ' + QString::number(passed) + ", " + tr("Failed") + ' ' +
|
||||
QString::number(failed));
|
||||
}
|
||||
|
||||
void FormTests::onRunClicked()
|
||||
{
|
||||
if (!m_testCases)
|
||||
return;
|
||||
for (int i = 0; i < m_testCases->count(); ++i)
|
||||
m_testCases->at(i)->run();
|
||||
reloadList();
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void FormTests::onSelectionChanged()
|
||||
{
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void FormTests::onShowSelected()
|
||||
{
|
||||
TestCase *testCase = selectedTestCase(ui->listViewTestCases);
|
||||
if (!testCase)
|
||||
return;
|
||||
FormTest dialog(this);
|
||||
dialog.setTestCase(testCase);
|
||||
dialog.exec();
|
||||
reloadList();
|
||||
}
|
||||
|
||||
void FormTests::onRunSelected()
|
||||
{
|
||||
TestCase *testCase = selectedTestCase(ui->listViewTestCases);
|
||||
if (!testCase)
|
||||
return;
|
||||
testCase->run();
|
||||
reloadList();
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
} // namespace Cevo
|
||||
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FormTests</class>
|
||||
<widget class="QDialog" name="FormTests">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>480</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Tests</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="listViewTestCases">
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Result</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="buttonLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelResult">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="buttonSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonRun">
|
||||
<property name="text">
|
||||
<string>Run</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonClose">
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonClose</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>FormTests</receiver>
|
||||
<slot>accept()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in new issue
Block a user