Skip to content

Commit

Permalink
Fixed few issues related to Qt 6 upgrade (inability to disable toolba…
Browse files Browse the repository at this point in the history
…r buttons, move/copy items between dbtree databases)
  • Loading branch information
pawelsalawa committed Dec 14, 2024
1 parent 8384774 commit 97b53fe
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 140 deletions.
60 changes: 32 additions & 28 deletions SQLiteStudio3/coreSQLiteStudio/dbobjectorganizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,19 @@ bool DbObjectOrganizer::processAll()
return false;
}

if (!setFkEnabled(false))
return false;

bool res = processAllWithFkDisabled();
setFkEnabled(true);
return res;
}

bool DbObjectOrganizer::processAllWithFkDisabled()
{
// Attaching target db if needed
AttachGuard attach;
if (srcDb->getTypeClassName() == dstDb->getTypeClassName() && !(referencedTables + srcTables).isEmpty())
if (useAttachingApproach())
{
attach = srcDb->guardedAttach(dstDb, true);
attachName = attach->getName();
Expand All @@ -215,13 +225,6 @@ bool DbObjectOrganizer::processAll()
return false;
}

if (!setFkEnabled(false))
{
srcDb->rollback();
dstDb->rollback();
return false;
}

bool res = false;
switch (mode)
{
Expand All @@ -244,26 +247,18 @@ bool DbObjectOrganizer::processAll()
}
}

if (!res)
if (!dstDb->commit())
{
srcDb->rollback();
// notifyError(tr("Could not commit transaction in database '%1'.").arg(dstDb->getName())); // TODO this is in another thread, cannot use notifyError
dstDb->rollback();
setFkEnabled(true);
return false;
}

if (!setFkEnabled(true))
{
srcDb->rollback();
dstDb->rollback();
return false;
}

if (!dstDb->commit())
if (!res)
{
// notifyError(tr("Could not commit transaction in database '%1'.").arg(dstDb->getName())); // TODO this is in another thread, cannot use notifyError
dstDb->rollback();
srcDb->rollback();
dstDb->rollback();
return false;
}

