In the smart playlist wizard, only repopulate the op combo box when changing to a field of a different type.

This commit is contained in:
David Sansome 2012-12-10 19:37:38 +11:00
parent 82575f233f
commit 14c07cbaed
4 changed files with 34 additions and 20 deletions

View File

@ -138,11 +138,12 @@ bool SearchTerm::is_valid() const {
}
switch (TypeOf(field_)) {
case Type_Text: return !value_.toString().isEmpty();
case Type_Date: return value_.toInt() != 0;
case Type_Number: return value_.toInt() >= 0;
case Type_Rating: return value_.toFloat() >= 0.0;
case Type_Time: return true;
case Type_Text: return !value_.toString().isEmpty();
case Type_Date: return value_.toInt() != 0;
case Type_Number: return value_.toInt() >= 0;
case Type_Rating: return value_.toFloat() >= 0.0;
case Type_Time: return true;
case Type_Invalid: return false;
}
return false;
}
@ -289,11 +290,12 @@ QString SearchTerm::FieldName(Field field) {
QString SearchTerm::FieldSortOrderText(Type type, bool ascending) {
switch (type) {
case Type_Text: return ascending ? QObject::tr("A-Z") : QObject::tr("Z-A");
case Type_Date: return ascending ? QObject::tr("oldest first") : QObject::tr("newest first");
case Type_Time: return ascending ? QObject::tr("shortest first") : QObject::tr("longest first");
case Type_Text: return ascending ? QObject::tr("A-Z") : QObject::tr("Z-A");
case Type_Date: return ascending ? QObject::tr("oldest first") : QObject::tr("newest first");
case Type_Time: return ascending ? QObject::tr("shortest first") : QObject::tr("longest first");
case Type_Number:
case Type_Rating: return ascending ? QObject::tr("smallest first") : QObject::tr("biggest first");
case Type_Rating: return ascending ? QObject::tr("smallest first") : QObject::tr("biggest first");
case Type_Invalid: return QString();
}
return QString();
}

View File

@ -85,6 +85,8 @@ public:
Type_Time,
Type_Number,
Type_Rating,
Type_Invalid
};
// These values are persisted, so add to the end of the enum only

View File

@ -69,7 +69,8 @@ SearchTermWidget::SearchTermWidget(LibraryBackend* library, QWidget* parent)
overlay_(NULL),
animation_(new QPropertyAnimation(this, "overlay_opacity", this)),
active_(true),
initialized_(false)
initialized_(false),
current_field_type_(SearchTerm::Type_Invalid)
{
ui_->setupUi(this);
connect(ui_->field, SIGNAL(currentIndexChanged(int)), SLOT(FieldChanged(int)));
@ -130,21 +131,25 @@ void SearchTermWidget::FieldChanged(int index) {
SearchTerm::Type type = SearchTerm::TypeOf(field);
// Populate the operator combo box
ui_->op->clear();
foreach (SearchTerm::Operator op, SearchTerm::OperatorsForType(type)) {
const int i = ui_->op->count();
ui_->op->addItem(SearchTerm::OperatorText(type, op));
ui_->op->setItemData(i, op);
if (type != current_field_type_) {
ui_->op->clear();
foreach (SearchTerm::Operator op, SearchTerm::OperatorsForType(type)) {
const int i = ui_->op->count();
ui_->op->addItem(SearchTerm::OperatorText(type, op));
ui_->op->setItemData(i, op);
}
current_field_type_ = type;
}
// Show the correct value editor
QWidget* page = NULL;
switch (type) {
case SearchTerm::Type_Time: page = ui_->page_time; break;
case SearchTerm::Type_Number: page = ui_->page_number; break;
case SearchTerm::Type_Date: page = ui_->page_date; break;
case SearchTerm::Type_Rating: page = ui_->page_rating; break;
case SearchTerm::Type_Text: page = ui_->page_text; break;
case SearchTerm::Type_Time: page = ui_->page_time; break;
case SearchTerm::Type_Number: page = ui_->page_number; break;
case SearchTerm::Type_Date: page = ui_->page_date; break;
case SearchTerm::Type_Rating: page = ui_->page_rating; break;
case SearchTerm::Type_Text: page = ui_->page_text; break;
case SearchTerm::Type_Invalid: page = NULL; break;
}
ui_->value_stack->setCurrentWidget(page);
@ -275,6 +280,9 @@ void SearchTermWidget::SetTerm(const SearchTerm& term) {
case SearchTerm::Type_Rating:
ui_->value_rating->set_rating(term.value_.toFloat());
break;
case SearchTerm::Type_Invalid:
break;
}
}

View File

@ -77,6 +77,8 @@ private:
QPropertyAnimation* animation_;
bool active_;
bool initialized_;
SearchTerm::Type current_field_type_;
};
} // namespace