Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Tools/SqlBrowser/BrowserWnd.cpp
T
torsten d5c13033e2 Session 022: Migrate Lts/Tools (72 submodules) to Qt6
- Copied complete Lts/Tools directory from qt5-before to qt6-after
- Updated 32 CMakeLists.txt files (Qt5:: → Qt6::)
- Tools subdirectory already included in parent Lts/CMakeLists.txt
- All 72 tool submodules now present in qt6-migrated-legatus
- Includes: Adler, ArAssets, ConfigX, DBAdministration, DBUpdate,
  DdsView, InfrastructureManagement, and 67 more tools
- C++17 standard (RTI 7.7.0 compatibility maintained)
- Tests deferred until final validation phase

Migration progress:
✅ Lts/Application (68 files)
✅ Lts/DDS (verified Qt6-ready)
✅ Lts/Plugins (60 submodules, verified)
✅ Lts/Projects (5 submodules, verified)
✅ Lts/Proxies (13 submodules, verified)
✅ Lts/Services (47 submodules, verified)
✅ Lts/Tools (72 submodules, copied + CMake updated)
✅ Lts/Viewer (LtsFileDialog, LtsReportDisplay, SituationMap)
🟡 TetraIF (partial)
🟡 Z (partial: nglwidgets, QtSingleApplication, qsql_informix, WMS_Interface)
2026-08-25 14:07:20 +02:00

252 lines
6.2 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 <QMessageBox>
#include <QRegExp>
#include <QShortcut>
#include <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
{
QRegExp regExp(m_ui->leFilter->text(), Qt::CaseInsensitive, QRegExp::Wildcard);
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();
}