Expand Down Expand Up @@ -362,7 +357,7 @@ bool DbObjectOrganizer::copyTableToDb(const QString& table)
{
QString ddl;
QString targetTable = table;
if (renamed.contains(table) || !attachName.isNull())
if (renamed.contains(table) || useAttachingApproach())
{
SqliteQueryPtr parsedObject = srcResolver->getParsedObject(table, SchemaResolver::TABLE);
SqliteCreateTablePtr createTable = parsedObject.dynamicCast<SqliteCreateTable>();
Expand All @@ -377,7 +372,7 @@ bool DbObjectOrganizer::copyTableToDb(const QString& table)
targetTable = renamed[table];

createTable->table = targetTable;
if (!attachName.isNull())
if (useAttachingApproach())
createTable->database = attachName;

createTable->rebuildTokens();
Expand All @@ -393,7 +388,7 @@ bool DbObjectOrganizer::copyTableToDb(const QString& table)

SqlQueryPtr result;

if (attachName.isNull())
if (!useAttachingApproach())
result = dstDb->exec(ddl);
else
result = srcDb->exec(ddl); // uses attachName to create object in attached db
Expand All @@ -412,7 +407,7 @@ bool DbObjectOrganizer::copyTableToDb(const QString& table)

srcTable = table;
bool res;
if (attachName.isNull())
if (!useAttachingApproach())
{
notifyInfo(tr("Database %1 could not be attached to database %2, so the data of table %3 will be copied "
"with SQLiteStudio as a mediator. This method can be slow for huge tables, so please be patient.")
Expand Down Expand Up @@ -544,7 +539,7 @@ bool DbObjectOrganizer::copySimpleObjectToDb(const QString& name, const QString&
return false;

SqlQueryPtr result;
if (attachName.isNull())
if (!useAttachingApproach())
result = dstDb->exec(ddl);
else
result = srcDb->exec(ddl); // uses attachName to create object in attached db
Expand Down Expand Up @@ -586,7 +581,8 @@ void DbObjectOrganizer::collectReferencedTriggersForView(const QString& view)

bool DbObjectOrganizer::setFkEnabled(bool enabled)
{
SqlQueryPtr result = dstDb->exec(QString("PRAGMA foreign_keys = %1").arg(enabled ? "on" : "off"));
Db* theDb = useAttachingApproach() ? srcDb : dstDb;
SqlQueryPtr result = theDb->exec(QString("PRAGMA foreign_keys = %1").arg(enabled ? "on" : "off"));
if (result->isError())
{
// notifyError(tr("Error while executing PRAGMA on target database: %1").arg(result->getErrorText())); // TODO this is in another thread, cannot use notifyError
Expand All @@ -601,6 +597,14 @@ bool DbObjectOrganizer::isInterrupted()
return interrupted;
}

bool DbObjectOrganizer::useAttachingApproach() const
{
return !attachName.isNull() || (
srcDb->getTypeClassName() == dstDb->getTypeClassName() &&
!(referencedTables + srcTables).isEmpty()
);
}

void DbObjectOrganizer::setExecuting(bool executing)
{
QMutexLocker lock(&executingMutex);
Expand Down Expand Up @@ -654,7 +658,7 @@ bool DbObjectOrganizer::execConfirmFunctionInMainThread(const QStringList& table

QString DbObjectOrganizer::processSimpleObjectAttachNameAndRename(const QString& objName, const QString& ddl)
{
if (attachName.isNull() && !renamed.contains(objName))
if (!useAttachingApproach() && !renamed.contains(objName))
return ddl;

Parser parser;
Expand All @@ -681,7 +685,7 @@ QString DbObjectOrganizer::processSimpleObjectAttachNameAndRename(const QString&
return QString();
}

if (!attachName.isNull())
if (useAttachingApproach())
ddlWithDb->setTargetDatabase(attachName);

if (renamed.contains(objName))
Expand Down
2 changes: 2 additions & 0 deletions SQLiteStudio3/coreSQLiteStudio/dbobjectorganizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class API_EXPORT DbObjectOrganizer : public QObject, public QRunnable, public In
void copyOrMoveObjectsToDb(Db* srcDb, const QSet<QString>& objNames, Db* dstDb, bool includeData, bool includeIndexes, bool includeTriggers, bool move);
void processPreparation();
bool processAll();
bool processAllWithFkDisabled();
bool processDbObjects();
bool processColumns();
bool resolveNameConflicts();
Expand All @@ -97,6 +98,7 @@ class API_EXPORT DbObjectOrganizer : public QObject, public QRunnable, public In
void dropObject(const QString& name, const QString& type);
bool setFkEnabled(bool enabled);
bool isInterrupted();
bool useAttachingApproach() const;
void setExecuting(bool executing);
void setSrcAndDstDb(Db* srcDb, Db* dstDb);
bool begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class QStringEncoder;

class API_EXPORT GenericExportPlugin : virtual public GenericPlugin, public ExportPlugin
class API_EXPORT GenericExportPlugin : public GenericPlugin, public ExportPlugin
{
Q_OBJECT

Expand Down
2 changes: 1 addition & 1 deletion SQLiteStudio3/guiSQLiteStudio/common/dialogsizehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void DialogSizeHandler::applyFor(const QString &key, QObject *parent)

bool DialogSizeHandler::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::Resize | event->type() == QEvent::Move)
if (event->type() == QEvent::Resize || event->type() == QEvent::Move)
{
QWidget* w = qobject_cast<QWidget*>(obj);
recentGeometry = w->geometry();
Expand Down
30 changes: 0 additions & 30 deletions SQLiteStudio3/guiSQLiteStudio/common/extaction.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions SQLiteStudio3/guiSQLiteStudio/common/extaction.h

This file was deleted.

16 changes: 13 additions & 3 deletions SQLiteStudio3/guiSQLiteStudio/common/extactioncontainer.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "extactioncontainer.h"
#include "iconmanager.h"
#include "common/extaction.h"
#include "common/global.h"
#include <QSignalMapper>
#include <QToolButton>
#include <QToolBar>
#include <QMenu>
#include <QDebug>
#include <QEvent>

ExtActionContainer::ClassNameToToolBarAndAction ExtActionContainer::extraActions;
QList<ExtActionContainer*> ExtActionContainer::instances;
Expand Down Expand Up @@ -43,13 +43,13 @@ void ExtActionContainer::initActions()

void ExtActionContainer::createAction(int action, const Icon& icon, const QString& text, const QObject* receiver, const char* slot, QWidget* container, QWidget* owner)
{
QAction* qAction = new ExtAction(icon, text);
QAction* qAction = new QAction(icon, text);
createAction(action, qAction, receiver, slot, container, owner);
}

void ExtActionContainer::createAction(int action, const QString& text, const QObject* receiver, const char* slot, QWidget* container, QWidget* owner)
{
QAction* qAction = new ExtAction(text);
QAction* qAction = new QAction(text);
createAction(action, qAction, receiver, slot, container, owner);
}

Expand Down Expand Up @@ -290,3 +290,13 @@ ExtActionContainer::ActionDetails::ActionDetails(ExtActionPrototype* action, int
action(action), position(position), after(after)
{
}

bool ExtActionContainer::KeySequenceFilter::eventFilter(QObject* watched, QEvent* e)
{
if (e->type() == QEvent::Shortcut)
{
qobject_cast<QAction*>(watched)->activate(QAction::Trigger);
return true;
}
return QObject::event(e);
}
6 changes: 6 additions & 0 deletions SQLiteStudio3/guiSQLiteStudio/common/extactioncontainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ class GUI_API_EXPORT ExtActionContainer
private:
typedef QPair<int,ActionDetails*> ToolbarAndProto;

class KeySequenceFilter : public QObject
{
public:
bool eventFilter(QObject* watched, QEvent* e);
};

void refreshShortcuts();
void refreshShortcut(int action);
void deleteActions();
Expand Down
1 change: 0 additions & 1 deletion SQLiteStudio3/guiSQLiteStudio/datagrid/sqlqueryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "tsvserializer.h"
#include "iconmanager.h"
#include "common/unused.h"
#include "common/extaction.h"
#include "multieditor/multieditordialog.h"
#include "uiconfig.h"
#include "dialogs/sortdialog.h"
Expand Down
11 changes: 5 additions & 6 deletions SQLiteStudio3/guiSQLiteStudio/dataview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "common/extlineedit.h"
#include "mainwindow.h"
#include "common/intvalidator.h"
#include "common/extaction.h"
#include "iconmanager.h"
#include "themetuner.h"
#include "uiconfig.h"
Expand Down Expand Up @@ -321,8 +320,8 @@ void DataView::resizeColumnsInitiallyToContents()
void DataView::createStaticActions()
{
// Tabs position actions
staticActions[TABS_ON_TOP] = new ExtAction(ICONS.TABS_ON_TOP, tr("Tabs on top", "data view"), MainWindow::getInstance());
staticActions[TABS_AT_BOTTOM] = new ExtAction(ICONS.TABS_AT_BOTTOM, tr("Tabs at bottom", "data view"), MainWindow::getInstance());
staticActions[TABS_ON_TOP] = new QAction(ICONS.TABS_ON_TOP, tr("Tabs on top", "data view"), MainWindow::getInstance());
staticActions[TABS_AT_BOTTOM] = new QAction(ICONS.TABS_AT_BOTTOM, tr("Tabs at bottom", "data view"), MainWindow::getInstance());

staticActionGroups[ActionGroup::TABS_POSITION] = new QActionGroup(MainWindow::getInstance());
staticActionGroups[ActionGroup::TABS_POSITION]->addAction(staticActions[TABS_ON_TOP]);
Expand All @@ -347,9 +346,9 @@ void DataView::createStaticActions()
staticActions[TABS_AT_BOTTOM]->setChecked(true);

// Insert row positioning
staticActions[INSERT_ROW_BEFORE] = new ExtAction(tr("Place new rows above selected row", "data view"), MainWindow::getInstance());
staticActions[INSERT_ROW_AFTER] = new ExtAction(tr("Place new rows below selected row", "data view"), MainWindow::getInstance());
staticActions[INSERT_ROW_AT_END] = new ExtAction(tr("Place new rows at the end of the data view", "data view"), MainWindow::getInstance());
staticActions[INSERT_ROW_BEFORE] = new QAction(tr("Place new rows above selected row", "data view"), MainWindow::getInstance());
staticActions[INSERT_ROW_AFTER] = new QAction(tr("Place new rows below selected row", "data view"), MainWindow::getInstance());
staticActions[INSERT_ROW_AT_END] = new QAction(tr("Place new rows at the end of the data view", "data view"), MainWindow::getInstance());

staticActionGroups[ActionGroup::INSERT_ROW_POSITIONING] = new QActionGroup(MainWindow::getInstance());
staticActionGroups[ActionGroup::INSERT_ROW_POSITIONING]->addAction(staticActions[INSERT_ROW_BEFORE]);
Expand Down
Loading

0 comments on commit 97b53fe

Please sign in to comment.