New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: remember library sorting #947
Conversation
@@ -21,7 +21,7 @@ | |||
#include "util/assert.h" | |||
#include "util/performancetimer.h" | |||
|
|||
static const bool sDebug = false; | |||
static const bool sDebug = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep this one off since it produces a ton of verbose logging.
Travis fails unrelated to this PR:
|
@@ -139,6 +139,23 @@ class BaseSqlTableModel : public QAbstractTableModel, public TrackModel { | |||
} | |||
int m_column; | |||
Qt::SortOrder m_order; | |||
|
|||
friend QTextStream& operator >> (QTextStream &in, SortColumn &sc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing the columns as integers means we can't make changes to the column orderings in the future since they are stored in user databases. Could you store them as column names instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'll change that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid we hit a conceptual issue. :-/
The current solution is a simple serialize without ans sanity checks. The same we have with the header state.
Since this is not that critical data, that "could" work as it is, including all issues we already heave.
If not, we should should probably ditch the SettingsDAO entirely and move to mixxx.cfg, which allows us to parse and check the values before using. .. and is human readable.
@jmigual and @rryan: What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if we save the column name as a string this should solve the problem. It is true that there are no sanity checks but this can only be a problem if we change the name or remove a column that the user has previously sorted but once she tries to sort again and restarts mixxx the problem solves (when I changed from integers to strings I had this problem and I forced sorting and restarted and then it worked fine again)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am afraid we hit a conceptual issue. :-/
The current solution is a simple serialize without ans sanity checks. The same we have with the header state.Since this is not that critical data, that "could" work as it is, including all issues we already heave.
I would prefer to treat user data as "sacred" -- if we decide to save something we should save it in a future-proof manner or not save it at all :).
If not, we should should probably ditch the SettingsDAO entirely and move to mixxx.cfg, which allows us to parse and check the values before using. .. and is human readable.
SettingsDAO and mixxx.cfg don't seem any different in this regard, are they? You can store any QString / QByteArray in either of them. It's up to the code that reads/stores to it to parse/check.
We could use a protocol buffer to serialize column sort state -- we could store that in either mixxx.cfg or SettingsDAO and we would get parsing, serializing and the ability to migrate users to a future format easily. Human readability can be achieved with protobuf text formatting but I'm not sure if it needs to be human readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR SettingsDAO has serialized data which where likely misinterpreted after an update and mixxx.cfg has human readable and editable data. I like the idea to treat the data as "sacred", but we don't do this with the header state.
Right -- header data is opaque since we can't really tell what Qt is storing in there (well, we could but we don't). So we rely on Qt to correctly save/restore it.
Do you mean that the header data already contains sorting state so there's the possibility for this PR to store data conflicting with the header state?
What will be the rule of thump, which storage is used when?
I agree conceptually it's awkward to have two different places to store key/value configuration data. I think the rule of thumb is that the library settings table is for storing library-specific configuration data. It's nice that a user can copy their mixxxdb.sqlite to a different profile and still have a working library. So things like the current schema version absolutely have to go in SettingsDAO, but things like the preferred column sort order is less clear-cut. I'd be OK with the rule of thumb being "all library-specific preferences go in the library settings table".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. that sounds reasonable.
Do you mean that the header data already contains sorting state so there's the possibility for this PR to store data conflicting with the header state?
No, because we need here the sorting hierarchy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmigual: Would you mind to put this rule of thump as comment into
mixxx/src/library/dao/settingsdao.h
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't really tell what Qt is storing in there
I thought I rewrote the header-saving code and got rid of the old QT-binary blob? So that upgrading is easier.
Yea I think I caused this when I enabled asan on Travis builds for OS X. I think we should make the tests run faster -- they take almost a minute on my machine. |
I reverted my asan commit. |
} | ||
|
||
friend QTextStream & operator << (QTextStream &out, SortColumn &sc) { | ||
out << sc.m_column << " "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we have here a space and not in the reading code above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because QTextStream skips spaces when reading but you need to set spaces when writing (like it happens normally in cin and cout)
QString name; | ||
|
||
in >> name >> ordI; | ||
int col = this->fieldIndex(name) + m_tableColumns.size() - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this-> is redundant
With this patch it happens, that the table is emptied. |
Yes it is related to the -1 column issue, I'll fix it now. By the way how can you view this with mixxx?
|
I use the Firefox SqLite Manager Add-on |
|
||
QString name; | ||
if (sc.m_column > 0 && sc.m_column < m_tableColumns.size()) { | ||
name = m_tableColumns[column]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo?
name = m_tableColumns[sc.m_column];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's a typo, I'll change it now
// Write new sortColumns order to user settings | ||
QString val; | ||
QTextStream out(&val); | ||
qDebug() << m_tableColumns; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seams to be an intermediate debug. Remove?
Thank you. There is only a single debug leftover and than LGTM. |
Ok, fixed. I didn't know GitHub does not notify users so I'll take into account. |
Thank you :-) |
Resolves https://bugs.launchpad.net/mixxx/+bug/1474098
Now the BaseSqlTableModel remembers the hierarchical sorting across restarts