All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent eafd18dac0
commit 25c3ba7338
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -21,15 +21,15 @@
***************************************************************************/
# include <QApplication>
# include <QElapsedTimer>
# include <QKeyEvent>
# include <QMessageBox>
# include <QMetaObject>
# include <QThread>
# include <QTime>
# include <QTimer>
# include <QWindow>
#include <QApplication>
#include <QElapsedTimer>
#include <QKeyEvent>
#include <QMessageBox>
#include <QMetaObject>
#include <QThread>
#include <QTime>
#include <QTimer>
#include <QWindow>
#include "ProgressBar.h"
@@ -41,7 +41,8 @@
using namespace Gui;
namespace Gui {
namespace Gui
{
struct SequencerBarPrivate
{
ProgressBar* bar;
@@ -64,31 +65,33 @@ struct ProgressBarPrivate
QWidget* parent = qobject_cast<QWidget*>(o);
if (!parent) {
QWindow* window = qobject_cast<QWindow*>(o);
if (window)
if (window) {
parent = QWidget::find(window->winId());
}
}
while (parent) {
auto* dlg = qobject_cast<QMessageBox*>(parent);
if (dlg && dlg->isModal())
if (dlg && dlg->isModal()) {
return true;
}
auto* pd = qobject_cast<QProgressDialog*>(parent);
if (pd)
if (pd) {
return true;
}
parent = parent->parentWidget();
}
return false;
}
};
}
} // namespace Gui
SequencerBar* SequencerBar::_pclSingleton = nullptr;
SequencerBar* SequencerBar::instance()
{
// not initialized?
if (!_pclSingleton)
{
if (!_pclSingleton) {
_pclSingleton = new SequencerBar();
}
@@ -110,11 +113,12 @@ SequencerBar::~SequencerBar()
void SequencerBar::pause()
{
QThread *currentThread = QThread::currentThread();
QThread *thr = d->bar->thread(); // this is the main thread
QThread* currentThread = QThread::currentThread();
QThread* thr = d->bar->thread(); // this is the main thread
d->bar->leaveControlEvents(d->guiThread);
if (thr != currentThread)
if (thr != currentThread) {
return;
}
// allow key handling of dialog and restore cursor
d->waitCursor->restoreCursor();
@@ -123,25 +127,30 @@ void SequencerBar::pause()
void SequencerBar::resume()
{
QThread *currentThread = QThread::currentThread();
QThread *thr = d->bar->thread(); // this is the main thread
QThread* currentThread = QThread::currentThread();
QThread* thr = d->bar->thread(); // this is the main thread
if (thr == currentThread) {
QApplication::restoreOverrideCursor();
d->waitCursor->setWaitCursor();
}
// must be called as last to get control before WaitCursor
d->bar->enterControlEvents(d->guiThread); // grab again
d->bar->enterControlEvents(d->guiThread); // grab again
}
void SequencerBar::startStep()
{
QThread *currentThread = QThread::currentThread();
QThread *thr = d->bar->thread(); // this is the main thread
QThread* currentThread = QThread::currentThread();
QThread* thr = d->bar->thread(); // this is the main thread
if (thr != currentThread) {
d->guiThread = false;
QMetaObject::invokeMethod(d->bar, "setRangeEx", Qt::QueuedConnection,
Q_ARG(int, 0), Q_ARG(int, (int)nTotalSteps));
QMetaObject::invokeMethod(
d->bar,
"setRangeEx",
Qt::QueuedConnection,
Q_ARG(int, 0),
Q_ARG(int, (int)nTotalSteps)
);
d->progressTime.start();
d->checkAbortTime.start();
d->measureTime.start();
@@ -162,11 +171,13 @@ void SequencerBar::startStep()
void SequencerBar::checkAbort()
{
if (d->bar->thread() != QThread::currentThread())
if (d->bar->thread() != QThread::currentThread()) {
return;
}
if (!wasCanceled()) {
if(d->checkAbortTime.elapsed() < 500)
if (d->checkAbortTime.elapsed() < 500) {
return;
}
d->checkAbortTime.restart();
qApp->processEvents();
return;
@@ -178,17 +189,18 @@ void SequencerBar::checkAbort()
resume();
// force to abort the operation
if ( ok ) {
if (ok) {
abort();
} else {
}
else {
rejectCancel();
}
}
void SequencerBar::nextStep(bool canAbort)
{
QThread *currentThread = QThread::currentThread();
QThread *thr = d->bar->thread(); // this is the main thread
QThread* currentThread = QThread::currentThread();
QThread* thr = d->bar->thread(); // this is the main thread
if (thr != currentThread) {
if (wasCanceled() && canAbort) {
abort();
@@ -206,15 +218,16 @@ void SequencerBar::nextStep(bool canAbort)
resume();
// force to abort the operation
if ( ok ) {
if (ok) {
abort();
} else {
}
else {
rejectCancel();
setValue((int)nProgress+1);
setValue((int)nProgress + 1);
}
}
else {
setValue((int)nProgress+1);
setValue((int)nProgress + 1);
}
}
}
@@ -222,7 +235,7 @@ void SequencerBar::nextStep(bool canAbort)
void SequencerBar::setProgress(size_t step)
{
QThread* currentThread = QThread::currentThread();
QThread* thr = d->bar->thread(); // this is the main thread
QThread* thr = d->bar->thread(); // this is the main thread
if (thr != currentThread) {
QMetaObject::invokeMethod(d->bar, "show", Qt::QueuedConnection);
}
@@ -235,8 +248,8 @@ void SequencerBar::setProgress(size_t step)
void SequencerBar::setValue(int step)
{
QThread *currentThread = QThread::currentThread();
QThread *thr = d->bar->thread(); // this is the main thread
QThread* currentThread = QThread::currentThread();
QThread* thr = d->bar->thread(); // this is the main thread
// if number of total steps is unknown then increment only by one
if (nTotalSteps == 0) {
int elapsed = d->progressTime.elapsed();
@@ -244,11 +257,15 @@ void SequencerBar::setValue(int step)
if (elapsed > 100) {
d->progressTime.restart();
if (thr != currentThread) {
QMetaObject::invokeMethod(d->bar, "setValueEx", Qt::/*Blocking*/QueuedConnection,
Q_ARG(int,d->bar->value()+1));
QMetaObject::invokeMethod(
d->bar,
"setValueEx",
Qt::/*Blocking*/ QueuedConnection,
Q_ARG(int, d->bar->value() + 1)
);
}
else {
d->bar->setValueEx(d->bar->value()+1);
d->bar->setValueEx(d->bar->value() + 1);
qApp->processEvents();
}
}
@@ -259,15 +276,21 @@ void SequencerBar::setValue(int step)
if (elapsed > 100) {
d->progressTime.restart();
if (thr != currentThread) {
QMetaObject::invokeMethod(d->bar, "setValueEx", Qt::/*Blocking*/QueuedConnection,
Q_ARG(int,step));
if (d->bar->isVisible())
QMetaObject::invokeMethod(
d->bar,
"setValueEx",
Qt::/*Blocking*/ QueuedConnection,
Q_ARG(int, step)
);
if (d->bar->isVisible()) {
showRemainingTime();
}
}
else {
d->bar->setValueEx(step);
if (d->bar->isVisible())
if (d->bar->isVisible()) {
showRemainingTime();
}
d->bar->resetObserveEventFilter();
qApp->processEvents();
}
@@ -277,8 +300,8 @@ void SequencerBar::setValue(int step)
void SequencerBar::showRemainingTime()
{
QThread *currentThread = QThread::currentThread();
QThread *thr = d->bar->thread(); // this is the main thread
QThread* currentThread = QThread::currentThread();
QThread* thr = d->bar->thread(); // this is the main thread
int elapsed = d->measureTime.elapsed();
int progress = d->bar->value();
@@ -287,19 +310,22 @@ void SequencerBar::showRemainingTime()
QString txt = d->text;
// More than 5 percent complete or more than 5 secs have elapsed.
if (progress * 20 > totalSteps || elapsed > 5000) {
int rest = (int) ( (double) totalSteps/progress * elapsed ) - elapsed;
int rest = (int)((double)totalSteps / progress * elapsed) - elapsed;
// more than 1 secs have elapsed and at least 100 ms are remaining
if (elapsed > 1000 && rest > 100) {
QTime time( 0,0, 0);
time = time.addSecs( rest/1000 );
QTime time(0, 0, 0);
time = time.addSecs(rest / 1000);
QString remain = Gui::ProgressBar::tr("Remaining: %1").arg(time.toString());
QString status = QStringLiteral("%1\t[%2]").arg(txt, remain);
if (thr != currentThread) {
QMetaObject::invokeMethod(getMainWindow(), "showMessage",
Qt::/*Blocking*/QueuedConnection,
Q_ARG(QString,status));
QMetaObject::invokeMethod(
getMainWindow(),
"showMessage",
Qt::/*Blocking*/ QueuedConnection,
Q_ARG(QString, status)
);
}
else {
getMainWindow()->showMessage(status);
@@ -310,18 +336,24 @@ void SequencerBar::showRemainingTime()
void SequencerBar::resetData()
{
QThread *currentThread = QThread::currentThread();
QThread *thr = d->bar->thread(); // this is the main thread
QThread* currentThread = QThread::currentThread();
QThread* thr = d->bar->thread(); // this is the main thread
if (thr != currentThread) {
QMetaObject::invokeMethod(d->bar, "resetEx", Qt::QueuedConnection);
QMetaObject::invokeMethod(d->bar, "aboutToHide", Qt::QueuedConnection);
QMetaObject::invokeMethod(getMainWindow(), "showMessage",
Qt::/*Blocking*/QueuedConnection,
Q_ARG(QString,QString()));
QMetaObject::invokeMethod(getMainWindow(), "setPaneText",
Qt::/*Blocking*/QueuedConnection,
Q_ARG(int,1),
Q_ARG(QString,QString()));
QMetaObject::invokeMethod(
getMainWindow(),
"showMessage",
Qt::/*Blocking*/ QueuedConnection,
Q_ARG(QString, QString())
);
QMetaObject::invokeMethod(
getMainWindow(),
"setPaneText",
Qt::/*Blocking*/ QueuedConnection,
Q_ARG(int, 1),
Q_ARG(QString, QString())
);
d->bar->leaveControlEvents(d->guiThread);
}
else {
@@ -342,23 +374,26 @@ void SequencerBar::resetData()
void SequencerBar::abort()
{
//resets
// resets
resetData();
Base::AbortException exc("User aborted");
throw exc;
}
void SequencerBar::setText (const char* pszTxt)
void SequencerBar::setText(const char* pszTxt)
{
QThread *currentThread = QThread::currentThread();
QThread *thr = d->bar->thread(); // this is the main thread
QThread* currentThread = QThread::currentThread();
QThread* thr = d->bar->thread(); // this is the main thread
// print message to the statusbar
d->text = pszTxt ? QString::fromUtf8(pszTxt) : QLatin1String("");
if (thr != currentThread) {
QMetaObject::invokeMethod(getMainWindow(), "showMessage",
Qt::/*Blocking*/QueuedConnection,
Q_ARG(QString,d->text));
QMetaObject::invokeMethod(
getMainWindow(),
"showMessage",
Qt::/*Blocking*/ QueuedConnection,
Q_ARG(QString, d->text)
);
}
else {
getMainWindow()->showMessage(d->text);
@@ -372,8 +407,9 @@ bool SequencerBar::isBlocking() const
QProgressBar* SequencerBar::getProgressBar(QWidget* parent)
{
if (!d->bar)
if (!d->bar) {
d->bar = new ProgressBar(this, parent);
}
return d->bar;
}
@@ -381,15 +417,16 @@ QProgressBar* SequencerBar::getProgressBar(QWidget* parent)
/* TRANSLATOR Gui::ProgressBar */
ProgressBar::ProgressBar (SequencerBar* s, QWidget * parent)
: QProgressBar(parent), sequencer(s)
ProgressBar::ProgressBar(SequencerBar* s, QWidget* parent)
: QProgressBar(parent)
, sequencer(s)
{
#ifdef QT_WINEXTRAS_LIB
m_taskbarButton = nullptr;
m_taskbarButton = nullptr;
m_taskbarButton = nullptr;
m_taskbarButton = nullptr;
#endif
d = new Gui::ProgressBarPrivate;
d->minimumDuration = 2000; // 2 seconds
d->minimumDuration = 2000; // 2 seconds
d->delayShowTimer = new QTimer(this);
d->delayShowTimer->setSingleShot(true);
connect(d->delayShowTimer, &QTimer::timeout, this, &ProgressBar::delayedShow);
@@ -402,7 +439,7 @@ ProgressBar::ProgressBar (SequencerBar* s, QWidget * parent)
hide();
}
ProgressBar::~ProgressBar ()
ProgressBar::~ProgressBar()
{
disconnect(d->delayShowTimer, &QTimer::timeout, this, &ProgressBar::delayedShow);
delete d->delayShowTimer;
@@ -416,35 +453,34 @@ int ProgressBar::minimumDuration() const
void ProgressBar::resetEx()
{
QProgressBar::reset();
QProgressBar::reset();
#ifdef QT_WINEXTRAS_LIB
setupTaskBarProgress();
m_taskbarProgress->reset();
setupTaskBarProgress();
m_taskbarProgress->reset();
#endif
}
void ProgressBar::setRangeEx(int minimum, int maximum)
{
QProgressBar::setRange(minimum, maximum);
QProgressBar::setRange(minimum, maximum);
#ifdef QT_WINEXTRAS_LIB
setupTaskBarProgress();
m_taskbarProgress->setRange(minimum, maximum);
setupTaskBarProgress();
m_taskbarProgress->setRange(minimum, maximum);
#endif
}
void ProgressBar::setValueEx(int value)
{
QProgressBar::setValue(value);
QProgressBar::setValue(value);
#ifdef QT_WINEXTRAS_LIB
setupTaskBarProgress();
m_taskbarProgress->setValue(value);
setupTaskBarProgress();
m_taskbarProgress->setValue(value);
#endif
}
void ProgressBar::setMinimumDuration (int ms)
void ProgressBar::setMinimumDuration(int ms)
{
if (value() == 0)
{
if (value() == 0) {
d->delayShowTimer->stop();
d->delayShowTimer->start(ms);
}
@@ -480,9 +516,13 @@ void ProgressBar::aboutToHide()
bool ProgressBar::canAbort() const
{
auto ret = QMessageBox::question(getMainWindow(),tr("Aborting"),
tr("Abort the operation?"), QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
auto ret = QMessageBox::question(
getMainWindow(),
tr("Aborting"),
tr("Abort the operation?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No
);
return (ret == QMessageBox::Yes) ? true : false;
}
@@ -513,8 +553,9 @@ void ProgressBar::enterControlEvents(bool grab)
#if defined(Q_OS_LINUX)
Q_UNUSED(grab)
#else
if (grab)
if (grab) {
grabKeyboard();
}
#endif
}
@@ -526,22 +567,22 @@ void ProgressBar::leaveControlEvents(bool release)
Q_UNUSED(release)
#else
// release the keyboard again
if (release)
if (release) {
releaseKeyboard();
}
#endif
}
#ifdef QT_WINEXTRAS_LIB
void ProgressBar::setupTaskBarProgress()
{
if (!m_taskbarButton || !m_taskbarProgress)
{
m_taskbarButton = new QWinTaskbarButton(this);
m_taskbarButton->setWindow(MainWindow::getInstance()->windowHandle());
//m_myButton->setOverlayIcon(QIcon(""));
if (!m_taskbarButton || !m_taskbarProgress) {
m_taskbarButton = new QWinTaskbarButton(this);
m_taskbarButton->setWindow(MainWindow::getInstance()->windowHandle());
// m_myButton->setOverlayIcon(QIcon(""));
m_taskbarProgress = m_taskbarButton->progress();
}
m_taskbarProgress = m_taskbarButton->progress();
}
}
#endif
@@ -549,7 +590,7 @@ bool ProgressBar::eventFilter(QObject* o, QEvent* e)
{
if (sequencer->isRunning() && e) {
QThread* currentThread = QThread::currentThread();
QThread* thr = this->thread(); // this is the main thread
QThread* thr = this->thread(); // this is the main thread
if (thr != currentThread) {
if (e->type() == QEvent::KeyPress) {
auto ke = static_cast<QKeyEvent*>(e);
@@ -563,16 +604,16 @@ bool ProgressBar::eventFilter(QObject* o, QEvent* e)
}
// main thread
switch ( e->type() )
{
// check for ESC
case QEvent::KeyPress:
{
switch (e->type()) {
// check for ESC
case QEvent::KeyPress: {
auto ke = static_cast<QKeyEvent*>(e);
if (ke->key() == Qt::Key_Escape) {
// eventFilter() was called from the application 50 times without performing a new step (app could hang)
// eventFilter() was called from the application 50 times without performing a
// new step (app could hang)
if (d->observeEventFilter > 50) {
// tries to unlock the application if it hangs (probably due to incorrect usage of Base::Sequencer)
// tries to unlock the application if it hangs (probably due to incorrect
// usage of Base::Sequencer)
if (ke->modifiers() & (Qt::ControlModifier | Qt::AltModifier)) {
sequencer->resetData();
return true;
@@ -584,45 +625,42 @@ bool ProgressBar::eventFilter(QObject* o, QEvent* e)
}
return true;
} break;
} break;
// ignore all these events
case QEvent::KeyRelease:
case QEvent::Enter:
case QEvent::Leave:
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
case QEvent::MouseMove:
case QEvent::NativeGesture:
case QEvent::ContextMenu:
{
if (!d->isModalDialog(o))
// ignore all these events
case QEvent::KeyRelease:
case QEvent::Enter:
case QEvent::Leave:
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonRelease:
case QEvent::MouseMove:
case QEvent::NativeGesture:
case QEvent::ContextMenu: {
if (!d->isModalDialog(o)) {
return true;
} break;
}
} break;
// special case if the main window's close button was pressed
case QEvent::Close:
{
// special case if the main window's close button was pressed
case QEvent::Close: {
// avoid to exit while app is working
// note: all other widget types are allowed to be closed anyway
if (o == getMainWindow()) {
e->ignore();
return true;
}
} break;
} break;
// do a system beep and ignore the event
case QEvent::MouseButtonPress:
{
// do a system beep and ignore the event
case QEvent::MouseButtonPress: {
if (!d->isModalDialog(o)) {
QApplication::beep();
return true;
}
} break;
} break;
default:
{
} break;
default: {
} break;
}
d->observeEventFilter++;