Skip to content
Snippets Groups Projects
Commit 7acd1b9c authored by Fabian Kosmale's avatar Fabian Kosmale
Browse files

minimal

parents
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(ECMUninstallTarget)
cmake_minimum_required(VERSION 3.16)
project(baseproject LANGUAGES CXX)
find_package(Qt6 REQUIRED COMPONENTS Core Qml)
qt_standard_project_setup(REQUIRES 6.5)
qt_add_qml_module(baseproject
SOURCES
birthdayparty.cpp birthdayparty.h
person.cpp person.h
URI People
QML_FILES
People/Klaus.qml
RESOURCES
People/some.txt
)
target_link_libraries(baseproject PUBLIC
Qt6::Core
Qt6::Qml
)
qt_query_qml_module(baseproject
URI module_uri
VERSION module_version
PLUGIN_TARGET module_plugin_target
TARGET_PATH module_target_path
QMLDIR module_qmldir
TYPEINFO module_typeinfo
QML_FILES module_qml_files
QML_FILES_DEPLOY_PATHS qml_files_deploy_paths
RESOURCES module_resources
RESOURCES_DEPLOY_PATHS resources_deploy_paths
)
set(staging_prefix "/home/fabian/qmltarget")
message(STATUS "My QML module URI is: ${module_uri}")
message(STATUS "My QML module version is: ${module_version}")
# Install the QML module backing library
install(TARGETS baseproject
ARCHIVE DESTINATION "${staging_prefix}/${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${staging_prefix}/${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${staging_prefix}/${CMAKE_INSTALL_BINDIR}"
)
set(module_dir "${staging_prefix}/qml/${module_target_path}")
message(STATUS "Module dir ${module_dir}")
# Install the QML module runtime loadable plugin
install(TARGETS "${module_plugin_target}"
LIBRARY DESTINATION "${module_dir}"
RUNTIME DESTINATION "${module_dir}"
)
# Install the QML module meta information.
install(FILES "${module_qmldir}" DESTINATION "${module_dir}")
install(FILES "${module_typeinfo}" DESTINATION "${module_dir}")
# Install QML files, possibly renamed.
foreach(src_file deploy_path IN ZIP_LISTS qml_files_deploy_paths qml_files_deploy_paths)
get_filename_component(dst_name "${deploy_path}" NAME)
get_filename_component(dest_dir "${deploy_path}" DIRECTORY)
install(FILES "${src_file}" DESTINATION "${module_dir}/${dest_dir}" RENAME "${dst_name}")
endforeach()
# Install resources, possibly renamed.
foreach(src_file deploy_path IN ZIP_LISTS module_resources resources_deploy_paths)
get_filename_component(dst_name "${deploy_path}" NAME)
get_filename_component(dest_dir "${deploy_path}" DIRECTORY)
install(FILES "${src_file}" DESTINATION "${module_dir}/${dest_dir}" RENAME "${dst_name}")
endforeach()
Main.qml 0 → 100644
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import People
BirthdayParty {
host: Person {
name: "Bob Jones"
shoeSize: 12
}
guests: [
Person { name: "Leo Hodges" },
Person { name: "Jack Smith" },
Person { name: "Anne Brown" }
]
}
import QtQuick
Text {
readonly property string name: "Klaus"
text: name
}
This is
some
text
.
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "birthdayparty.h"
Person *BirthdayParty::host() const
{
return m_host;
}
void BirthdayParty::setHost(Person *host)
{
if (m_host != host) {
m_host = host;
emit hostChanged();
}
}
QQmlListProperty<Person> BirthdayParty::guests()
{
return { this,
this,
&BirthdayParty::appendGuest,
&BirthdayParty::guestCount,
&BirthdayParty::guest,
&BirthdayParty::clearGuests,
&BirthdayParty::replaceGuest,
&BirthdayParty::removeLastGuest };
}
void BirthdayParty::appendGuest(Person *guest)
{
m_guests.append(guest);
emit guestsChanged();
}
qsizetype BirthdayParty::guestCount() const
{
return m_guests.count();
}
Person *BirthdayParty::guest(qsizetype index) const
{
return m_guests.at(index);
}
void BirthdayParty::clearGuests()
{
if (!m_guests.empty()) {
m_guests.clear();
emit guestsChanged();
}
}
void BirthdayParty::replaceGuest(qsizetype index, Person *guest)
{
if (m_guests.size() > index) {
m_guests[index] = guest;
emit guestsChanged();
}
}
void BirthdayParty::removeLastGuest()
{
if (!m_guests.empty()) {
m_guests.removeLast();
emit guestsChanged();
}
}
void BirthdayParty::appendGuest(QQmlListProperty<Person> *list, Person *guest)
{
static_cast<BirthdayParty *>(list->data)->appendGuest(guest);
}
void BirthdayParty::clearGuests(QQmlListProperty<Person> *list)
{
static_cast<BirthdayParty *>(list->data)->clearGuests();
}
void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, qsizetype index, Person *guest)
{
static_cast<BirthdayParty *>(list->data)->replaceGuest(index, guest);
}
void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list)
{
static_cast<BirthdayParty *>(list->data)->removeLastGuest();
}
Person *BirthdayParty::guest(QQmlListProperty<Person> *list, qsizetype index)
{
return static_cast<BirthdayParty *>(list->data)->guest(index);
}
qsizetype BirthdayParty::guestCount(QQmlListProperty<Person> *list)
{
return static_cast<BirthdayParty *>(list->data)->guestCount();
}
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef BIRTHDAYPARTY_H
#define BIRTHDAYPARTY_H
#include "person.h"
#include <QObject>
#include <QQmlListProperty>
class BirthdayParty : public QObject
{
Q_OBJECT
Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL)
Q_PROPERTY(QQmlListProperty<Person> guests READ guests NOTIFY guestsChanged FINAL)
QML_ELEMENT
public:
using QObject::QObject;
Person *host() const;
void setHost(Person *);
QQmlListProperty<Person> guests();
void appendGuest(Person *);
qsizetype guestCount() const;
Person *guest(qsizetype) const;
void clearGuests();
void replaceGuest(qsizetype, Person *);
void removeLastGuest();
signals:
void hostChanged();
void guestsChanged();
private:
static void appendGuest(QQmlListProperty<Person> *, Person *);
static qsizetype guestCount(QQmlListProperty<Person> *);
static Person *guest(QQmlListProperty<Person> *, qsizetype);
static void clearGuests(QQmlListProperty<Person> *);
static void replaceGuest(QQmlListProperty<Person> *, qsizetype, Person *);
static void removeLastGuest(QQmlListProperty<Person> *);
Person *m_host = nullptr;
QList<Person *> m_guests;
};
#endif // BIRTHDAYPARTY_H
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "person.h"
QString Person::name() const
{
return m_name;
}
void Person::setName(const QString &name)
{
if (m_name != name) {
m_name = name;
emit nameChanged();
}
}
int Person::shoeSize() const
{
return m_shoeSize;
}
void Person::setShoeSize(int shoeSize)
{
if (m_shoeSize != shoeSize) {
m_shoeSize = shoeSize;
emit shoeSizeChanged();
}
}
person.h 0 → 100644
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef PERSON_H
#define PERSON_H
#include <QtQml/qqml.h>
#include <QObject>
class Person : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize NOTIFY shoeSizeChanged FINAL)
QML_ELEMENT
public:
using QObject::QObject;
QString name() const;
void setName(const QString &);
int shoeSize() const;
void setShoeSize(int);
signals:
void nameChanged();
void shoeSizeChanged();
private:
QString m_name;
int m_shoeSize = 0;
};
#endif // PERSON_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment