Set the "group_by" properties of the actions in code instead of in the .ui file, so the enum keys don't get translated.
This commit is contained in:
parent
48270bfeec
commit
ae3923f93b
@ -814,15 +814,6 @@ void Library::SetGroupBy(const Grouping& g) {
|
||||
emit GroupingChanged(g);
|
||||
}
|
||||
|
||||
QMetaEnum Library::GroupByEnum() const {
|
||||
const QMetaObject* o = metaObject();
|
||||
for (int i=0 ; i<o->enumeratorCount() ; ++i) {
|
||||
if (o->enumerator(i).name() == QString("GroupBy"))
|
||||
return o->enumerator(i);
|
||||
}
|
||||
return QMetaEnum();
|
||||
}
|
||||
|
||||
const Library::GroupBy& Library::Grouping::operator [](int i) const {
|
||||
switch (i) {
|
||||
case 0: return first;
|
||||
|
@ -59,11 +59,12 @@ class Library : public SimpleTreeModel<LibraryItem> {
|
||||
GroupBy_Composer = 5,
|
||||
GroupBy_Genre = 6,
|
||||
};
|
||||
QMetaEnum GroupByEnum() const;
|
||||
|
||||
struct Grouping {
|
||||
Grouping() : first(GroupBy_None), second(GroupBy_None), third(GroupBy_None) {}
|
||||
Grouping(GroupBy f, GroupBy s, GroupBy t) : first(f), second(s), third(t) {}
|
||||
Grouping(GroupBy f = GroupBy_None,
|
||||
GroupBy s = GroupBy_None,
|
||||
GroupBy t = GroupBy_None)
|
||||
: first(f), second(s), third(t) {}
|
||||
|
||||
GroupBy first;
|
||||
GroupBy second;
|
||||
@ -71,6 +72,11 @@ class Library : public SimpleTreeModel<LibraryItem> {
|
||||
|
||||
const GroupBy& operator [](int i) const;
|
||||
GroupBy& operator [](int i);
|
||||
bool operator ==(const Grouping& other) const {
|
||||
return first == other.first &&
|
||||
second == other.second &&
|
||||
third == other.third;
|
||||
}
|
||||
};
|
||||
|
||||
// Useful for tests. The library takes ownership.
|
||||
@ -197,4 +203,6 @@ class Library : public SimpleTreeModel<LibraryItem> {
|
||||
QIcon no_cover_icon_;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(Library::Grouping);
|
||||
|
||||
#endif // LIBRARY_H
|
||||
|
@ -236,6 +236,19 @@ MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
||||
connect(ui_.library_filter_clear, SIGNAL(clicked()), SLOT(ClearLibraryFilter()));
|
||||
|
||||
// "Group by ..."
|
||||
ui_.group_by_artist->setProperty("group_by", QVariant::fromValue(
|
||||
Library::Grouping(Library::GroupBy_Artist)));
|
||||
ui_.group_by_artist_album->setProperty("group_by", QVariant::fromValue(
|
||||
Library::Grouping(Library::GroupBy_Artist, Library::GroupBy_Album)));
|
||||
ui_.group_by_artist_yearalbum->setProperty("group_by", QVariant::fromValue(
|
||||
Library::Grouping(Library::GroupBy_Artist, Library::GroupBy_YearAlbum)));
|
||||
ui_.group_by_album->setProperty("group_by", QVariant::fromValue(
|
||||
Library::Grouping(Library::GroupBy_Album)));
|
||||
ui_.group_by_genre_album->setProperty("group_by", QVariant::fromValue(
|
||||
Library::Grouping(Library::GroupBy_Genre, Library::GroupBy_Album)));
|
||||
ui_.group_by_genre_artist_album->setProperty("group_by", QVariant::fromValue(
|
||||
Library::Grouping(Library::GroupBy_Genre, Library::GroupBy_Artist, Library::GroupBy_Album)));
|
||||
|
||||
group_by_group_ = new QActionGroup(this);
|
||||
group_by_group_->addAction(ui_.group_by_artist);
|
||||
group_by_group_->addAction(ui_.group_by_artist_album);
|
||||
@ -812,19 +825,12 @@ void MainWindow::PlaylistRemoveCurrent() {
|
||||
}
|
||||
|
||||
void MainWindow::GroupByClicked(QAction* action) {
|
||||
Library::Grouping g;
|
||||
|
||||
QStringList group_by = action->property("group_by").toStringList();
|
||||
if (group_by.isEmpty()) {
|
||||
if (action->property("group_by").isNull()) {
|
||||
group_by_dialog_->show();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i=0 ; i<group_by.size() ; ++i) {
|
||||
g[i] = Library::GroupBy(
|
||||
library_->GroupByEnum().keyToValue(group_by[i].toUtf8().constData()));
|
||||
}
|
||||
|
||||
Library::Grouping g = action->property("group_by").value<Library::Grouping>();
|
||||
library_->SetGroupBy(g);
|
||||
}
|
||||
|
||||
@ -836,16 +842,10 @@ void MainWindow::LibraryGroupingChanged(const Library::Grouping& g) {
|
||||
|
||||
// Now make sure the correct action is checked
|
||||
foreach (QAction* action, group_by_group_->actions()) {
|
||||
QStringList group_by = action->property("group_by").toStringList();
|
||||
bool match = true;
|
||||
for (int i=0 ; i<group_by.size() ; ++i) {
|
||||
if (g[i] != library_->GroupByEnum().keyToValue(group_by[i].toUtf8().constData())) {
|
||||
match = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (action->property("group_by").isNull())
|
||||
continue;
|
||||
|
||||
if (match) {
|
||||
if (g == action->property("group_by").value<Library::Grouping>()) {
|
||||
action->setChecked(true);
|
||||
return;
|
||||
}
|
||||
|
@ -763,13 +763,6 @@
|
||||
<property name="text">
|
||||
<string>Group by Artist</string>
|
||||
</property>
|
||||
<property name="group_by" stdset="0">
|
||||
<stringlist>
|
||||
<string>GroupBy_Artist</string>
|
||||
<string>GroupBy_None</string>
|
||||
<string>GroupBy_None</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</action>
|
||||
<action name="group_by_artist_album">
|
||||
<property name="checkable">
|
||||
@ -778,13 +771,6 @@
|
||||
<property name="text">
|
||||
<string>Group by Artist/Album</string>
|
||||
</property>
|
||||
<property name="group_by" stdset="0">
|
||||
<stringlist>
|
||||
<string>GroupBy_Artist</string>
|
||||
<string>GroupBy_Album</string>
|
||||
<string>GroupBy_None</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</action>
|
||||
<action name="group_by_artist_yearalbum">
|
||||
<property name="checkable">
|
||||
@ -793,13 +779,6 @@
|
||||
<property name="text">
|
||||
<string>Group by Artist/Year - Album</string>
|
||||
</property>
|
||||
<property name="group_by" stdset="0">
|
||||
<stringlist>
|
||||
<string>GroupBy_Artist</string>
|
||||
<string>GroupBy_YearAlbum</string>
|
||||
<string>GroupBy_None</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</action>
|
||||
<action name="group_by_album">
|
||||
<property name="checkable">
|
||||
@ -808,13 +787,6 @@
|
||||
<property name="text">
|
||||
<string>Group by Album</string>
|
||||
</property>
|
||||
<property name="group_by" stdset="0">
|
||||
<stringlist>
|
||||
<string>GroupBy_Album</string>
|
||||
<string>GroupBy_None</string>
|
||||
<string>GroupBy_None</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</action>
|
||||
<action name="group_by_genre_album">
|
||||
<property name="checkable">
|
||||
@ -823,13 +795,6 @@
|
||||
<property name="text">
|
||||
<string>Group by Genre/Album</string>
|
||||
</property>
|
||||
<property name="group_by" stdset="0">
|
||||
<stringlist>
|
||||
<string>GroupBy_Genre</string>
|
||||
<string>GroupBy_Album</string>
|
||||
<string>GroupBy_None</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</action>
|
||||
<action name="group_by_genre_artist_album">
|
||||
<property name="checkable">
|
||||
@ -838,13 +803,6 @@
|
||||
<property name="text">
|
||||
<string>Group by Genre/Artist/Album</string>
|
||||
</property>
|
||||
<property name="group_by" stdset="0">
|
||||
<stringlist>
|
||||
<string>GroupBy_Genre</string>
|
||||
<string>GroupBy_Artist</string>
|
||||
<string>GroupBy_Album</string>
|
||||
</stringlist>
|
||||
</property>
|
||||
</action>
|
||||
<action name="group_by_advanced">
|
||||
<property name="checkable">
|
||||
|
Loading…
x
Reference in New Issue
Block a user