forked from qt-creator/qt-creator
QmlDesigner: Add image cache
The image cache is saving images and icon of this images in a sqlite database. If there are no images they are generated in the backgound. The icons are fetched by item library. Task-number: QDS-2782 Task-number: QDS-2783 Task-number: QDS-2858 Change-Id: I5a32cccfef7f8fd8eb78902605a09f5da18ce88e Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -44,4 +44,6 @@ add_qtc_library(Sqlite
|
||||
tableconstraints.h
|
||||
utf8string.cpp utf8string.h
|
||||
utf8stringvector.cpp utf8stringvector.h
|
||||
sqliteblob.h
|
||||
sqlitetimestamp.h
|
||||
)
|
||||
|
||||
@@ -27,6 +27,8 @@ SOURCES += \
|
||||
$$PWD/sqlitebasestatement.cpp
|
||||
HEADERS += \
|
||||
$$PWD/constraints.h \
|
||||
$$PWD/sqliteblob.h \
|
||||
$$PWD/sqlitetimestamp.h \
|
||||
$$PWD/tableconstraints.h \
|
||||
$$PWD/createtablesqlstatementbuilder.h \
|
||||
$$PWD/lastchangedrowid.h \
|
||||
|
||||
@@ -191,12 +191,12 @@ void BaseStatement::bind(int index, Utils::SmallStringView text)
|
||||
checkForBindingError(resultCode);
|
||||
}
|
||||
|
||||
void BaseStatement::bind(int index, Utils::span<const byte> bytes)
|
||||
void BaseStatement::bind(int index, BlobView blobView)
|
||||
{
|
||||
int resultCode = sqlite3_bind_blob64(m_compiledStatement.get(),
|
||||
index,
|
||||
bytes.data(),
|
||||
static_cast<long long>(bytes.size()),
|
||||
blobView.data(),
|
||||
blobView.size(),
|
||||
SQLITE_STATIC);
|
||||
if (resultCode != SQLITE_OK)
|
||||
checkForBindingError(resultCode);
|
||||
@@ -498,7 +498,7 @@ StringType textForColumn(sqlite3_stmt *sqlStatment, int column)
|
||||
return StringType(text, size);
|
||||
}
|
||||
|
||||
Utils::span<const byte> blobForColumn(sqlite3_stmt *sqlStatment, int column)
|
||||
BlobView blobForColumn(sqlite3_stmt *sqlStatment, int column)
|
||||
{
|
||||
const byte *blob = reinterpret_cast<const byte *>(sqlite3_column_blob(sqlStatment, column));
|
||||
std::size_t size = std::size_t(sqlite3_column_bytes(sqlStatment, column));
|
||||
@@ -506,7 +506,7 @@ Utils::span<const byte> blobForColumn(sqlite3_stmt *sqlStatment, int column)
|
||||
return {blob, size};
|
||||
}
|
||||
|
||||
Utils::span<const byte> convertToBlobForColumn(sqlite3_stmt *sqlStatment, int column)
|
||||
BlobView convertToBlobForColumn(sqlite3_stmt *sqlStatment, int column)
|
||||
{
|
||||
int dataType = sqlite3_column_type(sqlStatment, column);
|
||||
if (dataType == SQLITE_BLOB)
|
||||
@@ -571,7 +571,7 @@ double BaseStatement::fetchDoubleValue(int column) const
|
||||
return sqlite3_column_double(m_compiledStatement.get(), column);
|
||||
}
|
||||
|
||||
Utils::span<const byte> BaseStatement::fetchBlobValue(int column) const
|
||||
BlobView BaseStatement::fetchBlobValue(int column) const
|
||||
{
|
||||
return convertToBlobForColumn(m_compiledStatement.get(), column);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "sqliteglobal.h"
|
||||
|
||||
#include "sqliteblob.h"
|
||||
#include "sqliteexception.h"
|
||||
#include "sqlitevalue.h"
|
||||
|
||||
@@ -70,7 +71,7 @@ public:
|
||||
double fetchDoubleValue(int column) const;
|
||||
Utils::SmallStringView fetchSmallStringViewValue(int column) const;
|
||||
ValueView fetchValueView(int column) const;
|
||||
Utils::span<const byte> fetchBlobValue(int column) const;
|
||||
BlobView fetchBlobValue(int column) const;
|
||||
template<typename Type>
|
||||
Type fetchValue(int column) const;
|
||||
int columnCount() const;
|
||||
@@ -82,7 +83,7 @@ public:
|
||||
void bind(int index, void *pointer);
|
||||
void bind(int index, Utils::SmallStringView fetchValue);
|
||||
void bind(int index, const Value &fetchValue);
|
||||
void bind(int index, Utils::span<const byte> bytes);
|
||||
void bind(int index, BlobView blobView);
|
||||
|
||||
void bind(int index, uint value) { bind(index, static_cast<long long>(value)); }
|
||||
|
||||
@@ -358,7 +359,7 @@ private:
|
||||
operator long long() { return statement.fetchLongLongValue(column); }
|
||||
operator double() { return statement.fetchDoubleValue(column); }
|
||||
operator Utils::SmallStringView() { return statement.fetchSmallStringViewValue(column); }
|
||||
operator Utils::span<const Sqlite::byte>() { return statement.fetchBlobValue(column); }
|
||||
operator BlobView() { return statement.fetchBlobValue(column); }
|
||||
operator ValueView() { return statement.fetchValueView(column); }
|
||||
|
||||
StatementImplementation &statement;
|
||||
|
||||
100
src/libs/sqlite/sqliteblob.h
Normal file
100
src/libs/sqlite/sqliteblob.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sqliteglobal.h"
|
||||
|
||||
#include <utils/span.h>
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace Sqlite {
|
||||
|
||||
class BlobView
|
||||
{
|
||||
public:
|
||||
BlobView() = default;
|
||||
|
||||
BlobView(const byte *data, std::size_t size)
|
||||
: m_data(data)
|
||||
, m_size(size)
|
||||
{}
|
||||
|
||||
BlobView(const QByteArray &byteArray)
|
||||
: m_data(reinterpret_cast<const byte *>(byteArray.constData()))
|
||||
, m_size(static_cast<std::size_t>(byteArray.size()))
|
||||
{}
|
||||
|
||||
BlobView(const std::vector<Sqlite::byte> &bytes)
|
||||
: m_data(bytes.data())
|
||||
, m_size(static_cast<std::size_t>(bytes.size()))
|
||||
{}
|
||||
|
||||
const byte *data() const { return m_data; }
|
||||
const char *cdata() const { return reinterpret_cast<const char *>(m_data); }
|
||||
std::size_t size() const { return m_size; }
|
||||
int sisize() const { return static_cast<int>(m_size); }
|
||||
long long ssize() const { return static_cast<long long>(m_size); }
|
||||
bool empty() const { return !m_size; }
|
||||
|
||||
friend bool operator==(Sqlite::BlobView first, Sqlite::BlobView second)
|
||||
{
|
||||
return first.size() == second.size()
|
||||
&& std::memcmp(first.data(), second.data(), first.size()) == 0;
|
||||
}
|
||||
|
||||
private:
|
||||
const byte *m_data{};
|
||||
std::size_t m_size{};
|
||||
};
|
||||
|
||||
class Blob
|
||||
{
|
||||
public:
|
||||
Blob(BlobView blobView)
|
||||
{
|
||||
bytes.reserve(blobView.size());
|
||||
std::copy_n(blobView.data(), blobView.size(), std::back_inserter(bytes));
|
||||
}
|
||||
|
||||
std::vector<Sqlite::byte> bytes;
|
||||
};
|
||||
|
||||
class ByteArrayBlob
|
||||
{
|
||||
public:
|
||||
ByteArrayBlob(BlobView blobView)
|
||||
: byteArray{blobView.cdata(), blobView.sisize()}
|
||||
{}
|
||||
|
||||
QByteArray byteArray;
|
||||
};
|
||||
|
||||
} // namespace Sqlite
|
||||
@@ -46,7 +46,7 @@ void checkResultCode(int resultCode)
|
||||
|
||||
} // namespace
|
||||
|
||||
SessionChangeSet::SessionChangeSet(Utils::span<const byte> blob)
|
||||
SessionChangeSet::SessionChangeSet(BlobView blob)
|
||||
: data(sqlite3_malloc64(blob.size()))
|
||||
, size(int(blob.size()))
|
||||
{
|
||||
@@ -64,7 +64,7 @@ SessionChangeSet::~SessionChangeSet()
|
||||
sqlite3_free(data);
|
||||
}
|
||||
|
||||
Utils::span<const byte> SessionChangeSet::asSpan() const
|
||||
BlobView SessionChangeSet::asBlobView() const
|
||||
{
|
||||
return {static_cast<const byte *>(data), static_cast<std::size_t>(size)};
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sqliteblob.h"
|
||||
#include "sqliteglobal.h"
|
||||
|
||||
#include <utils/span.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -41,7 +40,7 @@ class Sessions;
|
||||
class SessionChangeSet
|
||||
{
|
||||
public:
|
||||
SessionChangeSet(Utils::span<const byte> blob);
|
||||
SessionChangeSet(BlobView blob);
|
||||
SessionChangeSet(Sessions &session);
|
||||
~SessionChangeSet();
|
||||
SessionChangeSet(const SessionChangeSet &) = delete;
|
||||
@@ -54,7 +53,7 @@ public:
|
||||
}
|
||||
void operator=(SessionChangeSet &);
|
||||
|
||||
Utils::span<const byte> asSpan() const;
|
||||
BlobView asBlobView() const;
|
||||
|
||||
friend void swap(SessionChangeSet &first, SessionChangeSet &second) noexcept
|
||||
{
|
||||
|
||||
@@ -103,7 +103,7 @@ void Sessions::commit()
|
||||
if (session && !sqlite3session_isempty(session.get())) {
|
||||
SessionChangeSet changeSet{*this};
|
||||
|
||||
insertSession.write(changeSet.asSpan());
|
||||
insertSession.write(changeSet.asBlobView());
|
||||
}
|
||||
|
||||
session.reset();
|
||||
|
||||
47
src/libs/sqlite/sqlitetimestamp.h
Normal file
47
src/libs/sqlite/sqlitetimestamp.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Sqlite {
|
||||
|
||||
class TimeStamp
|
||||
{
|
||||
public:
|
||||
TimeStamp() = default;
|
||||
TimeStamp(long long value)
|
||||
: value(value)
|
||||
{}
|
||||
|
||||
friend bool operator==(TimeStamp first, TimeStamp second)
|
||||
{
|
||||
return first.value == second.value;
|
||||
}
|
||||
|
||||
public:
|
||||
long long value = -1;
|
||||
};
|
||||
|
||||
} // namespace Sqlite
|
||||
@@ -23,6 +23,8 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sqliteexception.h"
|
||||
|
||||
#include <utils/smallstring.h>
|
||||
@@ -32,9 +34,6 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace Sqlite {
|
||||
|
||||
enum class ValueType : unsigned char { Null, Integer, Float, String };
|
||||
|
||||
Reference in New Issue
Block a user