[calamares] Use VariantModel instead of QJsonModel

- Drop the round-trip of forming a JSON document from a QVariant,
   then parsing the document into JSON objects and building a
   model out of that. View the Variant directly.
This commit is contained in:
Adriaan de Groot 2019-08-09 07:48:52 -04:00
parent 2bd03ad3c0
commit eba4dc8df1
2 changed files with 25 additions and 13 deletions

View File

@ -20,6 +20,8 @@
#include "DebugWindow.h" #include "DebugWindow.h"
#include "ui_DebugWindow.h" #include "ui_DebugWindow.h"
#include "VariantModel.h"
#include "Branding.h" #include "Branding.h"
#include "modulesystem/Module.h" #include "modulesystem/Module.h"
#include "modulesystem/ModuleManager.h" #include "modulesystem/ModuleManager.h"
@ -72,23 +74,25 @@ namespace Calamares {
DebugWindow::DebugWindow() DebugWindow::DebugWindow()
: QWidget( nullptr ) : QWidget( nullptr )
, m_ui( new Ui::DebugWindow ) , m_ui( new Ui::DebugWindow )
, m_globals( JobQueue::instance()->globalStorage()->data() )
, m_globals_model( std::make_unique< VariantModel >( &m_globals ) )
, m_module_model( std::make_unique< VariantModel >( &m_module ) )
{ {
m_ui->setupUi( this );
// GlobalStorage page
QJsonModel* jsonModel = new QJsonModel( this );
m_ui->globalStorageView->setModel( jsonModel );
GlobalStorage* gs = JobQueue::instance()->globalStorage(); GlobalStorage* gs = JobQueue::instance()->globalStorage();
m_ui->setupUi( this );
m_ui->globalStorageView->setModel( m_globals_model.get() );
m_ui->globalStorageView->expandAll();
// Do above when the GS changes, too
connect( gs, &GlobalStorage::changed, connect( gs, &GlobalStorage::changed,
this, [ = ] this, [ = ]
{ {
jsonModel->loadJson( QJsonDocument::fromVariant( gs->m ).toJson() ); m_globals = JobQueue::instance()->globalStorage()->data();
m_globals_model->reload();
m_ui->globalStorageView->expandAll(); m_ui->globalStorageView->expandAll();
} ); } );
jsonModel->loadJson( QJsonDocument::fromVariant( gs->m ).toJson() );
m_ui->globalStorageView->expandAll();
// JobQueue page // JobQueue page
m_ui->jobQueueText->setReadOnly( true ); m_ui->jobQueueText->setReadOnly( true );
@ -109,8 +113,7 @@ DebugWindow::DebugWindow()
m_ui->modulesListView->setModel( modulesModel ); m_ui->modulesListView->setModel( modulesModel );
m_ui->modulesListView->setSelectionMode( QAbstractItemView::SingleSelection ); m_ui->modulesListView->setSelectionMode( QAbstractItemView::SingleSelection );
QJsonModel* moduleConfigModel = new QJsonModel( this ); m_ui->moduleConfigView->setModel( m_module_model.get() );
m_ui->moduleConfigView->setModel( moduleConfigModel );
#ifdef WITH_PYTHONQT #ifdef WITH_PYTHONQT
QPushButton* pythonConsoleButton = new QPushButton; QPushButton* pythonConsoleButton = new QPushButton;
@ -181,7 +184,7 @@ DebugWindow::DebugWindow()
#endif #endif
connect( m_ui->modulesListView->selectionModel(), &QItemSelectionModel::selectionChanged, connect( m_ui->modulesListView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, [ this, moduleConfigModel this, [ this
#ifdef WITH_PYTHONQT #ifdef WITH_PYTHONQT
, pythonConsoleButton , pythonConsoleButton
#endif #endif
@ -191,7 +194,8 @@ DebugWindow::DebugWindow()
Module* module = ModuleManager::instance()->moduleInstance( moduleName ); Module* module = ModuleManager::instance()->moduleInstance( moduleName );
if ( module ) if ( module )
{ {
moduleConfigModel->loadJson( QJsonDocument::fromVariant( module->configurationMap() ).toJson() ); m_module = module->configurationMap();
m_module_model->reload();
m_ui->moduleConfigView->expandAll(); m_ui->moduleConfigView->expandAll();
m_ui->moduleTypeLabel->setText( module->typeString() ); m_ui->moduleTypeLabel->setText( module->typeString() );
m_ui->moduleInterfaceLabel->setText( module->interfaceString() ); m_ui->moduleInterfaceLabel->setText( module->interfaceString() );

View File

@ -20,8 +20,12 @@
#ifndef CALAMARES_DEBUGWINDOW_H #ifndef CALAMARES_DEBUGWINDOW_H
#define CALAMARES_DEBUGWINDOW_H #define CALAMARES_DEBUGWINDOW_H
#include "VariantModel.h"
#include <QVariant>
#include <QWidget> #include <QWidget>
#include <memory>
namespace Calamares { namespace Calamares {
@ -46,6 +50,10 @@ protected:
private: private:
Ui::DebugWindow *m_ui; Ui::DebugWindow *m_ui;
QVariant m_globals;
QVariant m_module;
std::unique_ptr< VariantModel> m_globals_model;
std::unique_ptr< VariantModel> m_module_model;
}; };