mirror of
				https://github.com/Palm1r/QodeAssist.git
				synced 2025-10-31 08:14:36 -04:00 
			
		
		
		
	Fix all warnings in QML
This commit is contained in:
		| @ -15,7 +15,7 @@ find_package(Qt6 COMPONENTS Core Gui Quick Widgets Network REQUIRED) | |||||||
| add_subdirectory(llmcore) | add_subdirectory(llmcore) | ||||||
| add_subdirectory(settings) | add_subdirectory(settings) | ||||||
| add_subdirectory(logger) | add_subdirectory(logger) | ||||||
| add_subdirectory(chatview) | add_subdirectory(ChatView) | ||||||
|  |  | ||||||
| add_qtc_plugin(QodeAssist | add_qtc_plugin(QodeAssist | ||||||
|   PLUGIN_DEPENDS |   PLUGIN_DEPENDS | ||||||
|  | |||||||
| @ -1,8 +1,12 @@ | |||||||
| qt_add_library(QodeAssistChatView STATIC) | qt_add_library(QodeAssistChatView STATIC) | ||||||
| 
 | 
 | ||||||
|  | qt_policy(SET QTP0001 NEW) | ||||||
|  | 
 | ||||||
|  | # URI name should match the subdirectory name to suppress the warning | ||||||
| qt_add_qml_module(QodeAssistChatView | qt_add_qml_module(QodeAssistChatView | ||||||
|     URI ChatView |     URI ChatView | ||||||
|     VERSION 1.0 |     VERSION 1.0 | ||||||
|  |     DEPENDENCIES QtQuick | ||||||
|     QML_FILES |     QML_FILES | ||||||
|     qml/RootItem.qml |     qml/RootItem.qml | ||||||
|     qml/ChatItem.qml |     qml/ChatItem.qml | ||||||
| @ -31,5 +35,5 @@ target_link_libraries(QodeAssistChatView | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| target_include_directories(QodeAssistChatView | target_include_directories(QodeAssistChatView | ||||||
|     PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} |     PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} | ||||||
| ) | ) | ||||||
| @ -24,7 +24,7 @@ | |||||||
| 
 | 
 | ||||||
| #include <QAbstractListModel> | #include <QAbstractListModel> | ||||||
| #include <QJsonArray> | #include <QJsonArray> | ||||||
| #include <qqmlintegration.h> | #include <QtQmlIntegration> | ||||||
| 
 | 
 | ||||||
| namespace QodeAssist::Chat { | namespace QodeAssist::Chat { | ||||||
| 
 | 
 | ||||||
| @ -28,8 +28,12 @@ namespace QodeAssist::Chat { | |||||||
| 
 | 
 | ||||||
| class ChatRootView : public QQuickItem | class ChatRootView : public QQuickItem | ||||||
| { | { | ||||||
|     Q_OBJECT     |     Q_OBJECT | ||||||
|     Q_PROPERTY(ChatModel *chatModel READ chatModel NOTIFY chatModelChanged FINAL) |     // Possibly Qt bug: QTBUG-131004
 | ||||||
|  |     // The class type name must be fully qualified
 | ||||||
|  |     // including the namespace.
 | ||||||
|  |     // Otherwise qmlls can't find it.
 | ||||||
|  |     Q_PROPERTY(QodeAssist::Chat::ChatModel *chatModel READ chatModel NOTIFY chatModelChanged FINAL) | ||||||
|     Q_PROPERTY(QString currentTemplate READ currentTemplate NOTIFY currentTemplateChanged FINAL) |     Q_PROPERTY(QString currentTemplate READ currentTemplate NOTIFY currentTemplateChanged FINAL) | ||||||
|     Q_PROPERTY(QColor backgroundColor READ backgroundColor CONSTANT FINAL) |     Q_PROPERTY(QColor backgroundColor READ backgroundColor CONSTANT FINAL) | ||||||
|     Q_PROPERTY(QColor primaryColor READ primaryColor CONSTANT FINAL) |     Q_PROPERTY(QColor primaryColor READ primaryColor CONSTANT FINAL) | ||||||
| @ -27,7 +27,7 @@ namespace QodeAssist::Chat { | |||||||
| ChatWidget::ChatWidget(QWidget *parent) | ChatWidget::ChatWidget(QWidget *parent) | ||||||
|     : QQuickWidget(parent) |     : QQuickWidget(parent) | ||||||
| { | { | ||||||
|     setSource(QUrl("qrc:/ChatView/qml/RootItem.qml")); |     setSource(QUrl("qrc:/qt/qml/ChatView/qml/RootItem.qml")); | ||||||
|     setResizeMode(QQuickWidget::SizeRootObjectToView); |     setResizeMode(QQuickWidget::SizeRootObjectToView); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
							
								
								
									
										111
									
								
								ChatView/qml/ChatItem.qml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								ChatView/qml/ChatItem.qml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,111 @@ | |||||||
|  | /* | ||||||
|  |  * Copyright (C) 2024 Petr Mironychev | ||||||
|  |  * | ||||||
|  |  * This file is part of QodeAssist. | ||||||
|  |  * | ||||||
|  |  * QodeAssist is free software: you can redistribute it and/or modify | ||||||
|  |  * it under the terms of the GNU General Public License as published by | ||||||
|  |  * the Free Software Foundation, either version 3 of the License, or | ||||||
|  |  * (at your option) any later version. | ||||||
|  |  * | ||||||
|  |  * QodeAssist is distributed in the hope that it will be useful, | ||||||
|  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
|  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
|  |  * GNU General Public License for more details. | ||||||
|  |  * | ||||||
|  |  * You should have received a copy of the GNU General Public License | ||||||
|  |  * along with QodeAssist. If not, see <https://www.gnu.org/licenses/>. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | pragma ComponentBehavior: Bound | ||||||
|  |  | ||||||
|  | import QtQuick | ||||||
|  | import ChatView | ||||||
|  | import "./dialog" | ||||||
|  |  | ||||||
|  | Rectangle { | ||||||
|  |     id: root | ||||||
|  |  | ||||||
|  |     property alias msgModel: msgCreator.model | ||||||
|  |     property color fontColor | ||||||
|  |     property color codeBgColor | ||||||
|  |     property color selectionColor | ||||||
|  |  | ||||||
|  |     height: msgColumn.height | ||||||
|  |     radius: 8 | ||||||
|  |  | ||||||
|  |     Column { | ||||||
|  |         id: msgColumn | ||||||
|  |  | ||||||
|  |         anchors.verticalCenter: parent.verticalCenter | ||||||
|  |         width: parent.width | ||||||
|  |         spacing: 5 | ||||||
|  |  | ||||||
|  |         Repeater { | ||||||
|  |             id: msgCreator | ||||||
|  |             delegate: Loader { | ||||||
|  |                 id: msgCreatorDelegate | ||||||
|  |                 // Fix me: | ||||||
|  |                 // why does `required property MessagePart modelData` not work? | ||||||
|  |                 required property var modelData | ||||||
|  |  | ||||||
|  |                 width: parent.width | ||||||
|  |                 sourceComponent: { | ||||||
|  |                     // If `required property MessagePart modelData` is used | ||||||
|  |                     // and conversion to MessagePart fails, you're left | ||||||
|  |                     // with a nullptr. This tests that to prevent crashing. | ||||||
|  |                     if(!modelData) { | ||||||
|  |                         return undefined; | ||||||
|  |                     } | ||||||
|  |  | ||||||
|  |                     switch(modelData.type) { | ||||||
|  |                         case MessagePart.Text: return textComponent; | ||||||
|  |                         case MessagePart.Code: return codeBlockComponent; | ||||||
|  |                         default: return textComponent; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 Component { | ||||||
|  |                     id: textComponent | ||||||
|  |                     TextComponent { | ||||||
|  |                         itemData: msgCreatorDelegate.modelData | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 Component { | ||||||
|  |                     id: codeBlockComponent | ||||||
|  |                     CodeBlockComponent { | ||||||
|  |                         itemData: msgCreatorDelegate.modelData | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     component TextComponent : TextBlock { | ||||||
|  |         required property var itemData | ||||||
|  |         height: implicitHeight + 10 | ||||||
|  |         verticalAlignment: Text.AlignVCenter | ||||||
|  |         leftPadding: 10 | ||||||
|  |         text: itemData.text | ||||||
|  |         color: root.fontColor | ||||||
|  |         selectionColor: root.selectionColor | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     component CodeBlockComponent : CodeBlock { | ||||||
|  |         required property var itemData | ||||||
|  |         anchors { | ||||||
|  |             left: parent.left | ||||||
|  |             leftMargin: 10 | ||||||
|  |             right: parent.right | ||||||
|  |             rightMargin: 10 | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         code: itemData.text | ||||||
|  |         language: itemData.language | ||||||
|  |         color: root.codeBgColor | ||||||
|  |         selectionColor: root.selectionColor | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @ -17,6 +17,8 @@ | |||||||
|  * along with QodeAssist. If not, see <https://www.gnu.org/licenses/>. |  * along with QodeAssist. If not, see <https://www.gnu.org/licenses/>. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | pragma ComponentBehavior: Bound | ||||||
|  | 
 | ||||||
| import QtQuick | import QtQuick | ||||||
| import QtQuick.Controls | import QtQuick.Controls | ||||||
| import QtQuick.Controls.Basic as QQC | import QtQuick.Controls.Basic as QQC | ||||||
| @ -51,6 +53,7 @@ ChatRootView { | |||||||
|             cacheBuffer: 2000 |             cacheBuffer: 2000 | ||||||
| 
 | 
 | ||||||
|             delegate: ChatItem { |             delegate: ChatItem { | ||||||
|  |                 required property var model | ||||||
|                 width: ListView.view.width - scroll.width |                 width: ListView.view.width - scroll.width | ||||||
|                 msgModel: root.chatModel.processMessageContent(model.content) |                 msgModel: root.chatModel.processMessageContent(model.content) | ||||||
|                 color: model.roleType === ChatModel.User ? root.primaryColor : root.secondaryColor |                 color: model.roleType === ChatModel.User ? root.primaryColor : root.secondaryColor | ||||||
| @ -71,12 +74,12 @@ ChatRootView { | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             onCountChanged: { |             onCountChanged: { | ||||||
|                 scrollToBottom() |                 root.scrollToBottom() | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             onContentHeightChanged: { |             onContentHeightChanged: { | ||||||
|                 if (atYEnd) { |                 if (atYEnd) { | ||||||
|                     scrollToBottom() |                     root.scrollToBottom() | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @ -103,7 +106,7 @@ ChatRootView { | |||||||
|                 } |                 } | ||||||
|                 Keys.onPressed: function(event) { |                 Keys.onPressed: function(event) { | ||||||
|                     if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && !(event.modifiers & Qt.ShiftModifier)) { |                     if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && !(event.modifiers & Qt.ShiftModifier)) { | ||||||
|                         sendChatMessage() |                         root.sendChatMessage() | ||||||
|                         event.accepted = true; |                         event.accepted = true; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
| @ -119,7 +122,7 @@ ChatRootView { | |||||||
| 
 | 
 | ||||||
|                 Layout.alignment: Qt.AlignBottom |                 Layout.alignment: Qt.AlignBottom | ||||||
|                 text: qsTr("Send") |                 text: qsTr("Send") | ||||||
|                 onClicked: sendChatMessage() |                 onClicked: root.sendChatMessage() | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             Button { |             Button { | ||||||
| @ -135,7 +138,7 @@ ChatRootView { | |||||||
| 
 | 
 | ||||||
|                 Layout.alignment: Qt.AlignBottom |                 Layout.alignment: Qt.AlignBottom | ||||||
|                 text: qsTr("Clear Chat") |                 text: qsTr("Clear Chat") | ||||||
|                 onClicked: clearChat() |                 onClicked: root.clearChat() | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             CheckBox { |             CheckBox { | ||||||
| @ -61,7 +61,7 @@ Rectangle { | |||||||
|         text: root.code |         text: root.code | ||||||
|         readOnly: true |         readOnly: true | ||||||
|         selectByMouse: true |         selectByMouse: true | ||||||
|         font.family: monospaceFont |         font.family: root.monospaceFont | ||||||
|         font.pointSize: 12 |         font.pointSize: 12 | ||||||
|         color: parent.color.hslLightness > 0.5 ? "black" : "white" |         color: parent.color.hslLightness > 0.5 ? "black" : "white" | ||||||
|         wrapMode: Text.WordWrap |         wrapMode: Text.WordWrap | ||||||
| @ -1,91 +0,0 @@ | |||||||
| /* |  | ||||||
|  * Copyright (C) 2024 Petr Mironychev |  | ||||||
|  * |  | ||||||
|  * This file is part of QodeAssist. |  | ||||||
|  * |  | ||||||
|  * QodeAssist is free software: you can redistribute it and/or modify |  | ||||||
|  * it under the terms of the GNU General Public License as published by |  | ||||||
|  * the Free Software Foundation, either version 3 of the License, or |  | ||||||
|  * (at your option) any later version. |  | ||||||
|  * |  | ||||||
|  * QodeAssist is distributed in the hope that it will be useful, |  | ||||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |  | ||||||
|  * GNU General Public License for more details. |  | ||||||
|  * |  | ||||||
|  * You should have received a copy of the GNU General Public License |  | ||||||
|  * along with QodeAssist. If not, see <https://www.gnu.org/licenses/>. |  | ||||||
|  */ |  | ||||||
|  |  | ||||||
| import QtQuick |  | ||||||
| import QtQuick.Controls |  | ||||||
| import ChatView |  | ||||||
| import "./dialog" |  | ||||||
|  |  | ||||||
| Rectangle { |  | ||||||
|     id: root |  | ||||||
|  |  | ||||||
|     property alias msgModel: msgCreator.model |  | ||||||
|     property color fontColor |  | ||||||
|     property color codeBgColor |  | ||||||
|     property color selectionColor |  | ||||||
|  |  | ||||||
|     height: msgColumn.height |  | ||||||
|     radius: 8 |  | ||||||
|  |  | ||||||
|     Column { |  | ||||||
|         id: msgColumn |  | ||||||
|  |  | ||||||
|         anchors.verticalCenter: parent.verticalCenter |  | ||||||
|         width: parent.width |  | ||||||
|         spacing: 5 |  | ||||||
|  |  | ||||||
|         Repeater { |  | ||||||
|             id: msgCreator |  | ||||||
|             delegate: Loader { |  | ||||||
|                 property var itemData: modelData |  | ||||||
|  |  | ||||||
|                 width: parent.width |  | ||||||
|                 sourceComponent: { |  | ||||||
|                     switch(modelData.type) { |  | ||||||
|                     case MessagePart.Text: return textComponent; |  | ||||||
|                     case MessagePart.Code: return codeBlockComponent; |  | ||||||
|                     default: return textComponent; |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     Component { |  | ||||||
|         id: textComponent |  | ||||||
|  |  | ||||||
|         TextBlock { |  | ||||||
|             height: implicitHeight + 10 |  | ||||||
|             verticalAlignment: Text.AlignVCenter |  | ||||||
|             leftPadding: 10 |  | ||||||
|             text: itemData.text |  | ||||||
|             color: fontColor |  | ||||||
|             selectionColor: root.selectionColor |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     Component { |  | ||||||
|         id: codeBlockComponent |  | ||||||
|  |  | ||||||
|         CodeBlock { |  | ||||||
|             anchors { |  | ||||||
|                 left: parent.left |  | ||||||
|                 leftMargin: 10 |  | ||||||
|                 right: parent.right |  | ||||||
|                 rightMargin: 10 |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             code: itemData.text |  | ||||||
|             language: itemData.language |  | ||||||
|             color: root.codeBgColor |  | ||||||
|             selectionColor: root.selectionColor |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user