Skip to content

Commit

Permalink
Prepare loading the named column layouts from the settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7pt0gr4ph7 committed May 21, 2024
1 parent d43f12b commit aca54d7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/library/trackmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,24 @@ class TrackModel {
/*non-virtual*/ bool hasCapabilities(Capabilities caps) const {
return (getCapabilities() & caps) == caps;
}

/*non-virtual*/ QString getKeyForModelSetting(const QString& name) const {
if (name.startsWith("shared_settings.")) {
return "mixxx.db.model." + name;
} else {
return m_settingsNamespace + "." + name;
}
}

virtual QString getModelSetting(const QString& name) {
SettingsDAO settings(m_db);
QString key = m_settingsNamespace + "." + name;
QString key = getKeyForModelSetting(name);
return settings.getValue(key);
}

virtual bool setModelSetting(const QString& name, const QVariant& value) {
SettingsDAO settings(m_db);
QString key = m_settingsNamespace + "." + name;
QString key = getKeyForModelSetting(name);
return settings.setValue(key, value);
}

Expand Down
8 changes: 8 additions & 0 deletions src/proto/headers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ message HeaderViewState {
// This corresponds to the Qt::SortOrder enum.
optional int32 sort_order = 4;
}

message NamedHeaderLayouts {
message NamedHeaderLayout {
required string layout_name = 1;
required HeaderViewState header_view_state = 2;
}
repeated NamedHeaderLayout layout = 1;
}
22 changes: 22 additions & 0 deletions src/widget/wtracktableviewheader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@

#define WTTVH_MINIMUM_SECTION_SIZE 20

NamedHeaderLayouts::NamedHeaderLayouts(const QString& base64serialized) {
// First decode the array from Base64, then initialize the protobuf from it.
QByteArray array = QByteArray::fromBase64(base64serialized.toLatin1());
if (!m_named_layouts.ParseFromArray(array.constData(), array.size())) {
qWarning() << "Could not parse m_named_layouts from QByteArray of size "
<< array.size();
return;
}
}

QString NamedHeaderLayouts::saveState() const {
// Serialize the proto to a byte array, then encode the array as Base64.
#if GOOGLE_PROTOBUF_VERSION >= 3001000
int size = static_cast<int>(m_named_layouts.ByteSizeLong());
#else
int size = m_named_layouts.ByteSize();
#endif
QByteArray array(size, '\0');
m_named_layouts.SerializeToArray(array.data(), size);
return QString(array.toBase64());
}

HeaderViewState::HeaderViewState(const QHeaderView& headers) {
QAbstractItemModel* model = headers.model();
for (int vi = 0; vi < headers.count(); ++vi) {
Expand Down
17 changes: 17 additions & 0 deletions src/widget/wtracktableviewheader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ class HeaderViewState {
mixxx::library::HeaderViewState m_view_state;
};

class NamedHeaderLayouts {
public:
NamedHeaderLayouts() {}

// Populate from an existing protobuf, mostly for testing.
explicit NamedHeaderLayouts(const mixxx::library::NamedHeaderLayouts& pb)
: m_named_layouts(pb) { }

// Populate the object with the serialized protobuf data provided.
explicit NamedHeaderLayouts(const QString& base64serialized);

// Returns a serialized protobuf of the current state.
QString saveState() const;

private:
mixxx::library::NamedHeaderLayouts m_named_layouts;
};

class WTrackTableViewHeader : public QHeaderView {
Q_OBJECT
Expand Down

0 comments on commit aca54d7

Please sign in to comment.