167 lines
4.6 KiB
C++
167 lines
4.6 KiB
C++
#include "projectpageactivity.h"
|
|
|
|
#include <QJSEngine>
|
|
#include <QQmlContext>
|
|
#include <QQmlEngine>
|
|
#include "QQuickItem"
|
|
#include "quickhelper.h"
|
|
#include <QDebug>
|
|
#include "dynamicloader.h"
|
|
#include <QGuiApplication>
|
|
#include <QQmlApplicationEngine>
|
|
#include "settingsrepository.h"
|
|
#include "callbackwrapper.h"
|
|
#include "ArrDifferentTypes.h"
|
|
|
|
ProjectPageActivity::ProjectPageActivity(QQuickItem *item, QObject *parent)
|
|
: root(item), QObject(parent)
|
|
{
|
|
if (!item) {
|
|
qWarning() << "[C++] Root object is null";
|
|
return;
|
|
}
|
|
|
|
engine = qmlEngine(item);
|
|
|
|
if (!engine) {
|
|
qWarning() << "[C++] Failed to get QQmlEngine";
|
|
return;
|
|
}
|
|
|
|
loader = new DynamicLoader(engine,this);
|
|
connect(loader, &DynamicLoader::errorOccurred, this, &ProjectPageActivity::errorOccurredDynamycLoaderHandler);
|
|
init();
|
|
}
|
|
|
|
void ProjectPageActivity::pageChanged()
|
|
{
|
|
|
|
}
|
|
|
|
void ProjectPageActivity::setProjectFolders(QStringList &listFolders, QStringList &listFiles)
|
|
{
|
|
if (tileScrollablePanel) {
|
|
QString funcitonName = "setSourceData";
|
|
bool success = QMetaObject::invokeMethod(
|
|
tileScrollablePanel,
|
|
funcitonName.toUtf8().constData(),
|
|
Q_ARG(QVariant, listFolders),
|
|
Q_ARG(QVariant, listFiles)
|
|
);
|
|
}
|
|
}
|
|
|
|
void ProjectPageActivity::setSubDirrectoryName(const QString &name)
|
|
{
|
|
labelSubbdirrectionName->setProperty("text",name);
|
|
}
|
|
|
|
bool ProjectPageActivity::isAllElementsFound()
|
|
{
|
|
bool retCode = true;
|
|
|
|
projectObserver = QuickHelper::getQuickItem(root, PROJECT_OBSERVER);
|
|
if (!projectObserver) {
|
|
qWarning() << "Failed to get projectObserver:" << PROJECT_OBSERVER;
|
|
retCode = false;
|
|
}
|
|
|
|
labelSubbdirrectionName = QuickHelper::getQuickItem(root, LABEL_SUBDIRRECTORU_NAME);
|
|
if (!labelSubbdirrectionName) {
|
|
qWarning() << "Failed to get labelSubbdirrectionName:" << LABEL_SUBDIRRECTORU_NAME;
|
|
retCode = false;
|
|
}
|
|
|
|
return retCode;
|
|
}
|
|
|
|
|
|
void ProjectPageActivity::init()
|
|
{
|
|
if (!isAllElementsFound()) return;
|
|
|
|
QString componentText = R"(
|
|
import QtQuckApp
|
|
import QtQuick
|
|
import QtQuick.Controls
|
|
|
|
TileScrollablePanel {
|
|
id: tilePanel
|
|
anchors.fill: parent
|
|
|
|
onFolderClicked: function(name) {
|
|
// console.log("Папка нажата:", name)
|
|
quickUpdaterData.arrDifferentTypes[2] = name
|
|
quickUpdaterData.arrDifferentTypes[0].invoke()
|
|
}
|
|
|
|
onFileClicked: function(name) {
|
|
console.log("Файл нажат:", name)
|
|
quickUpdaterData.arrDifferentTypes[2] = name
|
|
quickUpdaterData.arrDifferentTypes[1].invoke()
|
|
}
|
|
|
|
// Component.onCompleted: {
|
|
// tilePanel.setSourceData(
|
|
// ["Документы", "Изображения", "Видео"],
|
|
// ["Отчет.pdf", "Презентация.pptx", "Список.txt"]
|
|
// )
|
|
//}
|
|
}
|
|
)";
|
|
|
|
QVariantList list;
|
|
|
|
CallbackWrapper *folderHandler = new CallbackWrapper([this]{folderClickHandler();},projectObserver);
|
|
CallbackWrapper *fileHandler = new CallbackWrapper([this]{fileClickHandler();},projectObserver);
|
|
|
|
list.append(QVariant::fromValue(folderHandler));
|
|
list.append(QVariant::fromValue(fileHandler));
|
|
|
|
QObject *addedComponent = 0;
|
|
projectModel = 0;
|
|
QuickHelper::addComponent(projectObserver, list, componentText, &addedComponent, &projectModel);
|
|
|
|
if (addedComponent) {
|
|
tileScrollablePanel = qobject_cast<QQuickItem*>(addedComponent);
|
|
|
|
|
|
|
|
// QStringList listFolders = {
|
|
// "Folder","Folder","Folder","Folder","Folder","Folder","Folder",
|
|
// "Folder","Folder","Folder","Folder","Folder","Folder","Folder",
|
|
// "Folder","Folder","Folder","Folder","Folder","Folder","Folder",
|
|
// "Folder","Folder","Folder","Folder","Folder","Folder","Folder",
|
|
// "Folder","Folder","Folder","Folder","Folder","Folder","Folder",
|
|
// "Folder","Folder","Folder","Folder","Folder","Folder","Folder"
|
|
// };
|
|
|
|
// QStringList listFiles = {
|
|
// "File"
|
|
// };
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void ProjectPageActivity::folderClickHandler() {
|
|
auto value = projectModel->getArrDifferentTypes();
|
|
emit folderClick(value[2].toString());
|
|
|
|
}
|
|
|
|
void ProjectPageActivity::fileClickHandler() {
|
|
auto value = projectModel->getArrDifferentTypes();
|
|
emit fileClick(value[2].toString());
|
|
}
|
|
|
|
void ProjectPageActivity::isAllowChangePage(const std::function<void ()> &continueChange, const std::function<void ()> &blockChange)
|
|
{
|
|
continueChange();
|
|
}
|
|
|
|
void ProjectPageActivity::errorOccurredDynamycLoaderHandler(const QString &message)
|
|
{
|
|
qDebug()<<"message";
|
|
}
|