1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-01-19 07:27:59 +01:00

fix crashes, but deleting controls doesn't work of course :)

This commit is contained in:
Leo Franchi 2011-01-10 23:54:10 -05:00
parent 34799e36e0
commit ee78eb52dd
15 changed files with 78 additions and 21 deletions

View File

@ -156,6 +156,7 @@ void DynamicControlList::removeControl()
{
DynamicControlWidget* w = qobject_cast<DynamicControlWidget*>( sender() );
m_layout->removeWidget( w );
m_controls.removeAll( w );
delete w;
m_controls.last()->setShowCollapseButton( true );

View File

@ -48,7 +48,7 @@ public:
signals:
void controlsChanged();
void controlChanged( const dyncontrol_ptr& control );
void controlChanged( const Tomahawk::dyncontrol_ptr& control );
public slots:
virtual void onHidden(QWidget* );

View File

@ -74,7 +74,7 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
m_collapseL->setCurrentIndex( 0 );
connect( m_collapseButton, SIGNAL( clicked( bool ) ), this, SIGNAL( collapse() ) );
connect( m_typeSelector, SIGNAL( currentIndexChanged( QString ) ), SLOT( typeSelectorChanged( QString ) ) );
connect( m_typeSelector, SIGNAL( activated( QString) ), SLOT( typeSelectorChanged( QString ) ) );
connect( m_control.data(), SIGNAL( changed() ), this, SIGNAL( changed() ) );
m_layout->addWidget( m_typeSelector, 0, Qt::AlignLeft );
@ -84,7 +84,7 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
m_typeSelector->addItem( type );
}
typeSelectorChanged( m_control.isNull() ? "" : m_control->selectedType() );
typeSelectorChanged( m_control.isNull() ? "" : m_control->selectedType(), true );
m_layout->addLayout( m_collapseL, 0 );
m_layout->addLayout( m_plusL, 0 );
@ -101,7 +101,13 @@ DynamicControlWidget::DynamicControlWidget( const Tomahawk::dyncontrol_ptr& cont
DynamicControlWidget::~DynamicControlWidget()
{
// remove the controls widgets from our layout so they are not parented
// we don't want to auto-delete them since the control should own them
// if we delete them, then the control will be holding on to null ptrs
m_layout->removeWidget( m_control->inputField() );
m_control->inputField()->setParent( 0 );
m_layout->removeWidget( m_control->matchSelector() );
m_control->matchSelector()->setParent( 0 );
}
dyncontrol_ptr DynamicControlWidget::control() const
@ -132,13 +138,14 @@ QWidget* DynamicControlWidget::createDummy( QWidget* fromW )
void
DynamicControlWidget::typeSelectorChanged( QString type )
DynamicControlWidget::typeSelectorChanged( const QString& type, bool firstLoad )
{
Q_ASSERT( m_layout );
m_layout->removeWidget( m_control->matchSelector() );
m_layout->removeWidget( m_control->inputField() );
m_control->setSelectedType( type );
if( m_control->selectedType() == type && !firstLoad )
m_control->setSelectedType( type );
if( m_control->matchSelector() ) {
m_layout->insertWidget( 1, m_control->matchSelector(), 0 );

View File

@ -58,7 +58,7 @@ signals:
void changed();
private slots:
void typeSelectorChanged( QString );
void typeSelectorChanged( const QString& selectedType, bool firstLoad = false );
private:
QToolButton* initButton();

View File

@ -84,7 +84,7 @@ DynamicWidget::DynamicWidget( const Tomahawk::dynplaylist_ptr& playlist, QWidget
setLayout( m_layout );
connect( m_controls, SIGNAL( controlChanged( dyncontrol_ptr ) ), this, SLOT( controlChanged( dyncontrol_ptr ) ), Qt::QueuedConnection );
connect( m_controls, SIGNAL( controlChanged( Tomahawk::dyncontrol_ptr ) ), this, SLOT( controlChanged( Tomahawk::dyncontrol_ptr ) ), Qt::QueuedConnection );
connect( m_controls, SIGNAL( controlsChanged() ), this, SLOT( controlsChanged() ), Qt::QueuedConnection );
}
@ -101,6 +101,7 @@ void DynamicWidget::loadDynamicPlaylist(const Tomahawk::dynplaylist_ptr& playlis
m_playlist = playlist;
m_model->loadPlaylist( m_playlist );
if( !m_playlist.isNull() )
m_controls->setControls( m_playlist->generator(), m_playlist->generator()->controls() );
m_modeCombo->setCurrentIndex( static_cast<int>( playlist->mode() ) );

View File

@ -60,7 +60,7 @@ private slots:
void tracksGenerated( const QList< Tomahawk::query_ptr>& queries );
void controlsChanged();
void controlChanged( const dyncontrol_ptr& control );
void controlChanged( const Tomahawk::dyncontrol_ptr& control );
private:
dynplaylist_ptr m_playlist;

View File

@ -65,7 +65,7 @@ DatabaseCommand_LoadDynamicPlaylist::exec( DatabaseImpl* dbi )
c[ "type" ] = type;
c[ "id" ] = controlId;
c[ "selectedType" ] = controlQuery.value( 0 ).toString();
c["match" ] = controlQuery.value( 1 ).toString();
c[ "match" ] = controlQuery.value( 1 ).toString();
c[ "input" ] = controlQuery.value( 2 ).toString();
controls << c;
}

View File

@ -74,7 +74,6 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook()
Q_ASSERT( !playlist.isNull() );
return;
}
if( m_mode == OnDemand )
playlist->setRevision( newrev(),
true, // this *is* the newest revision so far

View File

@ -66,13 +66,13 @@ public:
virtual QWidget* inputField() { Q_ASSERT( false ); return 0; }
/// the serializable value of the match
QString match() const { return m_match; }
virtual QString match() const { Q_ASSERT( false ); return QString(); }
/// the serializable value of the input
QString input() const { return m_input; }
virtual QString input() const { Q_ASSERT( false ); return QString(); }
// used by JSON serialization
void setMatch( const QString& match ) { m_match = match; }
void setInput( const QString& input ) { m_input = input; }
virtual void setMatch( const QString& match ) { Q_ASSERT( false ); }
virtual void setInput( const QString& input ) { Q_ASSERT( false ); }
/// All the potential type selectors for this control
QStringList typeSelectors() const { return m_typeSelectors; }

View File

@ -395,7 +395,7 @@ void
DynamicPlaylist::setRevision( const QString& rev,
bool is_newest_rev,
const QString& type,
const QList< QVariantMap>& controlsV,
const QList< QVariantMap >& controlsV,
bool applied )
{
if( QThread::currentThread() != thread() )

View File

@ -138,7 +138,7 @@ public slots:
const QList<QString>& neworderedguids,
const QList<QString>& oldorderedguids,
const QString& type,
const QList< dyncontrol_ptr >& controls,
const QList< Tomahawk::dyncontrol_ptr >& controls,
bool is_newest_rev,
const QMap< QString, Tomahawk::plentry_ptr >& addedmap,
bool applied );
@ -151,7 +151,7 @@ public slots:
void setRevision( const QString& rev,
bool is_newest_rev,
const QString& type,
const QList< dyncontrol_ptr>& controls,
const QList< Tomahawk::dyncontrol_ptr>& controls,
bool applied );
private:
// called from loadAllPlaylists DB cmd via databasecollection (in GUI thread)

View File

@ -59,6 +59,31 @@ Tomahawk::EchonestControl::toENParam() const
return m_data;
}
QString Tomahawk::EchonestControl::input() const
{
return m_data.second.toString();
}
QString Tomahawk::EchonestControl::match() const
{
return m_matchString;
}
void Tomahawk::EchonestControl::setInput(const QString& input)
{
// TODO generate widgets
m_data.second = input;
updateWidgetsFromData();
}
void Tomahawk::EchonestControl::setMatch(const QString& match)
{
// TODO generate widgets
m_matchString = match;
updateWidgetsFromData();
}
void
Tomahawk::EchonestControl::updateWidgets()
{
@ -101,6 +126,7 @@ Tomahawk::EchonestControl::updateData()
if( selectedType() == "Artist" ) {
QComboBox* combo = qobject_cast<QComboBox*>( m_match.data() );
if( combo ) {
m_matchString = combo->itemData( combo->currentIndex() ).toString();
}
QLineEdit* edit = qobject_cast<QLineEdit*>( m_input.data() );
if( edit && !edit->text().isEmpty() ) {
@ -109,3 +135,17 @@ Tomahawk::EchonestControl::updateData()
}
}
}
// fills in the current widget with the data from json or dbcmd (m_data.second and m_matchString)
void Tomahawk::EchonestControl::updateWidgetsFromData()
{
if( selectedType() == "Artist" ) {
QComboBox* combo = qobject_cast<QComboBox*>( m_match.data() );
if( combo )
combo->setCurrentIndex( combo->findData( m_matchString ) );
QLineEdit* edit = qobject_cast<QLineEdit*>( m_input.data() );
if( edit )
edit->setText( m_data.second.toString() );
}
}

View File

@ -34,6 +34,12 @@ public:
/// Converts this to an echonest suitable parameter
Echonest::DynamicPlaylist::PlaylistParamData toENParam() const;
virtual QString input() const;
virtual QString match() const;
virtual void setInput(const QString& input);
virtual void setMatch(const QString& match);
/// DO NOT USE IF YOU ARE NOT A DBCMD
explicit EchonestControl( const QString& type, const QStringList& typeSelectors, QObject* parent = 0 );
@ -45,11 +51,13 @@ private slots:
private:
void updateWidgets();
void updateWidgetsFromData();
Echonest::DynamicPlaylist::PlaylistParam m_currentType;
QWeakPointer< QWidget > m_input;
QWeakPointer< QWidget > m_match;
QString m_matchString;
Echonest::DynamicPlaylist::PlaylistParamData m_data;

View File

@ -24,7 +24,6 @@ class DLLEXPORT PlaylistEntry : public QObject
Q_OBJECT
Q_PROPERTY( QString guid READ guid WRITE setGuid )
Q_PROPERTY( QString annotation READ annotation WRITE setAnnotation )
Q_PROPERTY( QString resulthint READ resultHint WRITE setResultHint )
Q_PROPERTY( unsigned int duration READ duration WRITE setDuration )
Q_PROPERTY( unsigned int lastmodified READ lastmodified WRITE setLastmodified )
Q_PROPERTY( QVariant query READ queryVariant WRITE setQueryVariant )

View File

@ -273,6 +273,8 @@ TomahawkApp::registerMetaTypes()
qRegisterMetaType< Tomahawk::result_ptr >("Tomahawk::result_ptr");
qRegisterMetaType< Tomahawk::query_ptr >("Tomahawk::query_ptr");
qRegisterMetaType< Tomahawk::source_ptr >("Tomahawk::source_ptr");
qRegisterMetaType< Tomahawk::dyncontrol_ptr >("Tomahawk::dyncontrol_ptr");
qRegisterMetaType< Tomahawk::geninterface_ptr >("Tomahawk::geninterface_ptr");
qRegisterMetaType< QList<Tomahawk::playlist_ptr> >("QList<Tomahawk::playlist_ptr>");
qRegisterMetaType< QList<Tomahawk::dynplaylist_ptr> >("QList<Tomahawk::dynplaylist_ptr>");
qRegisterMetaType< QList<Tomahawk::dyncontrol_ptr> >("QList<Tomahawk::dyncontrol_ptr>");