AutomatableModelView: adopted new coding style

This commit is contained in:
Tobias Doerffel
2014-01-16 00:00:53 +01:00
parent 17c1ede50c
commit b4030478c3
2 changed files with 90 additions and 119 deletions

View File

@@ -34,43 +34,43 @@ class QMenu;
class EXPORT AutomatableModelView : public ModelView
{
public:
AutomatableModelView( Model * _model, QWidget * _this );
AutomatableModelView( Model* model, QWidget* _this );
virtual ~AutomatableModelView();
// some basic functions for convenience
AutomatableModel * modelUntyped()
AutomatableModel* modelUntyped()
{
return( castModel<AutomatableModel>() );
return castModel<AutomatableModel>();
}
const AutomatableModel * modelUntyped() const
const AutomatableModel* modelUntyped() const
{
return( castModel<AutomatableModel>() );
return castModel<AutomatableModel>();
}
virtual void setModel( Model * _model, bool _old_model_valid = true );
virtual void setModel( Model* model, bool isOldModelValid = true );
template<typename T>
inline T value() const
{
return( modelUntyped() ? modelUntyped()->value<T>() : 0 );
return modelUntyped() ? modelUntyped()->value<T>() : 0;
}
inline void setDescription( const QString & _desc )
inline void setDescription( const QString& desc )
{
m_description = _desc;
m_description = desc;
}
inline void setUnit( const QString & _unit )
inline void setUnit( const QString& unit )
{
m_unit = _unit;
m_unit = unit;
}
void addDefaultActions( QMenu * _menu );
void addDefaultActions( QMenu* menu );
protected:
virtual void mousePressEvent( QMouseEvent * _ev );
virtual void mousePressEvent( QMouseEvent* event );
QString m_description;
QString m_unit;
@@ -84,9 +84,7 @@ class AutomatableModelViewSlots : public QObject
{
Q_OBJECT
public:
AutomatableModelViewSlots(
AutomatableModelView * _amv,
QObject * _parent );
AutomatableModelViewSlots( AutomatableModelView* amv, QObject* parent );
public slots:
void execConnectionDialog();
@@ -97,7 +95,7 @@ public slots:
protected:
AutomatableModelView * amv;
AutomatableModelView* m_amv;
} ;
@@ -108,19 +106,19 @@ protected:
class EXPORT type##ModelView : public AutomatableModelView \
{ \
public: \
type##ModelView( Model * _model, QWidget * _this ) : \
AutomatableModelView( _model, _this ) \
type##ModelView( Model* model, QWidget* _this ) : \
AutomatableModelView( model, _this ) \
{ \
} \
\
type##Model * model() \
type##Model* model() \
{ \
return( castModel<type##Model>() ); \
return castModel<type##Model>(); \
} \
\
const type##Model * model() const \
const type##Model* model() const \
{ \
return( castModel<type##Model>() ); \
return castModel<type##Model>(); \
} \
}

View File

@@ -1,7 +1,7 @@
/*
* AutomatableModelView.cpp - implementation of AutomatableModelView
*
* Copyright (c) 2011-2013 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2011-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
@@ -35,9 +35,8 @@
AutomatableModelView::AutomatableModelView( ::Model * _model,
QWidget * _this ) :
ModelView( _model, _this ),
AutomatableModelView::AutomatableModelView( ::Model* model, QWidget* _this ) :
ModelView( model, _this ),
m_description( QString::null ),
m_unit( QString::null )
{
@@ -55,117 +54,102 @@ AutomatableModelView::~AutomatableModelView()
void AutomatableModelView::addDefaultActions( QMenu * _menu )
void AutomatableModelView::addDefaultActions( QMenu* menu )
{
AutomatableModel * _model = modelUntyped();
AutomatableModel* model = modelUntyped();
AutomatableModelViewSlots * amvSlots =
new AutomatableModelViewSlots( this, _menu );
_menu->addAction( embed::getIconPixmap( "reload" ),
AutomatableModel::tr( "&Reset (%1%2)" ).
arg( _model->displayValue(
_model->initValue<float>() ) ).
arg( m_unit ),
_model, SLOT( reset() ) );
AutomatableModelViewSlots* amvSlots = new AutomatableModelViewSlots( this, menu );
_menu->addSeparator();
_menu->addAction( embed::getIconPixmap( "edit_copy" ),
AutomatableModel::tr( "&Copy value (%1%2)" ).
arg( _model->displayValue(
_model->value<float>() ) ).
arg( m_unit ),
_model, SLOT( copyValue() ) );
_menu->addAction( embed::getIconPixmap( "edit_paste" ),
AutomatableModel::tr( "&Paste value (%1%2)").
arg( _model->displayValue(
AutomatableModel::copiedValue() ) ).
arg( m_unit ),
_model, SLOT( pasteValue() ) );
menu->addAction( embed::getIconPixmap( "reload" ),
AutomatableModel::tr( "&Reset (%1%2)" ).
arg( model->displayValue( model->initValue<float>() ) ).
arg( m_unit ),
model, SLOT( reset() ) );
_menu->addSeparator();
menu->addSeparator();
menu->addAction( embed::getIconPixmap( "edit_copy" ),
AutomatableModel::tr( "&Copy value (%1%2)" ).
arg( model->displayValue( model->value<float>() ) ).
arg( m_unit ),
model, SLOT( copyValue() ) );
_menu->addAction( embed::getIconPixmap( "automation" ),
AutomatableModel::tr( "Edit song-global automation" ),
amvSlots,
SLOT( editSongGlobalAutomation() ) );
menu->addAction( embed::getIconPixmap( "edit_paste" ),
AutomatableModel::tr( "&Paste value (%1%2)").
arg( model->displayValue( AutomatableModel::copiedValue() ) ).
arg( m_unit ),
model, SLOT( pasteValue() ) );
_menu->addAction( QPixmap(),
AutomatableModel::tr( "Remove song-global automation" ),
amvSlots,
SLOT( removeSongGlobalAutomation() ) );
menu->addSeparator();
_menu->addSeparator();
menu->addAction( embed::getIconPixmap( "automation" ),
AutomatableModel::tr( "Edit song-global automation" ),
amvSlots,
SLOT( editSongGlobalAutomation() ) );
if( _model->hasLinkedModels() )
menu->addAction( QPixmap(),
AutomatableModel::tr( "Remove song-global automation" ),
amvSlots,
SLOT( removeSongGlobalAutomation() ) );
menu->addSeparator();
if( model->hasLinkedModels() )
{
_menu->addAction( embed::getIconPixmap( "edit-delete" ),
menu->addAction( embed::getIconPixmap( "edit-delete" ),
AutomatableModel::tr( "Remove all linked controls" ),
amvSlots, SLOT( unlinkAllModels() ) );
_menu->addSeparator();
menu->addSeparator();
}
QString controllerTxt;
if( _model->getControllerConnection() )
if( model->getControllerConnection() )
{
Controller * cont = _model->getControllerConnection()->
getController();
Controller* cont = model->getControllerConnection()->getController();
if( cont )
{
controllerTxt =
AutomatableModel::tr( "Connected to %1" ).
arg( cont->name() );
controllerTxt = AutomatableModel::tr( "Connected to %1" ).arg( cont->name() );
}
else
{
controllerTxt = AutomatableModel::tr(
"Connected to controller" );
controllerTxt = AutomatableModel::tr( "Connected to controller" );
}
QMenu * contMenu = _menu->addMenu(
embed::getIconPixmap( "controller" ),
controllerTxt );
QMenu* contMenu = menu->addMenu( embed::getIconPixmap( "controller" ), controllerTxt );
contMenu->addAction( embed::getIconPixmap( "controller" ),
AutomatableModel::tr("Edit connection..."),
amvSlots,
SLOT( execConnectionDialog() ) );
AutomatableModel::tr("Edit connection..."),
amvSlots, SLOT( execConnectionDialog() ) );
contMenu->addAction( embed::getIconPixmap( "cancel" ),
AutomatableModel::tr("Remove connection"),
amvSlots,
SLOT( removeConnection() ) );
AutomatableModel::tr("Remove connection"),
amvSlots, SLOT( removeConnection() ) );
}
else
{
_menu->addAction( embed::getIconPixmap( "controller" ),
AutomatableModel::tr("Connect to controller..."),
amvSlots,
SLOT( execConnectionDialog() ) );
menu->addAction( embed::getIconPixmap( "controller" ),
AutomatableModel::tr("Connect to controller..."),
amvSlots, SLOT( execConnectionDialog() ) );
}
}
void AutomatableModelView::setModel( Model * _model, bool _old_model_valid )
void AutomatableModelView::setModel( Model* model, bool isOldModelValid )
{
ModelView::setModel( _model, _old_model_valid );
ModelView::setModel( model, isOldModelValid );
}
void AutomatableModelView::mousePressEvent( QMouseEvent * _me )
void AutomatableModelView::mousePressEvent( QMouseEvent* event )
{
if( _me->button() == Qt::LeftButton &&
_me->modifiers() & Qt::ControlModifier )
if( event->button() == Qt::LeftButton && event->modifiers() & Qt::ControlModifier )
{
new stringPairDrag( "automatable_model",
QString::number( modelUntyped()->id() ),
QPixmap(), widget() );
_me->accept();
new stringPairDrag( "automatable_model", QString::number( modelUntyped()->id() ), QPixmap(), widget() );
event->accept();
}
else if( _me->button() == Qt::MidButton )
else if( event->button() == Qt::MidButton )
{
modelUntyped()->reset();
}
@@ -176,15 +160,11 @@ void AutomatableModelView::mousePressEvent( QMouseEvent * _me )
AutomatableModelViewSlots::AutomatableModelViewSlots(
AutomatableModelView * _amv,
QObject * _parent ) :
AutomatableModelViewSlots::AutomatableModelViewSlots( AutomatableModelView* amv, QObject* parent ) :
QObject(),
amv( _amv )
m_amv( amv )
{
QObject::connect( _parent, SIGNAL( destroyed() ),
this, SLOT( deleteLater() ),
Qt::QueuedConnection );
connect( parent, SIGNAL( destroyed() ), this, SLOT( deleteLater() ), Qt::QueuedConnection );
}
@@ -194,31 +174,27 @@ void AutomatableModelViewSlots::execConnectionDialog()
{
// TODO[pg]: Display a dialog with list of controllers currently in the song
// in addition to any system MIDI controllers
AutomatableModel * m = amv->modelUntyped();
AutomatableModel* m = m_amv->modelUntyped();
m->displayName();
ControllerConnectionDialog * d = new ControllerConnectionDialog(
(QWidget*)engine::mainWindow(), m );
ControllerConnectionDialog d( (QWidget*) engine::mainWindow(), m );
if( d->exec() == 1)
if( d.exec() == 1 )
{
// Actually chose something
if (d->chosenController() != NULL )
if( d.chosenController() )
{
// Update
if( m->getControllerConnection() )
{
m->getControllerConnection()->
setController( d->chosenController() );
m->getControllerConnection()->setController( d.chosenController() );
}
// New
else
{
ControllerConnection * cc =
new ControllerConnection( d->chosenController() );
ControllerConnection* cc = new ControllerConnection( d.chosenController() );
m->setControllerConnection( cc );
//cc->setTargetName( m->displayName() );
}
}
// no controller, so delete existing connection
@@ -227,8 +203,6 @@ void AutomatableModelViewSlots::execConnectionDialog()
removeConnection();
}
}
delete d;
}
@@ -236,7 +210,7 @@ void AutomatableModelViewSlots::execConnectionDialog()
void AutomatableModelViewSlots::removeConnection()
{
AutomatableModel * m = amv->modelUntyped();
AutomatableModel* m = m_amv->modelUntyped();
if( m->getControllerConnection() )
{
@@ -250,21 +224,20 @@ void AutomatableModelViewSlots::removeConnection()
void AutomatableModelViewSlots::editSongGlobalAutomation()
{
AutomationPattern::globalAutomationPattern( amv->modelUntyped() )->
openInAutomationEditor();
AutomationPattern::globalAutomationPattern( m_amv->modelUntyped() )->openInAutomationEditor();
}
void AutomatableModelViewSlots::removeSongGlobalAutomation()
{
delete AutomationPattern::globalAutomationPattern( amv->modelUntyped() );
delete AutomationPattern::globalAutomationPattern( m_amv->modelUntyped() );
}
void AutomatableModelViewSlots::unlinkAllModels()
{
amv->modelUntyped()->unlinkAllModels();
m_amv->modelUntyped()->unlinkAllModels();
}