mirror of
https://github.com/allankoechke/FigmaQML.git
synced 2026-12-01 17:04:14 +00:00
port to Qt6
This commit is contained in:
@@ -11,7 +11,14 @@ set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt5 COMPONENTS Core Quick Network Widgets Concurrent REQUIRED)
|
||||
|
||||
find_package(Qt5 COMPONENTS Core Quick Network Widgets Concurrent)
|
||||
find_package(Qt6 COMPONENTS Core Quick Network Widgets Concurrent)
|
||||
|
||||
if(NOT Qt5_FOUND AND NOT Qt6_FOUND)
|
||||
message(FATAL_ERROR "Qt5 or Qt6 is not found!")
|
||||
endif()
|
||||
|
||||
|
||||
set(VERSION_NUMBER "1.0.0")
|
||||
|
||||
@@ -60,5 +67,11 @@ include_directories(include)
|
||||
target_compile_definitions(FigmaQML
|
||||
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
|
||||
|
||||
target_link_libraries(FigmaQML
|
||||
PRIVATE Qt5::Core Qt5::Quick Qt5::Network Qt5::Widgets Qt5::Concurrent ${EXTRA})
|
||||
if(Qt5_FOUND)
|
||||
target_compile_definitions(FigmaQML -DQT5)
|
||||
target_link_libraries(FigmaQML
|
||||
PRIVATE Qt5::Core Qt5::Quick Qt5::Network Qt5::Widgets Qt5::Concurrent ${EXTRA})
|
||||
else()
|
||||
target_link_libraries(FigmaQML
|
||||
PRIVATE Qt6::Core Qt6::Quick Qt6::Network Qt6::Widgets Qt6::Concurrent ${EXTRA})
|
||||
endif()
|
||||
|
||||
@@ -39,6 +39,10 @@ QString toStr(const First& first, Rest&&... args) {
|
||||
|
||||
#define ERR(...) throw FigmaParser::Exception(toStr(__VA_ARGS__));
|
||||
|
||||
inline QByteArray& operator+=(QByteArray& ba, const QString& qstr) {
|
||||
ba += qstr.toUtf8();
|
||||
return ba;
|
||||
}
|
||||
|
||||
class FigmaParser {
|
||||
public:
|
||||
@@ -331,7 +335,8 @@ private:
|
||||
if(obj.contains("children")) {
|
||||
const auto children = obj["children"].toArray();
|
||||
for(const auto& c : children) {
|
||||
cList.insert(c["id"].toString(), c["name"].toString());
|
||||
const auto childObj = c.toObject();
|
||||
cList.insert(childObj["id"].toString(), childObj["name"].toString());
|
||||
}
|
||||
}
|
||||
return cList;
|
||||
|
||||
@@ -226,7 +226,7 @@ FigmaQml::FigmaQml(const QString& qmlDir, const QString& fontFolder, const Image
|
||||
emit warning(QString("Folder \"%1\", not found").arg(m_fontFolder));
|
||||
for(const auto& entry : fontFolder.entryInfoList()) {
|
||||
emit info(entry.fileName());
|
||||
if(!entry.fileName().endsWith(".txt" && QFontDatabase::addApplicationFont(entry.absoluteFilePath()) < 0))
|
||||
if(!entry.fileName().endsWith(".txt")&& QFontDatabase::addApplicationFont(entry.absoluteFilePath()) < 0)
|
||||
emit warning(QString("Font \"%1\", cannot be loaded").arg(entry.absoluteFilePath()));
|
||||
}
|
||||
};
|
||||
@@ -353,7 +353,7 @@ bool FigmaQml::ensureDirExists(const QString& e) const {
|
||||
QVariantMap FigmaQml::fonts() const {
|
||||
QVariantMap map;
|
||||
const auto c = m_fontCache->content();
|
||||
for(const auto v : c)
|
||||
for(const auto& v : c)
|
||||
map.insert(v.first, v.second);
|
||||
return map;
|
||||
}
|
||||
@@ -471,8 +471,7 @@ QString FigmaQml::nearestFontFamily(const QString& requestedFont, bool useAlt) {
|
||||
const auto value = fontInfo.family();
|
||||
return value;
|
||||
} else {
|
||||
QFontDatabase database;
|
||||
const QStringList fontFamilies = database.families();
|
||||
const QStringList fontFamilies = QFontDatabase::families();
|
||||
int min = std::numeric_limits<int>::max();
|
||||
int index = -1;
|
||||
for(auto ff = 0; ff < fontFamilies.size() ; ff++) {
|
||||
@@ -500,7 +499,7 @@ std::unique_ptr<T> FigmaQml::construct(const QJsonObject& obj, const QString& ta
|
||||
const auto d = QObject::connect(this, &FigmaQml::cancelled, this, [&doCancel]() {
|
||||
doCancel = true;
|
||||
}, Qt::UniqueConnection);
|
||||
RAII(([this, d](){QObject::disconnect(d);}));
|
||||
RAII(([d](){QObject::disconnect(d);}));
|
||||
|
||||
m_busy = true;
|
||||
emit busyChanged();
|
||||
@@ -568,7 +567,7 @@ std::unique_ptr<T> FigmaQml::construct(const QJsonObject& obj, const QString& ta
|
||||
header += QString("import %1 %2\n").arg(k).arg(m_imports[k].toString());
|
||||
}
|
||||
|
||||
const auto components = FigmaParser::components(obj, errorFunction, [this, &doCancel, &ok](const QString& id) {
|
||||
auto components = FigmaParser::components(obj, errorFunction, [this, &doCancel, &ok](const QString& id) {
|
||||
if(!ok || doCancel)
|
||||
return QByteArray();
|
||||
return mNodeProvider(id);
|
||||
@@ -611,8 +610,8 @@ std::unique_ptr<T> FigmaQml::construct(const QJsonObject& obj, const QString& ta
|
||||
|
||||
|
||||
const auto componentData =
|
||||
QtConcurrent::mapped<decltype(components),
|
||||
std::function<FigmaParser::Element (const FigmaParser::Components::const_iterator::value_type &) >>(components, [&, this](const auto& c)->FigmaParser::Element {
|
||||
QtConcurrent::mapped<decltype(components), std::function<FigmaParser::Element (const FigmaParser::Components::const_iterator::value_type &) >>
|
||||
(std::move(components), [&, this](const auto& c)->FigmaParser::Element {
|
||||
|
||||
if(!ok || doCancel)
|
||||
return FigmaParser::Element();
|
||||
@@ -658,7 +657,7 @@ std::unique_ptr<T> FigmaQml::construct(const QJsonObject& obj, const QString& ta
|
||||
if(!ok || doCancel)
|
||||
return nullptr;
|
||||
|
||||
const std::function<void (const FigmaParser::Element& c)> addComponent = [&, this](const FigmaParser::Element& c) { //recursive lambdas cannot be declared auto
|
||||
const std::function<void (const FigmaParser::Element& c)> addComponent = [&](const FigmaParser::Element& c) { //recursive lambdas cannot be declared auto
|
||||
if(!ok || doCancel)
|
||||
return;
|
||||
const auto name = components[c.id()]->name();
|
||||
@@ -710,8 +709,10 @@ std::unique_ptr<T> FigmaQml::construct(const QJsonObject& obj, const QString& ta
|
||||
}
|
||||
const auto element = hasElement ? FigmaParser::element(f, m_flags, errorFunction, imageFunction, components) : FigmaParser::Element();
|
||||
#else
|
||||
QFuture<FigmaParser::Element> elementData = QtConcurrent::mapped<FigmaParser::Canvas::ElementVector, std::function<FigmaParser::Element (const FigmaParser::Canvas::ElementVector::value_type&)> > (
|
||||
c.elements(), [&, this](const auto& f) {
|
||||
auto elements = c.elements();
|
||||
QFuture<FigmaParser::Element> elementData =
|
||||
QtConcurrent::mapped<FigmaParser::Canvas::ElementVector, std::function<FigmaParser::Element (const FigmaParser::Canvas::ElementVector::value_type&)> > (
|
||||
std::move(elements), [&, this](const auto& f) {
|
||||
if(!ok || doCancel)
|
||||
return FigmaParser::Element();
|
||||
if(!m_filter.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user