Skip to content

Commit 99105fb

Browse files
committed
instantiate CliOptions in ViewModelCollection (not in main)
1 parent 1330eb5 commit 99105fb

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/app/main.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ int main( int argc, char* argv[] )
3737

3838
QGuiApplication app( argc, argv ); // ... note next line...
3939
// QQuickStyle::setStyle( "Fusion" ); // <-- call setStyle after creating app (if style is needed)
40-
project::CliOptions cliOptions( app );
4140

4241
// ViewModels must OUTLIVE the qml engine, so create them first:
43-
project::ViewModelCollection vms( cliOptions );
42+
project::ViewModelCollection vms( app );
4443

4544
// For antialiasing: https://stackoverflow.com/a/49576756/10278
4645
// QSurfaceFormat format;
@@ -63,7 +62,7 @@ int main( int argc, char* argv[] )
6362

6463
engine.addImportPath( "qrc:///" ); // needed for finding qml in our plugins
6564
engine.load( QUrl( QStringLiteral( "qrc:///qml/main.qml" ) ) );
66-
if( cliOptions.ShowColorPalette() )
65+
if( vms.Options().ShowColorPalette() )
6766
{
6867
// This second app window will cause the FASSERT about root objects
6968
// count to trigger below, but just choose 'c' to continue beyond the

src/app/view_model_collection.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace project
2424
using str = std::string;
2525

2626
// clang-format off
27-
ViewModelCollection::ViewModelCollection( const CliOptions& opts )
28-
: m_opts( &opts ),
27+
ViewModelCollection::ViewModelCollection( const QCoreApplication& app )
28+
: m_opts( std::make_unique<CliOptions>( app ) ),
2929
m_eventFilter( std::make_unique<EventFilter>() ),
3030
m_qmlLogger( std::make_unique<QmlMessageInterceptor>( !m_opts->MaximumQtLogging() ) ),
3131
m_logging( std::make_unique<LoggingTags>( *m_opts ) )
@@ -39,6 +39,11 @@ ViewModelCollection::ViewModelCollection( const CliOptions& opts )
3939

4040
ViewModelCollection::~ViewModelCollection() = default;
4141

42+
const CliOptions& ViewModelCollection::Options() const
43+
{
44+
return *m_opts;
45+
}
46+
4247
void ViewModelCollection::ExportContextPropertiesToQml( QQmlApplicationEngine* engine )
4348
{
4449
// Sort of a "silly" demo usage of project::Log<>

src/app/view_model_collection.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class QmlMessageInterceptor;
2525
class ViewModelCollection
2626
{
2727
public:
28-
explicit ViewModelCollection( const CliOptions& opts );
28+
explicit ViewModelCollection( const QCoreApplication& app );
2929
~ViewModelCollection();
3030

3131
ViewModelCollection( const ViewModelCollection& ) = delete;
@@ -35,8 +35,10 @@ class ViewModelCollection
3535

3636
void SetRootObject( QObject* object );
3737

38+
const CliOptions& Options() const;
39+
3840
private:
39-
const CliOptions* const m_opts;
41+
std::unique_ptr<const CliOptions> m_opts;
4042
std::unique_ptr<EventFilter> m_eventFilter;
4143
std::unique_ptr<QmlMessageInterceptor> m_qmlLogger;
4244
std::unique_ptr<LoggingTags> m_logging;

0 commit comments

Comments
 (0)