4
0
mirror of https://github.com/QuasarApp/DocsSite.git synced 2025-05-12 19:19:33 +00:00

added frontEnd main model

This commit is contained in:
Andrei Yankovich 2020-05-14 00:27:06 +03:00
parent 9edeb69379
commit 6fee589768
20 changed files with 485 additions and 55 deletions

@ -13,9 +13,16 @@
class QQmlApplicationEngine;
/**
* @brief The BaseFront namespace - contains base frontend solutions for create sites and applications
* @brief The BaseFront namespace - Сontains base FrontEnd solutions for create sites and applications.
* After init in qml available next instances:
* - pageReader - see more information in Reader.
*/
namespace BaseFront {
/**
* @brief init - init all instances of this library.
* @param engine - qml engine
* @return - true if the function finished is seccussful.
*/
bool init(QQmlApplicationEngine *engine);
};
#endif // BaseFront_H

@ -0,0 +1,35 @@
#include "baselistmodel.h"
namespace BaseFront {
BaseListModel::BaseListModel(QObject *ptr):
QAbstractListModel(ptr) {
}
bool BaseListModel::canFetchMore(const QModelIndex &) const {
if (_itemCount != rowCount())
return true;
else
return false;
}
void BaseListModel::fetchMore(const QModelIndex &) {
int remainder = rowCount() - _itemCount;
int itemsToFetch = qMin(100, remainder);
if (itemsToFetch < 0) {
beginRemoveRows(QModelIndex(), 0, 0 - itemsToFetch - 1 );
_itemCount += itemsToFetch;
endRemoveRows();
} else if (itemsToFetch > 0) {
beginInsertRows(QModelIndex(), _itemCount, _itemCount + itemsToFetch - 1);
_itemCount += itemsToFetch;
endInsertRows();
}
}
}

@ -0,0 +1,23 @@
#ifndef BASELISTMODEL_H
#define BASELISTMODEL_H
#include "BaseFront_global.h"
#include <QAbstractListModel>
namespace BaseFront {
class BASEFRONT_LIBRARYSHARED_EXPORT BaseListModel: public QAbstractListModel
{
Q_OBJECT
public:
BaseListModel(QObject* ptr = nullptr);
bool canFetchMore(const QModelIndex & /* index */) const;
void fetchMore(const QModelIndex & /* index */);
private:
int _itemCount = 0;
};
}
#endif // BASELISTMODEL_H

@ -0,0 +1,48 @@
#include "infoblock.h"
namespace BaseFront {
InfoBlock::InfoBlock(QObject *parent) : QObject(parent) {
}
QString InfoBlock::title() const {
return m_title;
}
QString BaseFront::InfoBlock::sourceText() const {
return m_sourceText;
}
QString InfoBlock::bakcBroundPicture() const {
return m_bakcBroundPicture;
}
void InfoBlock::setTitle(QString title) {
if (m_title == title)
return;
m_title = title;
emit titleChanged(m_title);
}
void InfoBlock::setSourceText(QString sourceText) {
if (m_sourceText == sourceText)
return;
m_sourceText = sourceText;
emit sourceTextChanged(m_sourceText);
}
void InfoBlock::setBakcBroundPicture(QString bakcBroundPicture) {
if (m_bakcBroundPicture == bakcBroundPicture)
return;
m_bakcBroundPicture = bakcBroundPicture;
emit bakcBroundPictureChanged(m_bakcBroundPicture);
}
uint qHash(const InfoBlock &obj) {
return qHash(obj.title() + obj.sourceText() + obj.bakcBroundPicture());
}
}

@ -0,0 +1,46 @@
#ifndef INFOBLOCK_H
#define INFOBLOCK_H
#include <QObject>
namespace BaseFront {
/**
* @brief The InfoBlock class - this class contains information for viewsolutions comonents
*/
class InfoBlock : public QObject
{
Q_OBJECT
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(QString sourceText READ sourceText WRITE setSourceText NOTIFY sourceTextChanged)
Q_PROPERTY(QString bakcBroundPicture READ bakcBroundPicture WRITE setBakcBroundPicture NOTIFY bakcBroundPictureChanged)
public:
explicit InfoBlock(QObject *parent = nullptr);
QString title() const;
QString sourceText() const;
QString bakcBroundPicture() const;
public slots:
void setTitle(QString title);
void setSourceText(QString sourceText);
void setBakcBroundPicture(QString bakcBroundPicture);
signals:
void titleChanged(QString title);
void sourceTextChanged(QString sourceText);
void bakcBroundPictureChanged(QString bakcBroundPicture);
private:
QString m_title;
QString m_sourceText;
QString m_bakcBroundPicture;
};
uint qHash(const InfoBlock& obj);
}
#endif // INFOBLOCK_H

