Implemented loopstation preset detail widget

This commit is contained in:
2022-12-28 01:22:03 +01:00
parent 015d42d977
commit d3fd851d54
12 changed files with 425 additions and 4 deletions

View File

@ -26,6 +26,7 @@ SOURCES += \
loopstationjsonconverters.cpp \
loopstationpresets.cpp \
loopstationpresetsmodel.cpp \
loopstationpresettagsmodel.cpp \
main.cpp \
midicontainers.cpp \
midiinwrapper.cpp \
@ -37,6 +38,7 @@ SOURCES += \
widgets/drumpadsampleswidget.cpp \
widgets/drumpadsamplewidget.cpp \
widgets/drumpadwidget.cpp \
widgets/loopstationpresetdetailwidget.cpp \
widgets/loopstationwidget.cpp \
widgets/mainwindow.cpp \
widgets/midibutton.cpp \
@ -62,6 +64,7 @@ HEADERS += \
loopstationjsonconverters.h \
loopstationpresets.h \
loopstationpresetsmodel.h \
loopstationpresettagsmodel.h \
midicontainers.h \
midiinwrapper.h \
midioutwrapper.h \
@ -72,6 +75,7 @@ HEADERS += \
widgets/drumpadsampleswidget.h \
widgets/drumpadsamplewidget.h \
widgets/drumpadwidget.h \
widgets/loopstationpresetdetailwidget.h \
widgets/loopstationwidget.h \
widgets/mainwindow.h \
widgets/midibutton.h \
@ -88,6 +92,7 @@ FORMS += \
widgets/drumpadsampleswidget.ui \
widgets/drumpadsamplewidget.ui \
widgets/drumpadwidget.ui \
widgets/loopstationpresetdetailwidget.ui \
widgets/loopstationwidget.ui \
widgets/mainwindow.ui \
widgets/sequencerwidget.ui \

View File

@ -1,5 +1,7 @@
#include "drumpadpresettagsmodel.h"
#include "drumpadpresets.h"
DrumPadPresetTagsModel::DrumPadPresetTagsModel(QObject *parent) :
QAbstractListModel{parent}
{

View File

@ -2,8 +2,6 @@
#include <QAbstractListModel>
#include "drumpadpresets.h"
namespace drumpad_presets { struct Preset; }
class DrumPadPresetTagsModel : public QAbstractListModel

View File

@ -1,2 +1 @@
#include "loopstationpresets.h"

View File

@ -0,0 +1,43 @@
#include "loopstationpresettagsmodel.h"
#include "loopstationpresets.h"
LoopStationPresetTagsModel::LoopStationPresetTagsModel(QObject *parent) :
QAbstractListModel{parent}
{
}
void LoopStationPresetTagsModel::setPreset(const loopstation_presets::Preset &preset)
{
beginResetModel();
if (preset.tags)
m_tags = *preset.tags;
else
m_tags.clear();
endResetModel();
}
int LoopStationPresetTagsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_tags.size();
}
QVariant LoopStationPresetTagsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return {};
if (index.row() < 0 || index.row() >= int(m_tags.size()))
return {};
switch (role)
{
case Qt::DisplayRole:
case Qt::EditRole:
return m_tags[index.row()];
}
return {};
}

View File

@ -0,0 +1,19 @@
#pragma once
#include <QAbstractListModel>
namespace loopstation_presets { struct Preset; }
class LoopStationPresetTagsModel : public QAbstractListModel
{
public:
LoopStationPresetTagsModel(QObject *parent = nullptr);
void setPreset(const loopstation_presets::Preset &preset);
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
private:
std::vector<QString> m_tags;
};

View File

@ -128,6 +128,9 @@
<property name="text">
<string>tags:</string>
</property>
<property name="buddy">
<cstring>listViewTags</cstring>
</property>
</widget>
</item>
<item row="11" column="0">
@ -479,7 +482,11 @@
</widget>
</item>
<item row="10" column="1">
<widget class="QListView" name="listViewTags"/>
<widget class="QListView" name="listViewTags">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>

View File

