Expand Up
@@ -40,8 +40,8 @@ struct SmartPLField
int m_defaultValue;
};
static SmartPLField SmartPLFields[] =
{
static const std::array< const SmartPLField, 13 > SmartPLFields
{{
{ " " , " " , ftString, 0 , 0 , 0 },
{ " Artist" , " music_artists.artist_name" , ftString, 0 , 0 , 0 },
{ " Album" , " music_albums.album_name" , ftString, 0 , 0 , 0 },
Expand All
@@ -57,7 +57,7 @@ static SmartPLField SmartPLFields[] =
ftDate, 0 , 0 , 0 },
{ " Date Imported" , " FROM_DAYS(TO_DAYS(music_songs.date_entered))" ,
ftDate, 0 , 0 , 0 },
};
}} ;
struct SmartPLOperator
{
Expand All
@@ -67,8 +67,8 @@ struct SmartPLOperator
bool m_validForBoolean;
};
static SmartPLOperator SmartPLOperators[] =
{
static const std::array< const SmartPLOperator, 11 > SmartPLOperators
{{
{ " is equal to" , 1 , false , true },
{ " is not equal to" , 1 , false , true },
{ " is greater than" , 1 , false , false },
Expand All
@@ -80,27 +80,24 @@ static SmartPLOperator SmartPLOperators[] =
{ " is between" , 2 , false , false },
{ " is set" , 0 , false , false },
{ " is not set" , 0 , false , false },
};
static int SmartPLOperatorsCount = sizeof (SmartPLOperators) / sizeof (SmartPLOperators[0 ]);
static int SmartPLFieldsCount = sizeof (SmartPLFields) / sizeof (SmartPLFields[0 ]);
}};
static SmartPLOperator *lookupOperator (const QString& name)
static const SmartPLOperator *lookupOperator (const QString& name)
{
for (int x = 0 ; x < SmartPLOperatorsCount; x++ )
for (const auto & oper : SmartPLOperators )
{
if (SmartPLOperators[x] .m_name == name)
return &SmartPLOperators[x] ;
if (oper .m_name == name)
return &oper ;
}
return nullptr ;
}
static SmartPLField *lookupField (const QString& name)
static const SmartPLField *lookupField (const QString& name)
{
for (int x = 0 ; x < SmartPLFieldsCount; x++ )
for (const auto & field : SmartPLFields )
{
if (SmartPLFields[x] .m_name == name)
return &SmartPLFields[x] ;
if (field .m_name == name)
return &field ;
}
return nullptr ;
}
Expand Down
Expand Up
@@ -154,15 +151,15 @@ QString getCriteriaSQL(const QString& fieldName, const QString &operatorName,
if (fieldName.isEmpty ())
return result;
SmartPLField *Field = lookupField (fieldName);
const SmartPLField *Field = lookupField (fieldName);
if (!Field)
{
return " " ;
}
result = Field->m_sqlName ;
SmartPLOperator *Operator = lookupOperator (operatorName);
const SmartPLOperator *Operator = lookupOperator (operatorName);
if (!Operator)
{
return QString ();
Expand Down
Expand Up
@@ -251,7 +248,7 @@ QString getOrderBySQL(const QString& orderByFields)
for (int x = 0 ; x < list.count (); x++)
{
fieldName = list[x].trimmed ();
SmartPLField *Field = lookupField (fieldName.left (fieldName.length () - 4 ));
const SmartPLField *Field = lookupField (fieldName.left (fieldName.length () - 4 ));
if (Field)
{
if (fieldName.right (3 ) == " (D)" )
Expand All
@@ -274,7 +271,7 @@ QString getOrderBySQL(const QString& orderByFields)
QString getSQLFieldName (const QString &fieldName)
{
SmartPLField *Field = lookupField (fieldName);
const SmartPLField *Field = lookupField (fieldName);
if (!Field)
{
return " " ;
Expand Down
Expand Up
@@ -328,7 +325,7 @@ bool SmartPLCriteriaRow::saveToDatabase(int smartPlaylistID) const
QString SmartPLCriteriaRow::toString (void ) const
{
SmartPLOperator *PLOperator = lookupOperator (m_operator);
const SmartPLOperator *PLOperator = lookupOperator (m_operator);
if (PLOperator)
{
QString result;
Expand Down
Expand Up
@@ -397,12 +394,12 @@ bool SmartPlaylistEditor::Create(void)
new MythUIButtonListItem (m_matchSelector, tr (" Any" ));
connect (m_matchSelector, SIGNAL (itemSelected (MythUIButtonListItem*)), SLOT (updateMatches ()));
for (int x = 0 ; x < SmartPLFieldsCount; x++ )
for (const auto & field : SmartPLFields )
{
if (SmartPLFields[x] .m_name == " " )
new MythUIButtonListItem (m_orderBySelector, SmartPLFields[x] .m_name );
if (field .m_name == " " )
new MythUIButtonListItem (m_orderBySelector, field .m_name );
else
new MythUIButtonListItem (m_orderBySelector, SmartPLFields[x] .m_name + " (A)" );
new MythUIButtonListItem (m_orderBySelector, field .m_name + " (A)" );
}
m_limitSpin->SetRange (0 , 9999 , 10 );
Expand Down
Expand Up
@@ -1257,16 +1254,16 @@ bool CriteriaRowEditor::Create(void)
void CriteriaRowEditor::updateFields (void )
{
for (int x = 0 ; x < SmartPLFieldsCount; x++ )
new MythUIButtonListItem (m_fieldSelector, SmartPLFields[x] .m_name );
for (const auto & field : SmartPLFields )
new MythUIButtonListItem (m_fieldSelector, field .m_name );
m_fieldSelector->SetValue (m_criteriaRow->m_field );
}
void CriteriaRowEditor::updateOperators (void )
{
for (int x = 0 ; x < SmartPLOperatorsCount; x++ )
new MythUIButtonListItem (m_operatorSelector, SmartPLOperators[x] .m_name );
for (const auto & oper : SmartPLOperators )
new MythUIButtonListItem (m_operatorSelector, oper .m_name );
m_operatorSelector->SetValue (m_criteriaRow->m_operator );
}
Expand Down
Expand Up
@@ -1300,7 +1297,7 @@ void CriteriaRowEditor::updateValues(void)
void CriteriaRowEditor::saveClicked ()
{
SmartPLField *Field = lookupField (m_fieldSelector->GetValue ());
const SmartPLField *Field = lookupField (m_fieldSelector->GetValue ());
if (!Field)
return ;
Expand Down
Expand Up
@@ -1333,9 +1330,9 @@ void CriteriaRowEditor::enableSaveButton()
{
bool enabled = false ;
SmartPLField *Field = lookupField (m_fieldSelector->GetValue ());
const SmartPLField *Field = lookupField (m_fieldSelector->GetValue ());
SmartPLOperator *Operator = lookupOperator (m_operatorSelector->GetValue ());
const SmartPLOperator *Operator = lookupOperator (m_operatorSelector->GetValue ());
if (Field && Operator)
{
Expand Down
Expand Up
@@ -1364,7 +1361,7 @@ void CriteriaRowEditor::enableSaveButton()
void CriteriaRowEditor::fieldChanged (void )
{
SmartPLField *Field = lookupField (m_fieldSelector->GetValue ());
const SmartPLField *Field = lookupField (m_fieldSelector->GetValue ());
if (!Field)
return ;
Expand Down
Expand Up
@@ -1415,11 +1412,11 @@ void CriteriaRowEditor::fieldChanged(void)
void CriteriaRowEditor::operatorChanged (void )
{
SmartPLField *Field = lookupField (m_fieldSelector->GetValue ());
const SmartPLField *Field = lookupField (m_fieldSelector->GetValue ());
if (!Field)
return ;
SmartPLOperator *Operator = lookupOperator (m_operatorSelector->GetValue ());
const SmartPLOperator *Operator = lookupOperator (m_operatorSelector->GetValue ());
if (!Operator)
return ;
Expand Down
Expand Up
@@ -1499,17 +1496,17 @@ void CriteriaRowEditor::getOperatorList(SmartPLFieldType fieldType)
m_operatorSelector->Reset ();
for (int x = 0 ; x < SmartPLOperatorsCount; x++ )
for (const auto & oper : SmartPLOperators )
{
// don't add operators that only work with string fields
if (fieldType != ftString && SmartPLOperators[x] .m_stringOnly )
if (fieldType != ftString && oper .m_stringOnly )
continue ;
// don't add operators that only work with boolean fields
if (fieldType == ftBoolean && !SmartPLOperators[x] .m_validForBoolean )
if (fieldType == ftBoolean && !oper .m_validForBoolean )
continue ;
new MythUIButtonListItem (m_operatorSelector, SmartPLOperators[x] .m_name );
new MythUIButtonListItem (m_operatorSelector, oper .m_name );
}
// try to set the operatorCombo to the same operator or else the first item
Expand Down
Expand Up
@@ -1959,8 +1956,8 @@ void SmartPLOrderByDialog::orderByChanged(void)
void SmartPLOrderByDialog::getOrderByFields (void )
{
m_orderSelector->Reset ();
for (int x = 1 ; x < SmartPLFieldsCount; x++ )
new MythUIButtonListItem (m_orderSelector, SmartPLFields[x] .m_name );
for (const auto & field : SmartPLFields )
new MythUIButtonListItem (m_orderSelector, field .m_name );
}
/*
Expand Down