Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Tools/SqlBrowser/BrowserWnd.cpp
T
berrux-dev 84f8cfb41f Remove unused code from the Release 2 scope modules
Trim mostly-deletion changes (~700 lines) across the modules the Release
2 build compiles: unused telegrams and receiver/handler code in
TrainingAreaBase (telegrams, recv_from_dds_aes/fts, ism/main/pdm/position
handlers), dead members in SqlBrowser and ProjectDataManagement,
unused LtsPluginManager loader paths, LtsSession unit-test, WlsTetra and
DdsView cleanups, plus the stale include_directories removal in
Lts/CMakeLists.txt. Continues the Release 2 source prune (keep only what
the build compiles).

Excluded from this commit by design: the machine-specific .envrc
(MIGRATE_PIPELINE_ROOT path fix stays uncommitted) and the untracked
qt5-before/ reference tree.
2026-11-17 17:28:48 +01:00

226 lines
6.3 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "ui_BrowserWndUi.h"
#include "BrowserWnd.h"
#include "LoginWnd.h"
#include "Query.h"
#include "DataModel.h"
#include "QueryThread.h"
#include <QtCore/QDebug>
#include <QGraphicsDropShadowEffect>
#include <QListWidgetItem>
#include <QtWidgets/QMessageBox>
#include <QtCore/QRegularExpression>
#include <QShortcut>
#include <QtCore/QThread>
BrowserWnd::BrowserWnd()
: QWidget(nullptr)
, m_loginWnd(new LoginWnd(this))
, m_waitWnd(new WaitWnd(this))
, m_ui(new Ui::BrowserWnd)
, m_queryWorker(new QueryWorker())
, m_queryThread(new QThread())
{
//setVersionView();
qRegisterMetaType<LoginData>("LoginData");
if (!test())
exit(1);
new QShortcut(QKeySequence(QStringLiteral("Ctrl+Q")), this, SLOT(close()));
connect(this, &BrowserWnd::signalConnect, m_queryWorker, &QueryWorker::slotConnectIt);
connect(m_queryWorker, &QueryWorker::signalConnectResult, this, &BrowserWnd::slotConnectResult);
connect(this, &BrowserWnd::signalGetTableList, m_queryWorker, &QueryWorker::slotGetTableList);
connect(m_queryWorker, &QueryWorker::signalNewTableList, this, &BrowserWnd::slotNewTableList);
m_queryWorker->moveToThread(m_queryThread);
m_queryThread->start();
}
BrowserWnd::~BrowserWnd()
{
endThread();
delete m_ui;
delete m_waitWnd;
delete m_loginWnd;
}
void BrowserWnd::slotAddNewQuery()
{
addNewQuery();
}
void BrowserWnd::slotConnectResult(const QString &result)
{
if (result.isEmpty()) // connection success!
{
// everything okay, logged in, go!
m_ui->setupUi(this);
// showing Host / DB name in window title
this->setWindowTitle(QStringLiteral("RDE SQL Browser on Database: ") + m_loginWnd->getLoginData().database);
m_ui->splitter->setStretchFactor(0, 0); // not stretch for table list
m_ui->splitter->setStretchFactor(1, 1); // stretch the query widget
this->show();
addNewQuery();
refreshTableList();
connect(m_ui->leFilter, &QLineEdit::textChanged, this, &BrowserWnd::slotFilterTableList);
connect(m_ui->lwTables, &QListWidget::itemDoubleClicked, this, &BrowserWnd::slotFilterTableItemChanged);
connect(m_ui->twQueries, &QTabWidget::tabCloseRequested, this, &BrowserWnd::slotTabCloseRequested);
connect(m_ui->pbNewQuery, &QPushButton::clicked, this, &BrowserWnd::slotAddNewQuery);
connect(m_ui->pushButton, &QPushButton::clicked, qApp, &QApplication::quit);
connect(m_ui->pushButton_2, &QPushButton::clicked, this, &BrowserWnd::slotHeart);
}
else // failed with message
{
QMessageBox::critical(this,
tr("Connection Error"),
tr("Cannot connect to specified server."
"\nError:"
"\n'%1'").arg(result));
}
m_waitWnd->hide();
}
void BrowserWnd::slotFilterTableList(const QString &)
{
refreshTableList();
}
void BrowserWnd::addNewQuery(const QString &tableName) // tableName only set when query from double clicking table list
{
Query *query = new Query(m_queryWorker);
connect(query, &Query::signalShowWait, this, &BrowserWnd::slotShowWait);
connect(query, &Query::signalHideWait, this, &BrowserWnd::slotHideWait);
int tabIndex = -1;
if (tableName.length()) // there is a tablename
{
query->setTable(tableName);
tabIndex = m_ui->twQueries->addTab(query, tableName);
}
else // no tablename
tabIndex = m_ui->twQueries->addTab(query, QStringLiteral("Query %1").arg(m_newQueryCounter++));
m_ui->twQueries->setCurrentIndex(tabIndex);
}
//#warning TODO: reimpl
//void BrowserWnd::slotSelectQueryStatus(int percent)
//{
// m_waitWnd->setStatus(percent);
//}
void BrowserWnd::endThread()
{
if (!m_queryThread)
return;
m_queryWorker->dy();
m_queryThread->quit();
m_queryThread->wait();
delete m_queryThread;
m_queryThread = nullptr;
delete m_queryWorker;
m_queryWorker = nullptr;
}
void BrowserWnd::refreshTableList()
{
m_ui->lwTables->clear();
m_waitWnd->wait(QStringLiteral("Refreshing Table List .."));
emit signalGetTableList();
}
void BrowserWnd::slotNewTableList(QStringList tables)
{
if (!m_ui->leFilter->text().isEmpty()) // filter when there is a filter
{
QRegularExpression regExp(QRegularExpression::wildcardToRegularExpression(m_ui->leFilter->text()), QRegularExpression::CaseInsensitiveOption);
tables = tables.filter(regExp);
}
m_ui->lwTables->addItems(tables);
m_waitWnd->hide();
}
void BrowserWnd::startConnect()
{
//m_loginWnd->setDefaultLoginData(presetManager. defaultLoginData);
if (!m_loginWnd->exec()) // false = user reject
{
QCoreApplication::quit();
return;
}
m_waitWnd->wait(tr("Connecting .."));
emit signalConnect(m_loginWnd->getLoginData());
}
bool BrowserWnd::test()
{
if (QSqlDatabase::drivers().isEmpty() ||
QSqlDatabase::drivers().indexOf(QLatin1String("QSQLITE")) == -1)
{
QMessageBox::critical(this,
tr("Missing Qt PostgreSQL driver"),
tr("There is no QPSQL driver."
"\nDid you install the package 'libQt5Sql5-postgresql'?"));
return false;
}
return true;
}
void BrowserWnd::slotFilterTableItemChanged(QListWidgetItem *item)
{
QString tableName = item->text();
addNewQuery(tableName);
}
void BrowserWnd::slotTabCloseRequested(int index)
{
Query *q = qobject_cast<Query *>(m_ui->twQueries->widget(index));
m_ui->twQueries->removeTab(index);
if (!q)
QMessageBox::critical(this, QStringLiteral("Query Failed"), QStringLiteral("Woops..?!!"));
delete q; // It´s safe to delete nullptr;
}
void BrowserWnd::slotShowWait(const QString &msg)
{
m_waitWnd->wait(msg);
}
void BrowserWnd::slotHideWait()
{
m_waitWnd->hide();
}
void BrowserWnd::slotHeart()
{
QWidget *w = new QWidget;
w->setAttribute(Qt::WA_DeleteOnClose); // delete when closed
QVBoxLayout *b = new QVBoxLayout;
QLabel *l = new QLabel(QStringLiteral("<html><body>Geschmiedet mit %1 , ohne Kostenträger, für das Team.<br>Diese Software wurde in meiner Freizeit entwickelt, bitte habt Verständnis für Bugs und Geduld für Fixes. Danke! - Euer Mike Wille, SLSE 2016, 17</body></html>").arg(QChar(0x2764)));
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect;
shadow->setOffset(0, 0);
shadow->setBlurRadius(22);
shadow->setColor(QColor("blue"));
l->setGraphicsEffect(shadow);
b->addWidget(l);
w->setLayout(b);
w->show();
}