@ -0,0 +1,50 @@
#include "loopstationpresetdetailwidget.h"
#include "ui_loopstationpresetdetailwidget.h"
#include "loopstationpresets.h"
LoopStationPresetDetailWidget::LoopStationPresetDetailWidget(QWidget *parent) :
QScrollArea{parent},
m_ui{std::make_unique<Ui::LoopStationPresetDetailWidget>()}
{
m_ui->setupUi(this);
m_ui->listViewTags->setModel(&m_tagsModel);
}
LoopStationPresetDetailWidget::~LoopStationPresetDetailWidget() = default;
void LoopStationPresetDetailWidget::setPreset(const loopstation_presets::Preset &preset)
{
constexpr const auto applyField = [](QWidget *edit, const auto &field){
edit->setEnabled(field.has_value());
edit->setVisible(field.has_value());
};
constexpr const auto applyLineEdit = [applyField](QLineEdit *edit, const auto &field){
applyField(edit, field);
edit->setText(field ? *field : QString{});
};
constexpr const auto applySpinBox = [applyField](QSpinBox *edit, const auto &field){
applyField(edit, field);
edit->setValue(field ? *field : -1);
};
constexpr const auto applyCheckBox = [applyField](QCheckBox *edit, const auto &field){
applyField(edit, field);
edit->setChecked(field ? *field : false);
};
applyLineEdit(m_ui->lineEditId, preset.id);
applyLineEdit(m_ui->lineEditTitle, preset.title);
applyLineEdit(m_ui->lineEditAudioPreviewUrl, preset.audioPreviewUrl);
applyLineEdit(m_ui->lineEditAuthor, preset.author);
applySpinBox(m_ui->spinBoxBpm, preset.bpm);
// TODO lessons
applyLineEdit(m_ui->lineEditCoverUrl, preset.coverUrl);
applySpinBox(m_ui->spinBoxLoopLength, preset.loopLength);
applyLineEdit(m_ui->lineEditOrderBy, preset.orderBy);
// TODO pads
applyCheckBox(m_ui->checkBoxPremium, preset.premium);
applyCheckBox(m_ui->checkBoxDeleted, preset.DELETED);
m_tagsModel.setPreset(preset);
}

View File

@ -0,0 +1,26 @@
#pragma once
#include <QScrollArea>
#include <memory>
#include "loopstationpresettagsmodel.h"
namespace Ui { class LoopStationPresetDetailWidget; }
namespace loopstation_presets { struct Preset; }
class LoopStationPresetDetailWidget : public QScrollArea
{
Q_OBJECT
public:
explicit LoopStationPresetDetailWidget(QWidget *parent = nullptr);
~LoopStationPresetDetailWidget() override;
void setPreset(const loopstation_presets::Preset &preset);
private:
const std::unique_ptr<Ui::LoopStationPresetDetailWidget> m_ui;
LoopStationPresetTagsModel m_tagsModel;
};

View File

@ -0,0 +1,255 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LoopStationPresetDetailWidget</class>
<widget class="QScrollArea" name="LoopStationPresetDetailWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>431</width>
<height>640</height>
</rect>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>429</width>
<height>638</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelId">
<property name="text">
<string>id:</string>
</property>
<property name="buddy">
<cstring>lineEditId</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditId">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelAudioPreviewUrl">
<property name="text">
<string>audioPreviewUrl:</string>
</property>
<property name="buddy">
<cstring>lineEditAudioPreviewUrl</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelAuthor">
<property name="text">
<string>author:</string>
</property>
<property name="buddy">
<cstring>lineEditAuthor</cstring>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelBpm">
<property name="text">
<string>bpm:</string>
</property>
<property name="buddy">
<cstring>spinBoxBpm</cstring>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="labelCoverUrl">
<property name="text">
<string>coverUrl:</string>
</property>
<property name="buddy">
<cstring>lineEditCoverUrl</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelLoopLength">
<property name="text">
<string>loopLength:</string>
</property>
<property name="buddy">
<cstring>spinBoxLoopLength</cstring>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelOrderBy">
<property name="text">
<string>orderBy:</string>
</property>
<property name="buddy">
<cstring>lineEditOrderBy</cstring>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelPremium">
<property name="text">
<string>premium:</string>
</property>
<property name="buddy">
<cstring>checkBoxPremium</cstring>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelTags">
<property name="text">
<string>tags:</string>
</property>
<property name="buddy">
<cstring>listViewTags</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelTitle">
<property name="text">
<string>title:</string>
</property>
<property name="buddy">
<cstring>lineEditTitle</cstring>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="labelDeleted">
<property name="text">
<string>DELETED:</string>
</property>
<property name="buddy">
<cstring>checkBoxDeleted</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditTitle">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEditAudioPreviewUrl">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEditAuthor">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="spinBoxBpm">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="lineEditCoverUrl">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="spinBoxLoopLength">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="lineEditOrderBy">
<property name="enabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="11" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="checkBoxPremium">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QListView" name="listViewTags">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QCheckBox" name="checkBoxDeleted">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>CheckBox</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -90,6 +90,8 @@ void LoopStationWidget::currentRowChanged(const QModelIndex &current)
m_settings->setLoopstationLastPresetId(preset.id ? *preset.id : QString{});
else
qWarning() << "no settings available";
m_ui->presetDetailWidget->setPreset(preset);
}
void LoopStationWidget::loadPresets()

View File

@ -75,6 +75,15 @@
</property>
</widget>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<widget class="LoopStationPresetDetailWidget" name="presetDetailWidget">
<attribute name="title">
<string>Properties</string>
</attribute>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="widget" native="true">
@ -99,6 +108,12 @@
<extends>QPushButton</extends>
<header>widgets/midibutton.h</header>
</customwidget>
<customwidget>
<class>LoopStationPresetDetailWidget</class>
<extends>QWidget</extends>
<header>widgets/loopstationpresetdetailwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>