1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

don't change type and delete widgets unless we have to

fixes improper loading of input
This commit is contained in:
Leo Franchi
2011-01-16 14:10:03 -05:00
parent 893a200b8e
commit b68d8a3529
4 changed files with 27 additions and 13 deletions

View File

@@ -166,7 +166,7 @@ DynamicControlWidget::typeSelectorChanged( const QString& type, bool firstLoad )
m_typeSelector->setLabel( type );
if( m_control->matchSelector() ) {
m_matchSelector->setWritableWidget( m_control->matchSelector() );
m_matchSelector->setLabel( m_control->match() );
m_matchSelector->setLabel( m_control->matchString() );
m_matchSelector->setWritable( m_isLocal );
m_layout->insertWidget( 1, m_matchSelector, 0 );
}

View File

@@ -65,6 +65,9 @@ public:
*/
virtual QWidget* inputField() { Q_ASSERT( false ); return 0; }
/// The user-readable match value, for showing in read-only playlists
virtual QString matchString() { Q_ASSERT( false ); return QString(); }
/// the serializable value of the match
virtual QString match() const { Q_ASSERT( false ); return QString(); }
/// the serializable value of the input

View File

@@ -44,13 +44,15 @@ Tomahawk::EchonestControl::matchSelector()
void
Tomahawk::EchonestControl::setSelectedType ( const QString& type )
{
if( !m_input.isNull() )
delete m_input.data();
if( !m_match.isNull() )
delete m_match.data();
if( type != selectedType() ) {
if( !m_input.isNull() )
delete m_input.data();
if( !m_match.isNull() )
delete m_match.data();
Tomahawk::DynamicControl::setSelectedType ( type );
updateWidgets();
Tomahawk::DynamicControl::setSelectedType ( type );
updateWidgets();
}
}
Echonest::DynamicPlaylist::PlaylistParamData
@@ -65,10 +67,16 @@ QString Tomahawk::EchonestControl::input() const
}
QString Tomahawk::EchonestControl::match() const
{
return m_matchData;
}
QString Tomahawk::EchonestControl::matchString()
{
return m_matchString;
}
void Tomahawk::EchonestControl::setInput(const QString& input)
{
// TODO generate widgets
@@ -79,7 +87,7 @@ void Tomahawk::EchonestControl::setInput(const QString& input)
void Tomahawk::EchonestControl::setMatch(const QString& match)
{
// TODO generate widgets
m_matchString = match;
m_matchData = match;
updateWidgetsFromData();
}
@@ -101,7 +109,7 @@ Tomahawk::EchonestControl::updateWidgets()
match->addItem( "Limit To", Echonest::DynamicPlaylist::ArtistType );
match->addItem( "Similar To", Echonest::DynamicPlaylist::ArtistRadioType );
m_matchString = match->itemText( 0 );
m_matchString = match->currentText();
input->setPlaceholderText( "Artist name" );
input->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed );
@@ -127,7 +135,8 @@ Tomahawk::EchonestControl::updateData()
if( selectedType() == "Artist" ) {
QComboBox* combo = qobject_cast<QComboBox*>( m_match.data() );
if( combo ) {
m_matchString = combo->itemData( combo->currentIndex() ).toString();
m_matchString = combo->currentText();
m_matchData = combo->itemData( combo->currentIndex() ).toString();
}
QLineEdit* edit = qobject_cast<QLineEdit*>( m_input.data() );
if( edit && !edit->text().isEmpty() ) {
@@ -137,13 +146,13 @@ Tomahawk::EchonestControl::updateData()
}
}
// fills in the current widget with the data from json or dbcmd (m_data.second and m_matchString)
// fills in the current widget with the data from json or dbcmd (m_data.second and m_matchData)
void Tomahawk::EchonestControl::updateWidgetsFromData()
{
if( selectedType() == "Artist" ) {
QComboBox* combo = qobject_cast<QComboBox*>( m_match.data() );
if( combo )
combo->setCurrentIndex( combo->findData( m_matchString ) );
combo->setCurrentIndex( combo->findData( m_matchData ) );
QLineEdit* edit = qobject_cast<QLineEdit*>( m_input.data() );
if( edit )
edit->setText( m_data.second.toString() );

View File

@@ -36,6 +36,7 @@ public:
virtual QString input() const;
virtual QString match() const;
virtual QString matchString();
virtual void setInput(const QString& input);
virtual void setMatch(const QString& match);
@@ -57,6 +58,7 @@ private:
QWeakPointer< QWidget > m_input;
QWeakPointer< QWidget > m_match;
QString m_matchData;
QString m_matchString;
Echonest::DynamicPlaylist::PlaylistParamData m_data;