[calamares] Refactor debug-window handling

Move the management of the (a?) DebugWindow to a separate
class, and hang on to that manager in CalamaresWindow.
This is prep-work towards making it available from QML as well.
main
Adriaan de Groot 4 years ago
parent 992c673951
commit c00a382aea

@ -86,7 +86,7 @@ setButtonIcon( QPushButton* button, const QString& name )
}
static QWidget*
getWidgetSidebar( CalamaresWindow* window,
getWidgetSidebar( Calamares::DebugWindowManager* debug,
Calamares::ViewManager* viewManager,
QWidget* parent,
Qt::Orientation,
@ -128,7 +128,7 @@ getWidgetSidebar( CalamaresWindow* window,
tv->setFocusPolicy( Qt::NoFocus );
sideLayout->addWidget( tv );
if ( Calamares::Settings::instance()->debugMode() || ( Logger::logLevel() >= Logger::LOGVERBOSE ) )
if ( debug && debug->enabled() )
{
QPushButton* debugWindowBtn = new QPushButton;
debugWindowBtn->setObjectName( "debugButton" );
@ -138,8 +138,9 @@ getWidgetSidebar( CalamaresWindow* window,
sideLayout->addWidget( debugWindowBtn );
debugWindowBtn->setFlat( true );
debugWindowBtn->setCheckable( true );
QObject::connect( debugWindowBtn, &QPushButton::clicked, window, &CalamaresWindow::showDebugWindow );
QObject::connect( window, &CalamaresWindow::debugWindowShown, debugWindowBtn, &QPushButton::setChecked );
QObject::connect( debugWindowBtn, &QPushButton::clicked, debug, &Calamares::DebugWindowManager::show );
QObject::connect(
debug, &Calamares::DebugWindowManager::visibleChanged, debugWindowBtn, &QPushButton::setChecked );
}
CalamaresUtils::unmarginLayout( sideLayout );
@ -147,7 +148,11 @@ getWidgetSidebar( CalamaresWindow* window,
}
static QWidget*
getWidgetNavigation( CalamaresWindow*, Calamares::ViewManager* viewManager, QWidget* parent, Qt::Orientation, int )
getWidgetNavigation( Calamares::DebugWindowManager*,
Calamares::ViewManager* viewManager,
QWidget* parent,
Qt::Orientation,
int )
{
QWidget* navigation = new QWidget( parent );
QBoxLayout* bottomLayout = new QHBoxLayout;
@ -235,7 +240,11 @@ setDimension( QQuickWidget* w, Qt::Orientation o, int desiredWidth )
static QWidget*
getQmlSidebar( CalamaresWindow*, Calamares::ViewManager*, QWidget* parent, Qt::Orientation o, int desiredWidth )
getQmlSidebar( Calamares::DebugWindowManager*,
Calamares::ViewManager*,
QWidget* parent,
Qt::Orientation o,
int desiredWidth )
{
CalamaresUtils::registerQmlModels();
QQuickWidget* w = new QQuickWidget( parent );
@ -246,7 +255,11 @@ getQmlSidebar( CalamaresWindow*, Calamares::ViewManager*, QWidget* parent, Qt::O
}
static QWidget*
getQmlNavigation( CalamaresWindow*, Calamares::ViewManager*, QWidget* parent, Qt::Orientation o, int desiredWidth )
getQmlNavigation( Calamares::DebugWindowManager*,
Calamares::ViewManager*,
QWidget* parent,
Qt::Orientation o,
int desiredWidth )
{
CalamaresUtils::registerQmlModels();
QQuickWidget* w = new QQuickWidget( parent );
@ -261,12 +274,20 @@ getQmlNavigation( CalamaresWindow*, Calamares::ViewManager*, QWidget* parent, Qt
// Calls to flavoredWidget() still refer to these *names*
// even if they are subsequently not used.
static QWidget*
getQmlSidebar( CalamaresWindow*, Calamares::ViewManager*, QWidget* parent, Qt::Orientation, int desiredWidth )
getQmlSidebar( Calamares::DebugWindowManager*,
Calamares::ViewManager*,
QWidget* parent,
Qt::Orientation,
int desiredWidth )
{
return nullptr;
}
static QWidget*
getQmlNavigation( CalamaresWindow*, Calamares::ViewManager*, QWidget* parent, Qt::Orientation, int desiredWidth )
getQmlNavigation( Calamares::DebugWindowManager*,
Calamares::ViewManager*,
QWidget* parent,
Qt::Orientation,
int desiredWidth )
{
return nullptr;
}
@ -281,7 +302,7 @@ template < typename widgetMaker, typename... args >
QWidget*
flavoredWidget( Calamares::Branding::PanelFlavor flavor,
Qt::Orientation o,
CalamaresWindow* w,
Calamares::DebugWindowManager* w,
QWidget* parent,
widgetMaker widget,
widgetMaker qml, // Only if WITH_QML is on
@ -321,7 +342,7 @@ insertIf( QBoxLayout* layout,
CalamaresWindow::CalamaresWindow( QWidget* parent )
: QWidget( parent )
, m_debugWindow( nullptr )
, m_debugManager( new Calamares::DebugWindowManager( this ) )
, m_viewManager( nullptr )
{
// If we can never cancel, don't show the window-close button
@ -400,14 +421,14 @@ CalamaresWindow::CalamaresWindow( QWidget* parent )
QWidget* sideBox = flavoredWidget(
branding->sidebarFlavor(),
::orientation( branding->sidebarSide() ),
this,
m_debugManager,
baseWidget,
::getWidgetSidebar,
::getQmlSidebar,
qBound( 100, CalamaresUtils::defaultFontHeight() * 12, w < windowPreferredWidth ? 100 : 190 ) );
QWidget* navigation = flavoredWidget( branding->navigationFlavor(),
::orientation( branding->navigationSide() ),
this,
m_debugManager,
baseWidget,
::getWidgetNavigation,
::getQmlNavigation,
@ -461,29 +482,6 @@ CalamaresWindow::ensureSize( QSize size )
resize( w, h );
}
void
CalamaresWindow::showDebugWindow( bool show )
{
if ( show )
{
m_debugWindow = new Calamares::DebugWindow();
m_debugWindow->show();
connect( m_debugWindow.data(), &Calamares::DebugWindow::closed, this, [=]() {
m_debugWindow->deleteLater();
emit debugWindowShown( false );
} );
emit debugWindowShown( true );
}
else
{
if ( m_debugWindow )
{
m_debugWindow->deleteLater();
}
emit debugWindowShown( false );
}
}
void
CalamaresWindow::closeEvent( QCloseEvent* event )
{

@ -11,12 +11,13 @@
#ifndef CALAMARESWINDOW_H
#define CALAMARESWINDOW_H
#include <QPointer>
#include <QWidget>
#include <memory>
namespace Calamares
{
class DebugWindow;
class DebugWindowManager;
class ViewManager;
} // namespace Calamares
@ -38,23 +39,12 @@ public Q_SLOTS:
*/
void ensureSize( QSize size );
/** @brief Set visibility of debug window
*
* Shows or hides the debug window, depending on @p show.
* If Calamares is not in debug mode, nothing happens and the debug
* window remains hidden.
*/
void showDebugWindow( bool show );
Q_SIGNALS:
void debugWindowShown( bool show );
protected:
virtual void closeEvent( QCloseEvent* e ) override;
private:
QPointer< Calamares::DebugWindow > m_debugWindow; // Managed by self
Calamares::ViewManager* m_viewManager;
Calamares::DebugWindowManager* m_debugManager = nullptr;
Calamares::ViewManager* m_viewManager = nullptr;
};
#endif // CALAMARESWINDOW_H

@ -11,15 +11,14 @@
#include "DebugWindow.h"
#include "ui_DebugWindow.h"
#include "VariantModel.h"
#include "Branding.h"
#include "modulesystem/Module.h"
#include "modulesystem/ModuleManager.h"
#include "GlobalStorage.h"
#include "Job.h"
#include "JobQueue.h"
#include "Settings.h"
#include "VariantModel.h"
#include "modulesystem/Module.h"
#include "modulesystem/ModuleManager.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h"
@ -225,4 +224,55 @@ DebugWindow::closeEvent( QCloseEvent* e )
emit closed();
}
DebugWindowManager::DebugWindowManager( QObject* parent )
: QObject( parent )
{
}
bool
DebugWindowManager::enabled() const
{
const auto* s = Settings::instance();
return ( Logger::logLevel() >= Logger::LOGVERBOSE ) || ( s ? s->debugMode() : false );
}
void
DebugWindowManager::show( bool visible )
{
if ( !enabled() )
{
visible = false;
}
if ( m_visible == visible )
{
return;
}
if ( visible )
{
m_debugWindow = new Calamares::DebugWindow();
m_debugWindow->show();
connect( m_debugWindow.data(), &Calamares::DebugWindow::closed, this, [=]() {
m_debugWindow->deleteLater();
m_visible = false;
emit visibleChanged( false );
} );
m_visible = true;
emit visibleChanged( true );
}
else
{
if ( m_debugWindow )
{
m_debugWindow->deleteLater();
}
m_visible = false;
emit visibleChanged( false );
}
}
} // namespace Calamares

@ -13,6 +13,7 @@
#include "VariantModel.h"
#include <QPointer>
#include <QVariant>
#include <QWidget>
@ -48,6 +49,43 @@ private:
std::unique_ptr< VariantModel > m_module_model;
};
/** @brief Manager for the (single) DebugWindow
*
* Only one DebugWindow is expected to be around. This class manages
* (exactly one) DebugWindow and can create and destroy it as needed.
* It is available to the Calamares panels as object `DebugWindow`.
*/
class DebugWindowManager : public QObject
{
Q_OBJECT
/// @brief Proxy to Settings::debugMode() default @c false
Q_PROPERTY( bool enabled READ enabled CONSTANT FINAL )
/** @brief Is the debug window visible?
*
* Writing @c true to this **may** make the debug window visible to
* the user; only if debugMode() is on.
*/
Q_PROPERTY( bool visible READ visible WRITE show NOTIFY visibleChanged )
public:
DebugWindowManager( QObject* parent = nullptr );
virtual ~DebugWindowManager() override = default;
public Q_SLOTS:
bool enabled() const;
bool visible() const { return m_visible; }
void show( bool visible );
signals:
void visibleChanged( bool visible );
private:
QPointer< DebugWindow > m_debugWindow;
bool m_visible = false;
};
} // namespace Calamares
#endif

Loading…
Cancel
Save