Compare commits

..
Author SHA1 Message Date
Devin Lin ca0e9294f1 Add loading indicator to minimized bar when loading track 2022-05-23 21:21:17 -04:00
Jonah Brüchert cb16ebb812 Crop album art to square 2022-05-23 21:42:23 +02:00
Jonah Brüchert 2c1df5e9e4 asyncdatabase: Remove unused includes 2022-05-23 21:16:43 +02:00
Jonah Brüchert c3873d05ac asyncdatabase: Move parseRows into private API
It is no longer useful externally, as the database API doesn't return
unparsed QVariants any more.
2022-05-23 21:16:43 +02:00
Jonah Brüchert 4fca0ca0c5 Show mini progress bar when there is no space for the full one 2022-05-23 16:06:00 +00:00
Jonah Brüchert c02f369a0f asyncdatabase: Fix mistake in concept checks 2022-05-23 18:04:28 +02:00
4 changed files with 36 additions and 44 deletions

No files matched your search

+3 -41
View File
@@ -10,10 +10,6 @@ class QSqlDatabase;
#include <QString>
#include <QObject>
#include <QFuture>
#include <QFutureWatcher>
#include <QSqlQuery>
#include <QDebug>
#include <QThread>
#include <QSharedDataPointer>
#include <memory>
@@ -23,9 +19,6 @@ class QSqlDatabase;
#include "asyncdatabase_p.h"
using Row = std::vector<QVariant>;
using Rows = std::vector<Row>;
struct DatabaseConfigurationPrivate;
///
@@ -66,37 +59,6 @@ private:
///
const QString DATABASE_TYPE_SQLITE = QStringLiteral("QSQLITE");
///
/// Parse the row into a tuple of the given types.
/// The types need to be deserializable from QVariant.
///
template <typename RowTypesTuple>
auto parseRow(const Row &row) -> RowTypesTuple
{
auto tuple = RowTypesTuple();
int i = 0;
asyncdatabase_private::iterate_tuple(tuple, [&](auto &elem) {
elem = row.at(i).value<std::decay_t<decltype(elem)>>();
i++;
});
return tuple;
}
///
/// Parse the rows into a list of tuples of the given types.
/// The types need to be deserializable from QVariant.
///
template <typename RowTypesTuple>
auto parseRows(const Rows &rows) -> std::vector<RowTypesTuple> {
std::vector<RowTypesTuple> parsedRows;
parsedRows.reserve(rows.size());
for (const auto &row : rows) {
parsedRows.push_back(parseRow<RowTypesTuple>(row));
}
return parsedRows;
}
template <typename T>
concept FromSql = requires(T v, typename T::ColumnTypes row)
{
@@ -123,7 +85,7 @@ public:
/// \return
///
template <typename ...Args>
requires std::conjunction_v<std::is_convertible<Args, Args>...>
requires std::conjunction_v<std::is_convertible<Args, QVariant>...>
auto execute(const QString &sqlQuery, Args... args) -> QFuture<void> {
return db().execute(sqlQuery, args...);
}
@@ -151,7 +113,7 @@ public:
/// and a `static T fromSql(ColumnTypes tuple)` deserialization method.
///
template <typename T, typename ...Args>
requires FromSql<T> && std::conjunction_v<std::is_convertible<Args, Args>...>
requires FromSql<T> && std::conjunction_v<std::is_convertible<Args, QVariant>...>
auto getResults(const QString &sqlQuery, Args... args) -> QFuture<std::vector<T>> {
return db().getResults<T, Args...>(sqlQuery, args...);
}
@@ -160,7 +122,7 @@ public:
/// \brief Like getResults, but for retrieving just one row.
///
template <typename T, typename ...Args>
requires FromSql<T> && std::conjunction_v<std::is_convertible<Args, Args>...>
requires FromSql<T> && std::conjunction_v<std::is_convertible<Args, QVariant>...>
auto getResult(const QString &sqlQuery, Args... args) -> QFuture<std::optional<T>> {
return db().getResult<T, Args...>(sqlQuery, args...);
}
+20
View File
@@ -60,6 +60,26 @@ void connectFuture(const QFuture<T> &future, QObjectDerivedType *self, const Fun
using Row = std::vector<QVariant>;
using Rows = std::vector<Row>;
template <typename RowTypesTuple>
auto parseRow(const Row &row) -> RowTypesTuple
{
auto tuple = RowTypesTuple();
int i = 0;
asyncdatabase_private::iterate_tuple(tuple, [&](auto &elem) {
elem = row.at(i).value<std::decay_t<decltype(elem)>>();
i++;
});
return tuple;
}
template <typename RowTypesTuple>
auto parseRows(const Rows &rows) -> std::vector<RowTypesTuple> {
std::vector<RowTypesTuple> parsedRows;
parsedRows.reserve(rows.size());
std::ranges::transform(rows, std::back_inserter(parsedRows), parseRow<RowTypesTuple>);
return parsedRows;
}
void runDatabaseMigrations(QSqlDatabase &database, const QString &migrationDirectory);
void printSqlError(const QSqlQuery &query);
+2 -2
View File
@@ -28,7 +28,7 @@ Item {
anchors.fill: parent
color: Qt.rgba(25, 25, 30, 1)
}
Image {
anchors.fill: parent
asynchronous: true
@@ -171,7 +171,7 @@ Item {
height: 512
}
fillMode: Image.PreserveAspectFit
fillMode: Image.PreserveAspectCrop
}
}
+11 -1
View File
@@ -65,6 +65,8 @@ Item {
Image {
id: mainIcon
anchors.fill: parent
visible: !loadingIndicator.visible
asynchronous: true
mipmap: true
@@ -72,7 +74,15 @@ Item {
sourceSize.width: 512
sourceSize.height: 512
fillMode: Image.PreserveAspectFit
fillMode: Image.PreserveAspectCrop
}
BusyIndicator {
id: loadingIndicator
anchors.centerIn: parent
visible: UserPlaylistModel.loading
Kirigami.Theme.colorSet: Kirigami.Theme.Complementary
Kirigami.Theme.inherit: false
}
}