@ -0,0 +1,102 @@
#include "listviewmodel.h"
namespace BaseFront {
ListViewModel::ListViewModel(QObject *ptr):
BaseListModel(ptr){
}
ListViewModel::~ListViewModel() {
clear();
}
int ListViewModel::rowCount(const QModelIndex &) const {
if (external())
return _externalData->size();
return _data.size();
}
QVariant ListViewModel::data(const QModelIndex &index, int role) const {
if (index.row() < rowCount(index)) {
if (static_cast<ListViewModelRoles>(role) == ListViewModelRoles::Blok) {
QObject *item = (external())? _externalData->value(index.row()) : _data.value(index.row());
return QVariant::fromValue(item);
}
}
return {};
}
QHash<int, QByteArray> ListViewModel::roleNames() const {
QHash<int, QByteArray> roles;
roles[static_cast<int>(ListViewModelRoles::Blok)] = "block";
return roles;
}
void ListViewModel::setExternalSource(const QList<InfoBlock *> *newData) {
if (external()) {
beginResetModel();
_externalData = newData;
endResetModel();
} else {
_externalData = newData;
}
setExternal(true);
}
void ListViewModel::setSource(const QList<InfoBlock*> &newData) {
if (!external()) {
beginResetModel();
clear(true);
_data = newData;
endResetModel();
} else {
clear(true);
_data = newData;
}
setExternal(false);
}
void ListViewModel::addSource(InfoBlock* data) {
if (!external()) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
_data.push_back(data);
endInsertRows();
} else {
_data.push_back(data);
}
}
void ListViewModel::clear(bool fast) {
for (auto i : _data) {
if (fast) {
i->deleteLater();
} else {
delete i;
}
}
_data.clear();
}
bool ListViewModel::external() const {
return _external;
}
void ListViewModel::setExternal(bool external) {
if (external != _external) {
beginResetModel();
_external = external;
endResetModel();
}
}
}

@ -0,0 +1,42 @@
#ifndef LISTVIEWMODEL_H
#define LISTVIEWMODEL_H
#include "BaseFront_global.h"
#include "infoblock.h"
#include "baselistmodel.h"
namespace BaseFront {
enum class ListViewModelRoles {
Blok = Qt::UserRole
};
class BASEFRONT_LIBRARYSHARED_EXPORT ListViewModel: public BaseListModel
{
Q_OBJECT
public:
ListViewModel(QObject *ptr = nullptr);
~ListViewModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QHash<int, QByteArray> roleNames() const;
void setExternalSource(const QList<InfoBlock*>* newData);
void setSource(const QList<InfoBlock*>& newData);
void addSource(InfoBlock *data);
void clear(bool fast = false);
bool external() const;
private:
void setExternal(bool external);
bool _external = false;
QList<InfoBlock*> _data;
const QList<InfoBlock*> *_externalData = nullptr;
};
}
#endif // LISTVIEWMODEL_H

@ -31,6 +31,7 @@ find_package(Qt5 COMPONENTS Core REQUIRED)
file(GLOB SOURCE_CPP
"src/*.cpp"
"src/Models/*.cpp"
"src/*.qrc"
)
@ -44,6 +45,6 @@ endif()
target_compile_definitions(${PROJECT_NAME}
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core ViewSolutions QuasarApp)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core ViewSolutions QuasarApp BaseFront)
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/Private")
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/Models")

@ -1 +1 @@
Subproject commit 7542bf0f4e5713088fc6a8be85322f02f9f678ae
Subproject commit 549142fba0f1fe23b2494164eb306ebc1d239c1d

