mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-10-07 12:37:06 -04:00
refactor: Move Message type enum to separate header
This commit is contained in:
@ -41,6 +41,7 @@ qt_add_qml_module(QodeAssistChatView
|
|||||||
ChatUtils.h ChatUtils.cpp
|
ChatUtils.h ChatUtils.cpp
|
||||||
ChatSerializer.hpp ChatSerializer.cpp
|
ChatSerializer.hpp ChatSerializer.cpp
|
||||||
ChatView.hpp ChatView.cpp
|
ChatView.hpp ChatView.cpp
|
||||||
|
ChatData.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(QodeAssistChatView
|
target_link_libraries(QodeAssistChatView
|
||||||
|
32
ChatView/ChatData.hpp
Normal file
32
ChatView/ChatData.hpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2025 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 once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QtQmlIntegration>
|
||||||
|
|
||||||
|
namespace QodeAssist::Chat {
|
||||||
|
Q_NAMESPACE
|
||||||
|
QML_NAMED_ELEMENT(MessagePartType)
|
||||||
|
|
||||||
|
enum class MessagePartType { Code, Text };
|
||||||
|
Q_ENUM_NS(MessagePartType)
|
||||||
|
|
||||||
|
} // namespace QodeAssist::Chat
|
@ -132,10 +132,10 @@ QList<MessagePart> ChatModel::processMessageContent(const QString &content) cons
|
|||||||
QString textBetween
|
QString textBetween
|
||||||
= content.mid(lastIndex, match.capturedStart() - lastIndex).trimmed();
|
= content.mid(lastIndex, match.capturedStart() - lastIndex).trimmed();
|
||||||
if (!textBetween.isEmpty()) {
|
if (!textBetween.isEmpty()) {
|
||||||
parts.append({MessagePart::Text, textBetween, ""});
|
parts.append({MessagePartType::Text, textBetween, ""});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parts.append({MessagePart::Code, match.captured(2).trimmed(), match.captured(1)});
|
parts.append({MessagePartType::Code, match.captured(2).trimmed(), match.captured(1)});
|
||||||
lastIndex = match.capturedEnd();
|
lastIndex = match.capturedEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,13 +148,15 @@ QList<MessagePart> ChatModel::processMessageContent(const QString &content) cons
|
|||||||
if (unclosedMatch.hasMatch()) {
|
if (unclosedMatch.hasMatch()) {
|
||||||
QString beforeCodeBlock = remainingText.left(unclosedMatch.capturedStart()).trimmed();
|
QString beforeCodeBlock = remainingText.left(unclosedMatch.capturedStart()).trimmed();
|
||||||
if (!beforeCodeBlock.isEmpty()) {
|
if (!beforeCodeBlock.isEmpty()) {
|
||||||
parts.append({MessagePart::Text, beforeCodeBlock, ""});
|
parts.append({MessagePartType::Text, beforeCodeBlock, ""});
|
||||||
}
|
}
|
||||||
|
|
||||||
parts.append(
|
parts.append(
|
||||||
{MessagePart::Code, unclosedMatch.captured(2).trimmed(), unclosedMatch.captured(1)});
|
{MessagePartType::Code,
|
||||||
|
unclosedMatch.captured(2).trimmed(),
|
||||||
|
unclosedMatch.captured(1)});
|
||||||
} else if (!remainingText.isEmpty()) {
|
} else if (!remainingText.isEmpty()) {
|
||||||
parts.append({MessagePart::Text, remainingText, ""});
|
parts.append({MessagePartType::Text, remainingText, ""});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,33 +19,24 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <qobject.h>
|
#include <QObject>
|
||||||
#include <qqmlintegration.h>
|
#include <QtQmlIntegration>
|
||||||
|
|
||||||
|
#include "ChatData.hpp"
|
||||||
|
|
||||||
namespace QodeAssist::Chat {
|
namespace QodeAssist::Chat {
|
||||||
Q_NAMESPACE
|
|
||||||
|
|
||||||
class MessagePart
|
class MessagePart
|
||||||
{
|
{
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
Q_PROPERTY(PartType type MEMBER type CONSTANT FINAL)
|
Q_PROPERTY(MessagePartType type MEMBER type CONSTANT FINAL)
|
||||||
Q_PROPERTY(QString text MEMBER text CONSTANT FINAL)
|
Q_PROPERTY(QString text MEMBER text CONSTANT FINAL)
|
||||||
Q_PROPERTY(QString language MEMBER language CONSTANT FINAL)
|
Q_PROPERTY(QString language MEMBER language CONSTANT FINAL)
|
||||||
QML_VALUE_TYPE(messagePart)
|
QML_VALUE_TYPE(messagePart)
|
||||||
public:
|
public:
|
||||||
enum PartType { Code, Text };
|
MessagePartType type;
|
||||||
Q_ENUM(PartType)
|
|
||||||
|
|
||||||
PartType type;
|
|
||||||
QString text;
|
QString text;
|
||||||
QString language;
|
QString language;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MessagePartType : public MessagePart
|
|
||||||
{
|
|
||||||
Q_GADGET
|
|
||||||
};
|
|
||||||
|
|
||||||
QML_NAMED_ELEMENT(MessagePart)
|
|
||||||
QML_FOREIGN_NAMESPACE(QodeAssist::Chat::MessagePartType)
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
@ -87,8 +87,8 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch(modelData.type) {
|
switch(modelData.type) {
|
||||||
case MessagePart.Text: return textComponent;
|
case MessagePartType.Text: return textComponent;
|
||||||
case MessagePart.Code: return codeBlockComponent;
|
case MessagePartType.Code: return codeBlockComponent;
|
||||||
default: return textComponent;
|
default: return textComponent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user