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

View File

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