@ -0,0 +1,48 @@
#include "mainmodel.h"
#include "reader.h"
MainModel::MainModel(QObject *parent) : QObject(parent) {
setListModel(new BaseFront::ListViewModel(this));
initQuasarApp();
}
bool MainModel::openPage(const QString &url) {
if (url == "QuasarApp") {
_listModel->setExternalSource(_QuasarAppPage);
return true;
}
return false;
}
QObject *MainModel::listModel() const {
return _listModel;
}
void MainModel::setListModel(QObject *listModel) {
auto model = dynamic_cast<BaseFront::ListViewModel*>(listModel);
if (!model || _listModel == model)
return;
_listModel = model;
emit listModelChanged(_listModel);
}
void MainModel::initQuasarApp() {
if (_QuasarAppPage) {
return;
}
_QuasarAppPage = new QList<BaseFront::InfoBlock*>();
auto block = new BaseFront::InfoBlock(this);
_QuasarAppPage->push_back(block);
block->setTitle(tr("QuasarApp Group"));
block->setSourceText(BaseFront::Reader::instance()->read(":/sources/html/QuasarAppAbout.htm"));
block->setBakcBroundPicture(":/img/images/LOGO.png");
}

@ -0,0 +1,32 @@
#ifndef MAINPAGE_H
#define MAINPAGE_H
#include <QObject>
#include <listviewmodel.h>
class MainModel : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject* listModel READ listModel WRITE setListModel NOTIFY listModelChanged)
public:
explicit MainModel(QObject *parent = nullptr);
Q_INVOKABLE bool openPage(const QString& url);
QObject* listModel() const;
public slots:
void setListModel(QObject* listModel);
signals:
void listModelChanged(QObject* listModel);
private:
void initQuasarApp();
QList<BaseFront::InfoBlock*> * _QuasarAppPage = nullptr;
BaseFront::ListViewModel *_listModel = nullptr;
};
#endif // MAINPAGE_H

