234 lines
5.0 KiB
Bash
Executable File
234 lines
5.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
TARGET_DIR="${1:-qt5-before/qt5-legacy-migration-benchmark}"
|
|
mkdir -p "${TARGET_DIR}"
|
|
|
|
cat > "${TARGET_DIR}/CMakeLists.txt" <<'FILE_EOF'
|
|
cmake_minimum_required(VERSION 3.10)
|
|
|
|
project(Qt5LegacyMigrationBenchmark LANGUAGES CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_AUTOMOC ON)
|
|
set(CMAKE_AUTOUIC ON)
|
|
set(CMAKE_AUTORCC ON)
|
|
|
|
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets)
|
|
|
|
add_executable(Qt5LegacyMigrationBenchmark
|
|
main.cpp
|
|
MainWindow.h
|
|
MainWindow.cpp
|
|
MainWindow.ui
|
|
resources.qrc
|
|
)
|
|
|
|
target_link_libraries(Qt5LegacyMigrationBenchmark
|
|
Qt5::Core
|
|
Qt5::Gui
|
|
Qt5::Widgets
|
|
)
|
|
FILE_EOF
|
|
|
|
cat > "${TARGET_DIR}/MainWindow.h" <<'FILE_EOF'
|
|
#pragma once
|
|
|
|
#include <QMainWindow>
|
|
#include <QRegExp>
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
namespace Ui {
|
|
class MainWindow;
|
|
}
|
|
QT_END_NAMESPACE
|
|
|
|
class MainWindow : public QMainWindow
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit MainWindow(QWidget *parent = 0);
|
|
~MainWindow();
|
|
|
|
private slots:
|
|
void onValidateClicked();
|
|
void onScreenInfoClicked();
|
|
|
|
private:
|
|
Ui::MainWindow *ui;
|
|
QRegExp legacyPattern;
|
|
};
|
|
FILE_EOF
|
|
|
|
cat > "${TARGET_DIR}/MainWindow.cpp" <<'FILE_EOF'
|
|
#include "MainWindow.h"
|
|
#include "ui_MainWindow.h"
|
|
|
|
#include <QApplication>
|
|
#include <QDesktopWidget>
|
|
#include <QTextCodec>
|
|
#include <QPixmap>
|
|
#include <QString>
|
|
#include <QRect>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
, legacyPattern("^[A-Za-z]+\\d+$")
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
|
QString title = codec->toUnicode("Qt5 Legacy Migration Benchmark");
|
|
setWindowTitle(title);
|
|
|
|
ui->label->setText(codec->toUnicode("Bitte Text wie Test123 eingeben."));
|
|
ui->iconLabel->setPixmap(QPixmap(":/icons/app.png").scaled(48, 48));
|
|
|
|
connect(ui->validateButton, SIGNAL(clicked()), this, SLOT(onValidateClicked()));
|
|
connect(ui->screenButton, SIGNAL(clicked()), this, SLOT(onScreenInfoClicked()));
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::onValidateClicked()
|
|
{
|
|
QString text = ui->lineEdit->text();
|
|
|
|
if (legacyPattern.exactMatch(text)) {
|
|
ui->resultLabel->setText("Match");
|
|
} else {
|
|
ui->resultLabel->setText("No match");
|
|
}
|
|
}
|
|
|
|
void MainWindow::onScreenInfoClicked()
|
|
{
|
|
QRect screenGeometry = QApplication::desktop()->screenGeometry();
|
|
QString info = QString("Screen: %1x%2")
|
|
.arg(screenGeometry.width())
|
|
.arg(screenGeometry.height());
|
|
|
|
ui->resultLabel->setText(info);
|
|
}
|
|
FILE_EOF
|
|
|
|
cat > "${TARGET_DIR}/main.cpp" <<'FILE_EOF'
|
|
#include <QApplication>
|
|
#include <QTextCodec>
|
|
#include "MainWindow.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
|
|
#endif
|
|
|
|
QApplication a(argc, argv);
|
|
MainWindow w;
|
|
w.show();
|
|
|
|
return a.exec();
|
|
}
|
|
FILE_EOF
|
|
|
|
cat > "${TARGET_DIR}/MainWindow.ui" <<'FILE_EOF'
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<ui version="4.0">
|
|
<class>MainWindow</class>
|
|
<widget class="QMainWindow" name="MainWindow">
|
|
<property name="geometry">
|
|
<rect>
|
|
<x>0</x>
|
|
<y>0</y>
|
|
<width>420</width>
|
|
<height>240</height>
|
|
</rect>
|
|
</property>
|
|
<property name="windowTitle">
|
|
<string>Qt5 Legacy App</string>
|
|
</property>
|
|
<widget class="QWidget" name="centralwidget">
|
|
<layout class="QVBoxLayout" name="verticalLayout">
|
|
<item>
|
|
<widget class="QLabel" name="label">
|
|
<property name="text">
|
|
<string>Initial text</string>
|
|
</property>
|
|
</widget>
|
|
</item>
|
|
<item>
|
|
<widget class="QLineEdit" name="lineEdit">
|
|
<property name="placeholderText">
|
|
<string>Enter value like Test123</string>
|
|
</property>
|
|
</widget>
|
|
</item>
|
|
<item>
|
|
<widget class="QLabel" name="iconLabel">
|
|
<property name="text">
|
|
<string/>
|
|
</property>
|
|
</widget>
|
|
</item>
|
|
<item>
|
|
<layout class="QHBoxLayout" name="buttonLayout">
|
|
<item>
|
|
<widget class="QPushButton" name="validateButton">
|
|
<property name="text">
|
|
<string>Validate</string>
|
|
</property>
|
|
</widget>
|
|
</item>
|
|
<item>
|
|
<widget class="QPushButton" name="screenButton">
|
|
<property name="text">
|
|
<string>Screen Info</string>
|
|
</property>
|
|
</widget>
|
|
</item>
|
|
</layout>
|
|
</item>
|
|
<item>
|
|
<widget class="QLabel" name="resultLabel">
|
|
<property name="text">
|
|
<string>Result appears here</string>
|
|
</property>
|
|
</widget>
|
|
</item>
|
|
</layout>
|
|
</widget>
|
|
</widget>
|
|
<resources/>
|
|
<connections/>
|
|
</ui>
|
|
FILE_EOF
|
|
|
|
cat > "${TARGET_DIR}/resources.qrc" <<'FILE_EOF'
|
|
<RCC>
|
|
<qresource prefix="/icons">
|
|
<file>app.png</file>
|
|
</qresource>
|
|
</RCC>
|
|
FILE_EOF
|
|
|
|
(
|
|
cd "${TARGET_DIR}"
|
|
python3 - <<'FILE_EOF'
|
|
import base64
|
|
png = base64.b64decode(
|
|
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Wn8nKsAAAAASUVORK5CYII="
|
|
)
|
|
with open("app.png", "wb") as f:
|
|
f.write(png)
|
|
FILE_EOF
|
|
)
|
|
|
|
echo "Qt5 legacy benchmark created at: ${TARGET_DIR}"
|