From da126bfb5ce89f8625a9811b76f47487a2466595 Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Sun, 15 Apr 2018 18:17:37 -0700 Subject: [PATCH] Use range-based for loops + fix const correctness --- include/Controller.h | 3 +- include/GroupBox.h | 1 - src/core/Controller.cpp | 43 ++++++++++---------------- src/gui/ControllerConnectionDialog.cpp | 5 ++- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/include/Controller.h b/include/Controller.h index 7aded3bc1..89a5e9371 100644 --- a/include/Controller.h +++ b/include/Controller.h @@ -130,6 +130,7 @@ public: void removeConnection( ControllerConnection * ); int connectionCount() const; + bool hasModel( const Model * m ) const; public slots: virtual ControllerDialog * createDialog( QWidget * _parent ); @@ -139,8 +140,6 @@ public slots: m_name = _new_name; } - bool hasModel( const Model * m ); - protected: // The internal per-controller get-value function diff --git a/include/GroupBox.h b/include/GroupBox.h index 39d9a522a..8a857199f 100644 --- a/include/GroupBox.h +++ b/include/GroupBox.h @@ -70,7 +70,6 @@ private: } ; -typedef BoolModel groupBoxModel; #endif diff --git a/src/core/Controller.cpp b/src/core/Controller.cpp index 1293081fb..affb68d5f 100644 --- a/src/core/Controller.cpp +++ b/src/core/Controller.cpp @@ -63,11 +63,9 @@ Controller::Controller( ControllerTypes _type, Model * _parent, // Check if name is already in use bool name_used = false; - QVector::const_iterator it; - for ( it = s_controllers.constBegin(); - it != s_controllers.constEnd(); ++it ) + for (Controller * controller : s_controllers) { - if ( (*it)->name() == new_name ) + if ( controller->name() == new_name ) { name_used = true; break; @@ -157,13 +155,13 @@ float Controller::runningTime() void Controller::triggerFrameCounter() { - for( int i = 0; i < s_controllers.size(); ++i ) + for (Controller * controller : s_controllers) { // This signal is for updating values for both stubborn knobs and for // painting. If we ever get all the widgets to use or at least check // currentValue() then we can throttle the signal and only use it for // GUI. - emit s_controllers.at(i)->valueChanged(); + emit controller->valueChanged(); } s_periods ++; @@ -174,10 +172,10 @@ void Controller::triggerFrameCounter() void Controller::resetFrameCounter() { - for( int i = 0; i < s_controllers.size(); ++i ) + for (Controller * controller : s_controllers) { - s_controllers.at( i )->m_bufferLastUpdated = 0; - } + controller->m_bufferLastUpdated = 0; + } s_periods = 0; } @@ -190,15 +188,11 @@ Controller * Controller::create( ControllerTypes _ct, Model * _parent ) switch( _ct ) { - case Controller::DummyController: - if( dummy ) - c = dummy; - else - { - c = new Controller( DummyController, NULL, + case Controller::DummyController: + if (!dummy) + dummy = new Controller( DummyController, NULL, QString() ); - dummy = c; - } + c = dummy; break; case Controller::LfoController: @@ -247,12 +241,10 @@ Controller * Controller::create( const QDomElement & _this, Model * _parent ) -bool Controller::hasModel( const Model * m ) +bool Controller::hasModel( const Model * m ) const { - QObjectList chldren = children(); - for( int i = 0; i < chldren.size(); ++i ) + for (QObject * c : children()) { - QObject * c = chldren.at(i); AutomatableModel * am = qobject_cast(c); if( am != NULL ) { @@ -262,16 +254,13 @@ bool Controller::hasModel( const Model * m ) } ControllerConnection * cc = am->controllerConnection(); - if( cc != NULL ) + if( cc != NULL && cc->getController()->hasModel( m ) ) { - if( cc->getController()->hasModel( m ) ) - { - return true; - } + return true; } } } - + return false; } diff --git a/src/gui/ControllerConnectionDialog.cpp b/src/gui/ControllerConnectionDialog.cpp index 1adf162e7..49747e087 100644 --- a/src/gui/ControllerConnectionDialog.cpp +++ b/src/gui/ControllerConnectionDialog.cpp @@ -189,12 +189,11 @@ ControllerConnectionDialog::ControllerConnectionDialog( QWidget * _parent, m_userController = new ComboBox( m_userGroupBox, "Controller" ); m_userController->setGeometry( 10, 24, 200, 22 ); - for( int i = 0; i < Engine::getSong()->controllers().size(); ++i ) + for (Controller * c : Engine::getSong()->controllers()) { - Controller * c = Engine::getSong()->controllers().at( i ); m_userController->model()->addItem( c->name() ); } - + // Mapping functions m_mappingBox = new TabWidget( tr( "MAPPING FUNCTION" ), this );