@ -8,11 +8,16 @@ import QtQuick.Layouts 1.14
ToolBar {
property string currentPage: privateRoot.pages[privateRoot.currentItem]
RowLayout {
id: privateRoot
property int currrentItem : 0;
property int currentItem : 0;
property var pages: [
"QuasarApp"
]
ImageView {
background: (0 == privateRoot.currrentItem)? Material.accent : Material.background
background: (0 == privateRoot.currentItem)? Material.accent : Material.background
Layout.fillHeight: true
Layout.preferredWidth: height * 0.8
soucre : "qrc:/img/images/LOGO.png"
@ -20,12 +25,12 @@ ToolBar {
text: qsTr("Home")
onClicked: {
privateRoot.currrentItem = 0
privateRoot.currentItem = 0
}
}
ImageView {
background: (1 == privateRoot.currrentItem)? Material.accent : Material.background
background: (1 == privateRoot.currentItem)? Material.accent : Material.background
Layout.fillHeight: true
Layout.preferredWidth: height * 0.8
soucre : "qrc:/img/images/CQtDeployer logo.png"
@ -33,43 +38,43 @@ ToolBar {
toolTip: qsTr("Crossplatform tool for deploying cpp applications." +
" The CQtDeployer is application for extract all depends library of executable and create launch script for your application.");
onClicked: {
privateRoot.currrentItem = 1
privateRoot.currentItem = 1
}
}
ImageView {
background: (2 == privateRoot.currrentItem)? Material.accent : Material.background
background: (2 == privateRoot.currentItem)? Material.accent : Material.background
Layout.fillHeight: true
Layout.preferredWidth: height * 0.8
soucre : "qrc:/img/images/Qt-Secret Logo.png"
text: qsTr("Qt-Secret")
toolTip: qsTr("Fast encryption library supporting RSA and AES algorithms.");
onClicked: {
privateRoot.currrentItem = 2
privateRoot.currentItem = 2
}
}
ImageView {
background: (3 == privateRoot.currrentItem)? Material.accent : Material.background
background: (3 == privateRoot.currentItem)? Material.accent : Material.background
Layout.fillHeight: true
Layout.preferredWidth: height * 0.8
soucre : "qrc:/img/images/HanoiTowers.png"
text: qsTr("Hanoi Towers")
toolTip: qsTr("Simple Crossplatform game");
onClicked: {
privateRoot.currrentItem = 3
privateRoot.currentItem = 3
}
}
ImageView {
background: (4 == privateRoot.currrentItem)? Material.accent : Material.background
background: (4 == privateRoot.currentItem)? Material.accent : Material.background
Layout.fillHeight: true
Layout.preferredWidth: height * 0.8
soucre : "qrc:/img/images/QtBigint Logo.png"
text: qsTr("QtBigInt")
toolTip: qsTr("QtBigInt - Arbitrary-sized integer class for C++ and build system qmake and cmake. Power by minigmp.");
onClicked: {
privateRoot.currrentItem = 4
privateRoot.currentItem = 4
}
}
Item {

@ -1,37 +0,0 @@
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Controls.Material 2.14
import QtQuick.Controls.Universal 2.14
import QtQuick.Layouts 1.14
import ViewSolutionsModule 1.0
Item {
ListView {
id: viewPort
property real globalPos: 0
anchors.fill: parent
delegate: Component {
ViewPortPage {
viewPortDelegatH: 500
scrollPos: viewPort.globalPos
source: modelData
viewground: root
title: "QuasarApp Group"
text: ""
}
}
ScrollBar.vertical: ScrollBar {
onPositionChanged: {
viewPort.globalPos = position
}
}
model: [
"qrc:/img/res/LOGO.png",
]
}
}

@ -0,0 +1,30 @@
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Controls.Material 2.14
import QtQuick.Controls.Universal 2.14
import QtQuick.Layouts 1.14
import ViewSolutionsModule 1.0
ListView {
id: viewPort
property real globalPos: 0
anchors.fill: parent
delegate: Component {
ViewPortPage {
viewPortDelegatH: viewPort.height * 0.8
scrollPos: viewPort.globalPos
source: modelData
viewground: viewPort
title: titleTxt
text: sourceTxt
}
}
ScrollBar.vertical: ScrollBar {
onPositionChanged: {
viewPort.globalPos = position
}
}
}

@ -11,7 +11,7 @@ ApplicationWindow {
height: 480
title: qsTr("Hello World")
Material.theme: Material.System
Material.theme: Material.Light
Material.accent: Material.LightBlue
// Material.background: Material.Teal
// Material.foreground: Material.Pink
@ -19,6 +19,23 @@ ApplicationWindow {
header: Header {
height: root.height * 0.2
onCurrentPageChanged: {
mainModel.openPage(currentPage);
}
}
contentData: StackView {
id: stackView
initialItem: ListViewer {
id: sourceList
model: mainModel.listModel
anchors.fill: parent
}
anchors.fill: parent
}
}

@ -0,0 +1,11 @@
<b> The QuasarApp<b> is developing open source mobile and desktop applications.<br>
Our company has ben created on 2017 yahr and have experians of develepment android and desctop applications and games.
During our existence, we have accumulated more than 40 software components and ready-made solutions for the most diverse tasks.
This approach allows us now to create final products with impressive speed. If you have an idea for the application, we will hear you.
At the moment, we can offer support for our solutions for the following platforms:<br>
* <i> Linux </i><br>
* <i> Windows </i><br>
* <i> Android </i><br>
* <i> Web </i><br>

@ -1,9 +1,13 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickStyle>
#include <QQmlContext>
#include <BaseFront.h>
#include <viewsolutions.h>
#include "mainmodel.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
@ -17,11 +21,22 @@ int main(int argc, char *argv[])
return -1;
}
if (!BaseFront::init(&engine)) {
return -2;
}
auto root = engine.rootContext();
auto mainModel = MainModel();
root->setContextProperty("mainModel", &mainModel);
const QUrl url(QStringLiteral("qrc:/View/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
QCoreApplication::exit(-3);
}, Qt::QueuedConnection);
engine.load(url);

@ -2,7 +2,7 @@
<qresource prefix="/">
<file>View/main.qml</file>
<file>View/Header.qml</file>
<file>View/Home.qml</file>
<file>View/ListViewer.qml</file>
</qresource>
<qresource prefix="/img">
<file>images/HanoiTowers.png</file>
@ -11,4 +11,9 @@
<file>images/QtBigint Logo.png</file>
<file>images/Qt-Secret Logo.png</file>
</qresource>
<qresource prefix="/sources">
<file>html/QuasarAppAbout.htm</file>
<file>html/QuasarAppLinks.htm</file>
<file>html/QuasarAppRequest.htm</file>
</qresource>
</RCC>