- setResizeMode is no longer available on Qt6
( I think the setSectionResizeMode from Qt5 was reintroduced in Qt6 LTS )
This commit is contained in:
Youssef BEDDAD 2022-05-20 12:32:47 +01:00
parent c622a5a009
commit 747346b413

View File

@ -28,20 +28,18 @@
* GNU General Public License for more details. * * GNU General Public License for more details. *
****************************************************************************/ ****************************************************************************/
#include "lrsqleditdialog.h" #include "lrsqleditdialog.h"
#include "ui_lrsqleditdialog.h"
#include "lrreportengine_p.h" #include "lrreportengine_p.h"
#include "ui_lrsqleditdialog.h"
#include <QDebug> #include <QDebug>
#include <QSqlDatabase>
#include <QMessageBox> #include <QMessageBox>
#include <QSqlDatabase>
namespace LimeReport { namespace LimeReport {
SQLEditDialog::SQLEditDialog(QWidget *parent, LimeReport::DataSourceManager *dataSources, SQLDialogMode dialogMode) : SQLEditDialog::SQLEditDialog(QWidget *parent, LimeReport::DataSourceManager *dataSources, SQLDialogMode dialogMode)
QDialog(parent), : QDialog(parent), ui(new Ui::SQLEditDialog), m_datasources(dataSources), m_dialogMode(dialogMode),
ui(new Ui::SQLEditDialog),m_datasources(dataSources),m_dialogMode(dialogMode), m_oldDatasourceName(""), m_oldDatasourceName(""), m_settings(0), m_ownedSettings(false) {
m_settings(0), m_ownedSettings(false)
{
ui->setupUi(this); ui->setupUi(this);
m_masterDatasources = new QCompleter(this); m_masterDatasources = new QCompleter(this);
ui->leMaster->setCompleter(m_masterDatasources); ui->leMaster->setCompleter(m_masterDatasources);
@ -57,18 +55,14 @@ SQLEditDialog::SQLEditDialog(QWidget *parent, LimeReport::DataSourceManager *dat
ui->fieldsMap->setHorizontalHeaderItem(0, new QTableWidgetItem("master")); ui->fieldsMap->setHorizontalHeaderItem(0, new QTableWidgetItem("master"));
ui->fieldsMap->setHorizontalHeaderItem(1, new QTableWidgetItem("detail")); ui->fieldsMap->setHorizontalHeaderItem(1, new QTableWidgetItem("detail"));
#ifdef HAVE_QT5
ui->fieldsMap->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); ui->fieldsMap->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
#else
ui->fieldsMap->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
#endif
ui->pnlChildDatasource->setVisible(false); ui->pnlChildDatasource->setVisible(false);
connect(ui->pbPreview, SIGNAL(pressed()), this, SLOT(slotPreviewData())); connect(ui->pbPreview, SIGNAL(pressed()), this, SLOT(slotPreviewData()));
connect(ui->pbHidePreview, SIGNAL(pressed()), this, SLOT(slotHidePreview())); connect(ui->pbHidePreview, SIGNAL(pressed()), this, SLOT(slotHidePreview()));
} }
SQLEditDialog::~SQLEditDialog() SQLEditDialog::~SQLEditDialog() {
{
delete ui; delete ui;
if (m_settings && m_ownedSettings) if (m_settings && m_ownedSettings)
delete m_settings; delete m_settings;
@ -85,13 +79,13 @@ QSettings *SQLEditDialog::settings(){
} }
void SQLEditDialog::setSettings(QSettings *value, bool owned) { void SQLEditDialog::setSettings(QSettings *value, bool owned) {
if (m_settings && m_ownedSettings) delete m_settings; if (m_settings && m_ownedSettings)
delete m_settings;
m_settings = value; m_settings = value;
m_ownedSettings = owned; m_ownedSettings = owned;
} }
void SQLEditDialog::accept() void SQLEditDialog::accept() {
{
SQLEditResult result; SQLEditResult result;
if (ui->tabWidget->currentIndex() == 1) { if (ui->tabWidget->currentIndex() == 1) {
@ -99,8 +93,10 @@ void SQLEditDialog::accept()
} else if (!ui->cbSubdetail->isChecked()) { } else if (!ui->cbSubdetail->isChecked()) {
result.resultMode = SQLEditResult::Query; result.resultMode = SQLEditResult::Query;
} else { } else {
if (ui->rbSubQuery->isChecked()) result.resultMode = SQLEditResult::SubQuery; if (ui->rbSubQuery->isChecked())
else result.resultMode=SQLEditResult::SubProxy; result.resultMode = SQLEditResult::SubQuery;
else
result.resultMode = SQLEditResult::SubProxy;
} }
result.connectionName = ConnectionDesc::connectionNameForReport(ui->cbbConnection->currentText()); result.connectionName = ConnectionDesc::connectionNameForReport(ui->cbbConnection->currentText());
@ -118,8 +114,10 @@ void SQLEditDialog::accept()
if (ui->fieldsMap->rowCount() > 0) { if (ui->fieldsMap->rowCount() > 0) {
for (int i = 0; i < ui->fieldsMap->rowCount(); ++i) { for (int i = 0; i < ui->fieldsMap->rowCount(); ++i) {
LimeReport::FieldsCorrelation fieldsCorrelation; LimeReport::FieldsCorrelation fieldsCorrelation;
fieldsCorrelation.master = ui->fieldsMap->item(i,0) ? ui->fieldsMap->item(i,0)->data(Qt::DisplayRole).toString() : ""; fieldsCorrelation.master =
fieldsCorrelation.detail = ui->fieldsMap->item(i,1) ? ui->fieldsMap->item(i,1)->data(Qt::DisplayRole).toString() : ""; ui->fieldsMap->item(i, 0) ? ui->fieldsMap->item(i, 0)->data(Qt::DisplayRole).toString() : "";
fieldsCorrelation.detail =
ui->fieldsMap->item(i, 1) ? ui->fieldsMap->item(i, 1)->data(Qt::DisplayRole).toString() : "";
result.fieldMap.append(fieldsCorrelation); result.fieldMap.append(fieldsCorrelation);
} }
} }
@ -133,55 +131,51 @@ void SQLEditDialog::accept()
} }
} }
void SQLEditDialog::showEvent(QShowEvent *) void SQLEditDialog::showEvent(QShowEvent *) {
{
ui->lblInfo->setVisible(false); ui->lblInfo->setVisible(false);
initConnections(); initConnections();
readSettings(); readSettings();
} }
void SQLEditDialog::closeEvent(QCloseEvent *) void SQLEditDialog::closeEvent(QCloseEvent *) { writeSetting(); }
{
writeSetting();
}
void SQLEditDialog::hideEvent(QHideEvent *) void SQLEditDialog::hideEvent(QHideEvent *) { writeSetting(); }
{
writeSetting();
}
void SQLEditDialog::check() void SQLEditDialog::check() {
{ if (ui->leDatasourceName->text().isEmpty())
if (ui->leDatasourceName->text().isEmpty()) throw LimeReport::ReportError(tr("Datasource Name is empty!")); throw LimeReport::ReportError(tr("Datasource Name is empty!"));
if (ui->sqlText->toPlainText().isEmpty() && (!ui->rbProxy) ) throw LimeReport::ReportError(tr("SQL is empty!")); if (ui->sqlText->toPlainText().isEmpty() && (!ui->rbProxy))
throw LimeReport::ReportError(tr("SQL is empty!"));
if (m_dialogMode == AddMode) { if (m_dialogMode == AddMode) {
if (m_datasources->containsDatasource(ui->leDatasourceName->text())) { if (m_datasources->containsDatasource(ui->leDatasourceName->text())) {
throw LimeReport::ReportError(QString(tr("Datasource with name: \"%1\" already exists!")).arg(ui->leDatasourceName->text())); throw LimeReport::ReportError(
QString(tr("Datasource with name: \"%1\" already exists!")).arg(ui->leDatasourceName->text()));
} }
} }
} }
void SQLEditDialog::initConnections() void SQLEditDialog::initConnections() {
{
foreach (QString connectionName, QSqlDatabase::connectionNames()) { foreach (QString connectionName, QSqlDatabase::connectionNames()) {
ui->cbbConnection->addItem(QIcon(":/databrowser/images/plug-connect.png"),ConnectionDesc::connectionNameForUser(connectionName)); ui->cbbConnection->addItem(QIcon(":/databrowser/images/plug-connect.png"),
ConnectionDesc::connectionNameForUser(connectionName));
} }
foreach (QString connectionName, m_datasources->connectionNames()) { foreach (QString connectionName, m_datasources->connectionNames()) {
connectionName = (connectionName.compare(QSqlDatabase::defaultConnection)==0) ? connectionName =
tr("defaultConnection") : connectionName; (connectionName.compare(QSqlDatabase::defaultConnection) == 0) ? tr("defaultConnection") : connectionName;
if (ui->cbbConnection->findText(connectionName, Qt::MatchExactly) == -1) if (ui->cbbConnection->findText(connectionName, Qt::MatchExactly) == -1)
ui->cbbConnection->addItem(QIcon(":/databrowser/images/plug-disconnect.png"),ConnectionDesc::connectionNameForUser(connectionName)); ui->cbbConnection->addItem(QIcon(":/databrowser/images/plug-disconnect.png"),
ConnectionDesc::connectionNameForUser(connectionName));
} }
ui->cbbConnection->setCurrentIndex(ui->cbbConnection->findText(m_defaultConnection)); ui->cbbConnection->setCurrentIndex(ui->cbbConnection->findText(m_defaultConnection));
if (!m_oldDatasourceName.isEmpty()) { if (!m_oldDatasourceName.isEmpty()) {
ui->cbbConnection->setCurrentIndex(ui->cbbConnection->findText(ConnectionDesc::connectionNameForUser(m_datasources->connectionName(m_oldDatasourceName)))); ui->cbbConnection->setCurrentIndex(ui->cbbConnection->findText(
ConnectionDesc::connectionNameForUser(m_datasources->connectionName(m_oldDatasourceName))));
} }
} }
void SQLEditDialog::setDataSources(LimeReport::DataSourceManager *dataSources, QString datasourceName) void SQLEditDialog::setDataSources(LimeReport::DataSourceManager *dataSources, QString datasourceName) {
{
m_datasources = dataSources; m_datasources = dataSources;
if (!datasourceName.isEmpty()) { if (!datasourceName.isEmpty()) {
ui->cbSubdetail->setEnabled(true); ui->cbSubdetail->setEnabled(true);
@ -217,19 +211,18 @@ void SQLEditDialog::setDataSources(LimeReport::DataSourceManager *dataSources, Q
} }
} }
void SQLEditDialog::setDefaultConnection(QString defaultConnection) void SQLEditDialog::setDefaultConnection(QString defaultConnection) {
{
m_defaultConnection = ConnectionDesc::connectionNameForUser(defaultConnection); m_defaultConnection = ConnectionDesc::connectionNameForUser(defaultConnection);
} }
void SQLEditDialog::slotDataSourceNameEditing() void SQLEditDialog::slotDataSourceNameEditing() {
{
if (m_dialogMode == AddMode) { if (m_dialogMode == AddMode) {
QPalette palette = ui->leDatasourceName->palette(); QPalette palette = ui->leDatasourceName->palette();
if (m_datasources->containsDatasource(ui->leDatasourceName->text())) { if (m_datasources->containsDatasource(ui->leDatasourceName->text())) {
palette.setColor(QPalette::Text, Qt::red); palette.setColor(QPalette::Text, Qt::red);
ui->leDatasourceName->setPalette(palette); ui->leDatasourceName->setPalette(palette);
ui->lblInfo->setText(QString(tr("Datasource with name %1 already exist")).arg(ui->leDatasourceName->text())); ui->lblInfo->setText(
QString(tr("Datasource with name %1 already exist")).arg(ui->leDatasourceName->text()));
ui->lblInfo->setVisible(true); ui->lblInfo->setVisible(true);
} else { } else {
palette.setColor(QPalette::Text, QApplication::palette().text().color()); palette.setColor(QPalette::Text, QApplication::palette().text().color());
@ -239,37 +232,34 @@ void SQLEditDialog::slotDataSourceNameEditing()
} }
} }
void SQLEditDialog::on_cbSubdetail_clicked(bool checked) void SQLEditDialog::on_cbSubdetail_clicked(bool checked) {
{
if (checked) { if (checked) {
m_masterDatasources->setModel(new QStringListModel(m_datasources->dataSourceNames(), m_datasources)); m_masterDatasources->setModel(new QStringListModel(m_datasources->dataSourceNames(), m_datasources));
} }
ui->leMaster->setEnabled(checked); ui->leMaster->setEnabled(checked);
ui->rbProxy->setEnabled(checked); ui->rbProxy->setEnabled(checked);
ui->rbSubQuery->setEnabled(checked); ui->rbSubQuery->setEnabled(checked);
if ((checked)&&(ui->rbProxy->isChecked())) initProxyMode(); if ((checked) && (ui->rbProxy->isChecked()))
if ((checked)&&(ui->rbSubQuery->isChecked())) initSubQueryMode(); initProxyMode();
if (!checked) initQueryMode(); if ((checked) && (ui->rbSubQuery->isChecked()))
initSubQueryMode();
if (!checked)
initQueryMode();
} }
void SQLEditDialog::on_rbProxy_clicked(bool checked) void SQLEditDialog::on_rbProxy_clicked(bool checked) {
{ if (checked)
if (checked) initProxyMode(); initProxyMode();
} }
void SQLEditDialog::on_rbSubQuery_clicked(bool checked) void SQLEditDialog::on_rbSubQuery_clicked(bool checked) {
{ if (checked)
if (checked) initSubQueryMode(); initSubQueryMode();
} }
void SQLEditDialog::on_pbAddField_clicked() void SQLEditDialog::on_pbAddField_clicked() { ui->fieldsMap->setRowCount(ui->fieldsMap->rowCount() + 1); }
{
ui->fieldsMap->setRowCount(ui->fieldsMap->rowCount()+1);
}
void SQLEditDialog::initQueryMode() {
void SQLEditDialog::initQueryMode()
{
ui->gbSQL->setVisible(true); ui->gbSQL->setVisible(true);
ui->gbFieldsMap->setVisible(false); ui->gbFieldsMap->setVisible(false);
ui->pnlChildDatasource->setVisible(false); ui->pnlChildDatasource->setVisible(false);
@ -282,8 +272,7 @@ void SQLEditDialog::initQueryMode()
ui->tabWidget->addTab(ui->csvTab, tr("CSV")); ui->tabWidget->addTab(ui->csvTab, tr("CSV"));
} }
void SQLEditDialog::initSubQueryMode() void SQLEditDialog::initSubQueryMode() {
{
ui->gbSQL->setVisible(true); ui->gbSQL->setVisible(true);
ui->gbFieldsMap->setVisible(false); ui->gbFieldsMap->setVisible(false);
ui->pnlChildDatasource->setVisible(false); ui->pnlChildDatasource->setVisible(false);
@ -297,8 +286,7 @@ void SQLEditDialog::initSubQueryMode()
ui->tabWidget->removeTab(1); ui->tabWidget->removeTab(1);
} }
void SQLEditDialog::initProxyMode() void SQLEditDialog::initProxyMode() {
{
ui->gbSQL->setVisible(false); ui->gbSQL->setVisible(false);
ui->gbFieldsMap->setVisible(true); ui->gbFieldsMap->setVisible(true);
ui->pnlChildDatasource->setVisible(true); ui->pnlChildDatasource->setVisible(true);
@ -313,22 +301,16 @@ void SQLEditDialog::initProxyMode()
ui->tabWidget->removeTab(1); ui->tabWidget->removeTab(1);
} }
void SQLEditDialog::initCSVMode() void SQLEditDialog::initCSVMode() { ui->tabWidget->setCurrentWidget(ui->csvTab); }
{
ui->tabWidget->setCurrentWidget(ui->csvTab);
}
void SQLEditDialog::slotPreviewData() void SQLEditDialog::slotPreviewData() {
{
if (ui->cbbConnection->currentText().isEmpty()) { if (ui->cbbConnection->currentText().isEmpty()) {
QMessageBox::critical(this, tr("Attention"), tr("Connection is not specified")); QMessageBox::critical(this, tr("Attention"), tr("Connection is not specified"));
return; return;
} }
m_previewModel = m_datasources->previewSQL( m_previewModel =
ConnectionDesc::connectionNameForReport(ui->cbbConnection->currentText()), m_datasources->previewSQL(ConnectionDesc::connectionNameForReport(ui->cbbConnection->currentText()),
ui->sqlText->toPlainText(), ui->sqlText->toPlainText(), ui->leMaster->text());
ui->leMaster->text()
);
if (m_previewModel) { if (m_previewModel) {
ui->tvPreview->setModel(m_previewModel.data()); ui->tvPreview->setModel(m_previewModel.data());
ui->gbDataPreview->setVisible(true); ui->gbDataPreview->setVisible(true);
@ -341,13 +323,9 @@ void SQLEditDialog::slotPreviewData()
} }
} }
void SQLEditDialog::slotHidePreview() void SQLEditDialog::slotHidePreview() { hidePreview(); }
{
hidePreview();
}
void SQLEditDialog::writeSetting() void SQLEditDialog::writeSetting() {
{
if (settings() != 0) { if (settings() != 0) {
settings()->beginGroup("SQLEditor"); settings()->beginGroup("SQLEditor");
settings()->setValue("Geometry", saveGeometry()); settings()->setValue("Geometry", saveGeometry());
@ -355,9 +333,9 @@ void SQLEditDialog::writeSetting()
} }
} }
void SQLEditDialog::readSettings() void SQLEditDialog::readSettings() {
{ if (settings() == 0)
if (settings()==0) return; return;
settings()->beginGroup("SQLEditor"); settings()->beginGroup("SQLEditor");
QVariant v = settings()->value("Geometry"); QVariant v = settings()->value("Geometry");
if (v.isValid()) { if (v.isValid()) {
@ -366,20 +344,12 @@ void SQLEditDialog::readSettings()
settings()->endGroup(); settings()->endGroup();
} }
void SQLEditDialog::hidePreview() void SQLEditDialog::hidePreview() {
{
ui->gbDataPreview->setVisible(false); ui->gbDataPreview->setVisible(false);
ui->pbPreview->setText(tr("Preview")); ui->pbPreview->setText(tr("Preview"));
ui->pbHidePreview->setVisible(false); ui->pbHidePreview->setVisible(false);
} }
void SQLEditDialog::on_pbDelField_clicked() void SQLEditDialog::on_pbDelField_clicked() { ui->fieldsMap->removeRow(ui->fieldsMap->currentRow()); }
{
ui->fieldsMap->removeRow(ui->fieldsMap->currentRow());
}
} // namespace LimeReport } // namespace LimeReport