Skip to content

Commit

Permalink
feat: adapt Javascript plugin to qt6.8
Browse files Browse the repository at this point in the history
log: as title
  • Loading branch information
LiHua000 committed Jan 23, 2025
1 parent ce33cbb commit ab87de6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ add_subdirectory(debugger)
add_subdirectory(codeeditor)
add_subdirectory(filebrowser)
if (QT_VERSION_MAJOR MATCHES 5)
#add_subdirectory(collaborators)
# add_subdirectory(javascript)
add_subdirectory(collaborators)
endif()
add_subdirectory(javascript)
add_subdirectory(console)
add_subdirectory(builder)
#remove it until system lock issue resolved.
Expand Down
35 changes: 33 additions & 2 deletions src/plugins/javascript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ cmake_minimum_required(VERSION 3.0.2)

project(javascript)

find_package(Qt${QT_DESIRED_VERSION} COMPONENTS Xml REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Xml REQUIRED)

if (${QT_VERSION_MAJOR} MATCHES 6)
find_package(Qt6 REQUIRED COMPONENTS Qml)
else()
find_package(Qt5 REQUIRED COMPONENTS Script ScriptTools Qml)
endif()

set(javascript_CPP
javascriptplugin.cpp
Expand Down Expand Up @@ -37,10 +43,35 @@ target_link_libraries(${PROJECT_NAME}
duc-base
duc-services
duc-common
Qt${QT_DESIRED_VERSION}::Xml
Qt${QT_VERSION_MAJOR}::Xml
${QtUseModules}
${PkgUserModules}
)

if (${QT_VERSION_MAJOR} MATCHES 6)
target_link_libraries(${PROJECT_NAME}
duc-framework
duc-base
duc-services
duc-common
Qt6::Xml
Qt6::Qml
${QtUseModules}
${PkgUserModules}
)
else()
target_link_libraries(${PROJECT_NAME}
duc-framework
duc-base
duc-services
duc-common
Qt5::Xml
Qt5::Script
Qt5::ScriptTools
${QtUseModules}
${PkgUserModules}
)
endif()

install_logo(${PROJECT_NAME}.svg)
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH})
3 changes: 3 additions & 0 deletions src/plugins/javascript/debugger/jsdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QTextStream>
#include <QDebug>
#include <QAction>
#if QT_VERSION <= 0x060000

#define SAFE_DELETE(p) \
if (p) { \
Expand Down Expand Up @@ -251,3 +252,5 @@ void JSDebugger::setupDebugEnv()
runState = kNoRun;
emit runStateChanged(kNoRun);
}

#endif
4 changes: 2 additions & 2 deletions src/plugins/javascript/debugger/jsdebugger.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef JSDebugger_H
#define JSDebugger_H

#include "base/abstractdebugger.h"

#if QT_VERSION <= 0x060000
#include <QObject>
#include <QtScript/QScriptEngine>
#include <QScriptEngineDebugger>
Expand Down Expand Up @@ -72,4 +71,5 @@ public slots:
AbstractWidget *codeEditor = nullptr;
};

#endif
#endif // JSDebugger_H
10 changes: 8 additions & 2 deletions src/plugins/javascript/javascriptplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
#include "services/window/windowservice.h"
#include "services/debugger/debuggerservice.h"
#include "base/abstractwidget.h"

#if QT_VERSION <= 0x060000
#include "debugger/jsdebugger.h"

#include <QtWidgets/QAction>
#include <QtScript>

#ifndef QT_NO_SCRIPTTOOLS
#include <QtScriptTools>
#endif
#endif

#include <QMainWindow>
#include <QApplication>

Expand Down Expand Up @@ -53,13 +58,14 @@ bool JavascriptPlugin::start()
projectService->implGenerator<JSProjectGenerator>(JSProjectGenerator::toolKitName(), &errorString);
}

// debugger register.
#if QT_VERSION <= 0x060000
// debugger register. Qt6 dose not supprt
auto jsDebugger = new JSDebugger(qApp);
auto debuggerService = dpfGetService(DebuggerService);
if (debuggerService && debuggerService->registerDebugger) {
debuggerService->registerDebugger("local", jsDebugger);
}

#endif
return true;
}

Expand Down
5 changes: 5 additions & 0 deletions src/plugins/javascript/jsgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ bool JSGenerator::prepareDebug(const QMap<QString, QVariant> &param, QString &re
{
Q_UNUSED(param)
Q_UNUSED(retMsg)
#if QT_VERSION <= 0x060000
return true;
#else
retMsg = tr("JavaScript can`t Debugging in Qt6 envrionment");
return false;
#endif
}

bool JSGenerator::requestDAPPort(const QString &ppid, const QMap<QString, QVariant> &param, QString &retMsg)
Expand Down

0 comments on commit ab87de6

Please sign in to comment.