refactor: Full rework quick refactor (#257)

This commit is contained in:
Petr Mironychev
2025-11-15 14:51:47 +01:00
committed by GitHub
parent 9ecd285d1d
commit 953774aaa8
45 changed files with 2002 additions and 125 deletions

View File

@ -22,6 +22,7 @@
#include <utils/aspects.h>
#include <utils/layoutbuilder.h>
#include <QPushButton>
#include <QIcon>
class ButtonAspect : public Utils::BaseAspect
{
@ -36,6 +37,17 @@ public:
{
auto button = new QPushButton(m_buttonText);
button->setVisible(m_visible);
if (!m_icon.isNull()) {
button->setIcon(m_icon);
button->setText(""); // Clear text if icon is set
}
if (m_isCompact) {
button->setMaximumWidth(30);
button->setToolTip(m_tooltip.isEmpty() ? m_buttonText : m_tooltip);
}
connect(button, &QPushButton::clicked, this, &ButtonAspect::clicked);
connect(this, &ButtonAspect::visibleChanged, button, &QPushButton::setVisible);
parent.addItem(button);
@ -50,6 +62,9 @@ public:
}
QString m_buttonText;
QIcon m_icon;
QString m_tooltip;
bool m_isCompact = false;
signals:
void clicked();

View File

@ -7,6 +7,7 @@ add_library(QodeAssistSettings STATIC
SettingsTr.hpp
CodeCompletionSettings.hpp CodeCompletionSettings.cpp
ChatAssistantSettings.hpp ChatAssistantSettings.cpp
QuickRefactorSettings.hpp QuickRefactorSettings.cpp
ToolsSettings.hpp ToolsSettings.cpp
SettingsDialog.hpp SettingsDialog.cpp
ProjectSettings.hpp ProjectSettings.cpp

View File

@ -21,11 +21,12 @@
#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/icore.h>
#include <utils/detailswidget.h>
#include <utils/layoutbuilder.h>
#include <utils/utilsicons.h>
#include <QInputDialog>
#include <QLabel>
#include <QMessageBox>
#include <QTextEdit>
#include <QTimer>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qcompleter.h>
@ -117,7 +118,6 @@ GeneralSettings::GeneralSettings()
ccTemplateDescription.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
ccTemplateDescription.setReadOnly(true);
ccTemplateDescription.setDefaultValue("");
ccTemplateDescription.setLabelText(TrConstants::CURRENT_TEMPLATE_DESCRIPTION);
// preset1
specifyPreset1.setSettingsKey(Constants::CC_SPECIFY_PRESET1);
@ -203,7 +203,56 @@ GeneralSettings::GeneralSettings()
caTemplateDescription.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
caTemplateDescription.setReadOnly(true);
caTemplateDescription.setDefaultValue("");
caTemplateDescription.setLabelText(TrConstants::CURRENT_TEMPLATE_DESCRIPTION);
// quick refactor settings
initStringAspect(qrProvider, Constants::QR_PROVIDER, TrConstants::PROVIDER, "Ollama");
qrProvider.setReadOnly(true);
qrSelectProvider.m_buttonText = TrConstants::SELECT;
initStringAspect(qrModel, Constants::QR_MODEL, TrConstants::MODEL, "qwen2.5-coder:7b");
qrModel.setHistoryCompleter(Constants::QR_MODEL_HISTORY);
qrSelectModel.m_buttonText = TrConstants::SELECT;
initStringAspect(qrTemplate, Constants::QR_TEMPLATE, TrConstants::TEMPLATE, "Ollama Chat");
qrTemplate.setReadOnly(true);
qrSelectTemplate.m_buttonText = TrConstants::SELECT;
initStringAspect(qrUrl, Constants::QR_URL, TrConstants::URL, "http://localhost:11434");
qrUrl.setHistoryCompleter(Constants::QR_URL_HISTORY);
qrSetUrl.m_buttonText = TrConstants::SELECT;
qrEndpointMode.setSettingsKey(Constants::QR_ENDPOINT_MODE);
qrEndpointMode.setDisplayStyle(Utils::SelectionAspect::DisplayStyle::ComboBox);
qrEndpointMode.addOption("Auto");
qrEndpointMode.addOption("Custom");
qrEndpointMode.addOption("FIM");
qrEndpointMode.addOption("Chat");
qrEndpointMode.setDefaultValue("Auto");
initStringAspect(qrCustomEndpoint, Constants::QR_CUSTOM_ENDPOINT, TrConstants::ENDPOINT_MODE, "");
qrCustomEndpoint.setHistoryCompleter(Constants::QR_CUSTOM_ENDPOINT_HISTORY);
qrStatus.setDisplayStyle(Utils::StringAspect::LabelDisplay);
qrStatus.setLabelText(TrConstants::STATUS);
qrStatus.setDefaultValue("");
qrTest.m_buttonText = TrConstants::TEST;
qrTemplateDescription.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
qrTemplateDescription.setReadOnly(true);
qrTemplateDescription.setDefaultValue("");
ccShowTemplateInfo.m_icon = Utils::Icons::INFO.icon();
ccShowTemplateInfo.m_tooltip = Tr::tr("Show template information");
ccShowTemplateInfo.m_isCompact = true;
caShowTemplateInfo.m_icon = Utils::Icons::INFO.icon();
caShowTemplateInfo.m_tooltip = Tr::tr("Show template information");
caShowTemplateInfo.m_isCompact = true;
qrShowTemplateInfo.m_icon = Utils::Icons::INFO.icon();
qrShowTemplateInfo.m_tooltip = Tr::tr("Show template information");
qrShowTemplateInfo.m_isCompact = true;
readSettings();
@ -215,6 +264,7 @@ GeneralSettings::GeneralSettings()
ccCustomEndpoint.setEnabled(ccEndpointMode.stringValue() == "Custom");
ccPreset1CustomEndpoint.setEnabled(ccPreset1EndpointMode.stringValue() == "Custom");
caCustomEndpoint.setEnabled(caEndpointMode.stringValue() == "Custom");
qrCustomEndpoint.setEnabled(qrEndpointMode.stringValue() == "Custom");
setLayouter([this]() {
using namespace Layouting;
@ -224,7 +274,7 @@ GeneralSettings::GeneralSettings()
ccGrid.addRow({ccUrl, ccSetUrl});
ccGrid.addRow({ccCustomEndpoint, ccEndpointMode});
ccGrid.addRow({ccModel, ccSelectModel});
ccGrid.addRow({ccTemplate, ccSelectTemplate});
ccGrid.addRow({ccTemplate, ccSelectTemplate, ccShowTemplateInfo});
auto ccPreset1Grid = Grid{};
ccPreset1Grid.addRow({ccPreset1Provider, ccPreset1SelectProvider});
@ -238,21 +288,27 @@ GeneralSettings::GeneralSettings()
caGrid.addRow({caUrl, caSetUrl});
caGrid.addRow({caCustomEndpoint, caEndpointMode});
caGrid.addRow({caModel, caSelectModel});
caGrid.addRow({caTemplate, caSelectTemplate});
caGrid.addRow({caTemplate, caSelectTemplate, caShowTemplateInfo});
auto qrGrid = Grid{};
qrGrid.addRow({qrProvider, qrSelectProvider});
qrGrid.addRow({qrUrl, qrSetUrl});
qrGrid.addRow({qrCustomEndpoint, qrEndpointMode});
qrGrid.addRow({qrModel, qrSelectModel});
qrGrid.addRow({qrTemplate, qrSelectTemplate, qrShowTemplateInfo});
auto ccGroup = Group{
title(TrConstants::CODE_COMPLETION),
Column{
ccGrid,
ccTemplateDescription,
Row{specifyPreset1, preset1Language, Stretch{1}},
ccPreset1Grid}};
auto caGroup = Group{
title(TrConstants::CHAT_ASSISTANT),
Column{
caGrid,
caTemplateDescription}};
title(TrConstants::CHAT_ASSISTANT), Column{caGrid}};
auto qrGroup = Group{
title(TrConstants::QUICK_REFACTOR), Column{qrGrid}};
auto rootLayout = Column{
Row{enableQodeAssist, Stretch{1}, Row{checkUpdate, resetToDefaults}},
@ -262,6 +318,8 @@ GeneralSettings::GeneralSettings()
ccGroup,
Space{8},
caGroup,
Space{8},
qrGroup,
Stretch{1}};
return rootLayout;
@ -307,6 +365,9 @@ void GeneralSettings::showModelsNotFoundDialog(Utils::StringAspect &aspect)
} else if (&aspect == &caModel) {
providerButton = &caSelectProvider;
urlButton = &caSetUrl;
} else if (&aspect == &qrModel) {
providerButton = &qrSelectProvider;
urlButton = &qrSetUrl;
}
if (providerButton && urlButton) {
@ -357,7 +418,8 @@ void GeneralSettings::showModelsNotSupportedDialog(Utils::StringAspect &aspect)
QString key = QString("CompleterHistory/")
.append(
(&aspect == &ccModel) ? Constants::CC_MODEL_HISTORY
: Constants::CA_MODEL_HISTORY);
: (&aspect == &caModel) ? Constants::CA_MODEL_HISTORY
: Constants::QR_MODEL_HISTORY);
#if QODEASSIST_QT_CREATOR_VERSION >= QT_VERSION_CHECK(18, 0, 0)
QStringList historyList
= Utils::QtcSettings().value(Utils::Key(key.toLocal8Bit())).toStringList();
@ -399,7 +461,8 @@ void GeneralSettings::showUrlSelectionDialog(
.append(
(&aspect == &ccUrl) ? Constants::CC_URL_HISTORY
: (&aspect == &ccPreset1Url) ? Constants::CC_PRESET1_URL_HISTORY
: Constants::CA_URL_HISTORY);
: (&aspect == &caUrl) ? Constants::CA_URL_HISTORY
: Constants::QR_URL_HISTORY);
#if QODEASSIST_QT_CREATOR_VERSION >= QT_VERSION_CHECK(18, 0, 0)
QStringList historyList
= Utils::QtcSettings().value(Utils::Key(key.toLocal8Bit())).toStringList();
@ -431,6 +494,31 @@ void GeneralSettings::showUrlSelectionDialog(
dialog.exec();
}
void GeneralSettings::showTemplateInfoDialog(const Utils::StringAspect &descriptionAspect, const QString &templateName)
{
SettingsDialog dialog(Tr::tr("Template Information"));
dialog.addLabel(QString("<b>%1:</b> %2").arg(Tr::tr("Template"), templateName));
dialog.addSpacing();
auto *descriptionLabel = new QLabel(Tr::tr("Description:"));
dialog.layout()->addWidget(descriptionLabel);
auto *textEdit = new QTextEdit();
textEdit->setReadOnly(true);
textEdit->setMinimumHeight(200);
textEdit->setMinimumWidth(500);
textEdit->setText(descriptionAspect.value());
dialog.layout()->addWidget(textEdit);
dialog.addSpacing();
auto *closeButton = new QPushButton(TrConstants::CLOSE);
connect(closeButton, &QPushButton::clicked, &dialog, &QDialog::accept);
dialog.buttonLayout()->addWidget(closeButton);
dialog.exec();
}
void GeneralSettings::updatePreset1Visiblity(bool state)
{
ccPreset1Provider.setVisible(specifyPreset1.volatileValue());
@ -471,6 +559,22 @@ void GeneralSettings::setupConnections()
caCustomEndpoint.setEnabled(
caEndpointMode.volatileValue() == caEndpointMode.indexForDisplay("Custom"));
});
connect(&qrEndpointMode, &Utils::BaseAspect::volatileValueChanged, this, [this]() {
qrCustomEndpoint.setEnabled(
qrEndpointMode.volatileValue() == qrEndpointMode.indexForDisplay("Custom"));
});
connect(&ccShowTemplateInfo, &ButtonAspect::clicked, this, [this]() {
showTemplateInfoDialog(ccTemplateDescription, ccTemplate.value());
});
connect(&caShowTemplateInfo, &ButtonAspect::clicked, this, [this]() {
showTemplateInfoDialog(caTemplateDescription, caTemplate.value());
});
connect(&qrShowTemplateInfo, &ButtonAspect::clicked, this, [this]() {
showTemplateInfoDialog(qrTemplateDescription, qrTemplate.value());
});
}
void GeneralSettings::resetPageToDefaults()
@ -506,6 +610,12 @@ void GeneralSettings::resetPageToDefaults()
resetAspect(ccPreset1CustomEndpoint);
resetAspect(caEndpointMode);
resetAspect(caCustomEndpoint);
resetAspect(qrProvider);
resetAspect(qrModel);
resetAspect(qrTemplate);
resetAspect(qrUrl);
resetAspect(qrEndpointMode);
resetAspect(qrCustomEndpoint);
writeSettings();
}
}

View File

@ -20,9 +20,14 @@
#pragma once
#include <utils/aspects.h>
#include <QPointer>
#include "ButtonAspect.hpp"
namespace Utils {
class DetailsWidget;
}
namespace QodeAssist::LLMCore {
class Provider;
}
@ -102,6 +107,31 @@ public:
Utils::StringAspect caTemplateDescription{this};
// quick refactor settings
Utils::StringAspect qrProvider{this};
ButtonAspect qrSelectProvider{this};
Utils::StringAspect qrModel{this};
ButtonAspect qrSelectModel{this};
Utils::StringAspect qrTemplate{this};
ButtonAspect qrSelectTemplate{this};
Utils::StringAspect qrUrl{this};
ButtonAspect qrSetUrl{this};
Utils::SelectionAspect qrEndpointMode{this};
Utils::StringAspect qrCustomEndpoint{this};
Utils::StringAspect qrStatus{this};
ButtonAspect qrTest{this};
Utils::StringAspect qrTemplateDescription{this};
ButtonAspect ccShowTemplateInfo{this};
ButtonAspect caShowTemplateInfo{this};
ButtonAspect qrShowTemplateInfo{this};
void showSelectionDialog(
const QStringList &data,
Utils::StringAspect &aspect,
@ -114,6 +144,8 @@ public:
void showUrlSelectionDialog(Utils::StringAspect &aspect, const QStringList &predefinedUrls);
void showTemplateInfoDialog(const Utils::StringAspect &descriptionAspect, const QString &templateName);
void updatePreset1Visiblity(bool state);
private:

View File

@ -0,0 +1,295 @@
/*
* Copyright (C) 2024-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/>.
*/
#include "QuickRefactorSettings.hpp"
#include <coreplugin/dialogs/ioptionspage.h>
#include <coreplugin/icore.h>
#include <utils/layoutbuilder.h>
#include <QMessageBox>
#include "SettingsConstants.hpp"
#include "SettingsTr.hpp"
#include "SettingsUtils.hpp"
namespace QodeAssist::Settings {
QuickRefactorSettings &quickRefactorSettings()
{
static QuickRefactorSettings settings;
return settings;
}
QuickRefactorSettings::QuickRefactorSettings()
{
setAutoApply(false);
setDisplayName(Tr::tr("Quick Refactor"));
// General Parameters Settings
temperature.setSettingsKey(Constants::QR_TEMPERATURE);
temperature.setLabelText(Tr::tr("Temperature:"));
temperature.setDefaultValue(0.5);
temperature.setRange(0.0, 2.0);
temperature.setSingleStep(0.1);
maxTokens.setSettingsKey(Constants::QR_MAX_TOKENS);
maxTokens.setLabelText(Tr::tr("Max Tokens:"));
maxTokens.setRange(-1, 200000);
maxTokens.setDefaultValue(2000);
// Advanced Parameters
useTopP.setSettingsKey(Constants::QR_USE_TOP_P);
useTopP.setDefaultValue(false);
useTopP.setLabelText(Tr::tr("Top P:"));
topP.setSettingsKey(Constants::QR_TOP_P);
topP.setDefaultValue(0.9);
topP.setRange(0.0, 1.0);
topP.setSingleStep(0.1);
useTopK.setSettingsKey(Constants::QR_USE_TOP_K);
useTopK.setDefaultValue(false);
useTopK.setLabelText(Tr::tr("Top K:"));
topK.setSettingsKey(Constants::QR_TOP_K);
topK.setDefaultValue(50);
topK.setRange(1, 1000);
usePresencePenalty.setSettingsKey(Constants::QR_USE_PRESENCE_PENALTY);
usePresencePenalty.setDefaultValue(false);
usePresencePenalty.setLabelText(Tr::tr("Presence Penalty:"));
presencePenalty.setSettingsKey(Constants::QR_PRESENCE_PENALTY);
presencePenalty.setDefaultValue(0.0);
presencePenalty.setRange(-2.0, 2.0);
presencePenalty.setSingleStep(0.1);
useFrequencyPenalty.setSettingsKey(Constants::QR_USE_FREQUENCY_PENALTY);
useFrequencyPenalty.setDefaultValue(false);
useFrequencyPenalty.setLabelText(Tr::tr("Frequency Penalty:"));
frequencyPenalty.setSettingsKey(Constants::QR_FREQUENCY_PENALTY);
frequencyPenalty.setDefaultValue(0.0);
frequencyPenalty.setRange(-2.0, 2.0);
frequencyPenalty.setSingleStep(0.1);
// Ollama Settings
ollamaLivetime.setSettingsKey(Constants::QR_OLLAMA_LIVETIME);
ollamaLivetime.setToolTip(
Tr::tr("Time to suspend Ollama after completion request (in minutes), "
"Only Ollama, -1 to disable"));
ollamaLivetime.setLabelText("Livetime:");
ollamaLivetime.setDefaultValue("5m");
ollamaLivetime.setDisplayStyle(Utils::StringAspect::LineEditDisplay);
contextWindow.setSettingsKey(Constants::QR_OLLAMA_CONTEXT_WINDOW);
contextWindow.setLabelText(Tr::tr("Context Window:"));
contextWindow.setRange(-1, 10000);
contextWindow.setDefaultValue(2048);
useTools.setSettingsKey(Constants::QR_USE_TOOLS);
useTools.setLabelText(Tr::tr("Enable Tools"));
useTools.setToolTip(
Tr::tr("Enable AI tools/functions for quick refactoring (allows reading project files, "
"searching code, etc.)"));
useTools.setDefaultValue(false);
useThinking.setSettingsKey(Constants::QR_USE_THINKING);
useThinking.setLabelText(Tr::tr("Enable Thinking Mode"));
useThinking.setToolTip(
Tr::tr("Enable extended thinking mode for complex refactoring tasks (supported by "
"compatible models like Claude and Google AI)"));
useThinking.setDefaultValue(false);
thinkingBudgetTokens.setSettingsKey(Constants::QR_THINKING_BUDGET_TOKENS);
thinkingBudgetTokens.setLabelText(Tr::tr("Thinking Budget Tokens:"));
thinkingBudgetTokens.setToolTip(
Tr::tr("Number of tokens allocated for thinking process. Use -1 for dynamic thinking "
"(model decides), 0 to disable, or positive value for custom budget"));
thinkingBudgetTokens.setRange(-1, 100000);
thinkingBudgetTokens.setDefaultValue(10000);
thinkingMaxTokens.setSettingsKey(Constants::QR_THINKING_MAX_TOKENS);
thinkingMaxTokens.setLabelText(Tr::tr("Thinking Max Output Tokens:"));
thinkingMaxTokens.setToolTip(
Tr::tr("Maximum output tokens when thinking mode is enabled (includes thinking + response)"));
thinkingMaxTokens.setRange(1000, 200000);
thinkingMaxTokens.setDefaultValue(16000);
// Context Settings
readFullFile.setSettingsKey(Constants::QR_READ_FULL_FILE);
readFullFile.setLabelText(Tr::tr("Read Full File"));
readFullFile.setDefaultValue(false);
readFileParts.setLabelText(Tr::tr("Read Strings Before Cursor:"));
readFileParts.setDefaultValue(true);
readStringsBeforeCursor.setSettingsKey(Constants::QR_READ_STRINGS_BEFORE_CURSOR);
readStringsBeforeCursor.setLabelText(Tr::tr("Lines Before Cursor/Selection:"));
readStringsBeforeCursor.setToolTip(
Tr::tr("Number of lines to include before cursor or selection for context"));
readStringsBeforeCursor.setRange(0, 10000);
readStringsBeforeCursor.setDefaultValue(50);
readStringsAfterCursor.setSettingsKey(Constants::QR_READ_STRINGS_AFTER_CURSOR);
readStringsAfterCursor.setLabelText(Tr::tr("Lines After Cursor/Selection:"));
readStringsAfterCursor.setToolTip(
Tr::tr("Number of lines to include after cursor or selection for context"));
readStringsAfterCursor.setRange(0, 10000);
readStringsAfterCursor.setDefaultValue(30);
systemPrompt.setSettingsKey(Constants::QR_SYSTEM_PROMPT);
systemPrompt.setLabelText(Tr::tr("System Prompt:"));
systemPrompt.setDisplayStyle(Utils::StringAspect::TextEditDisplay);
systemPrompt.setDefaultValue(
"You are an expert C++, Qt, and QML code completion assistant. Your task is to provide "
"precise and contextually appropriate code completions to insert depending on user "
"instructions.\n\n");
resetToDefaults.m_buttonText = TrConstants::RESET_TO_DEFAULTS;
readSettings();
readFileParts.setValue(!readFullFile.value());
setupConnections();
setLayouter([this]() {
using namespace Layouting;
auto genGrid = Grid{};
genGrid.addRow({Row{temperature}});
genGrid.addRow({Row{maxTokens}});
auto advancedGrid = Grid{};
advancedGrid.addRow({useTopP, topP});
advancedGrid.addRow({useTopK, topK});
advancedGrid.addRow({usePresencePenalty, presencePenalty});
advancedGrid.addRow({useFrequencyPenalty, frequencyPenalty});
auto ollamaGrid = Grid{};
ollamaGrid.addRow({ollamaLivetime});
ollamaGrid.addRow({contextWindow});
auto toolsGrid = Grid{};
toolsGrid.addRow({useTools});
toolsGrid.addRow({useThinking});
toolsGrid.addRow({thinkingBudgetTokens});
toolsGrid.addRow({thinkingMaxTokens});
auto contextGrid = Grid{};
contextGrid.addRow({Row{readFullFile}});
contextGrid.addRow({Row{readFileParts, readStringsBeforeCursor, readStringsAfterCursor}});
return Column{
Row{Stretch{1}, resetToDefaults},
Space{8},
Group{
title(Tr::tr("General Parameters")),
Row{genGrid, Stretch{1}},
},
Space{8},
Group{title(Tr::tr("Advanced Parameters")), Column{Row{advancedGrid, Stretch{1}}}},
Space{8},
Group{title(Tr::tr("Tools Settings")), Column{Row{toolsGrid, Stretch{1}}}},
Space{8},
Group{title(Tr::tr("Context Settings")), Column{Row{contextGrid, Stretch{1}}}},
Space{8},
Group{title(Tr::tr("Prompt Settings")), Column{Row{systemPrompt}}},
Space{8},
Group{title(Tr::tr("Ollama Settings")), Column{Row{ollamaGrid, Stretch{1}}}},
Stretch{1}};
});
}
void QuickRefactorSettings::setupConnections()
{
connect(
&resetToDefaults,
&ButtonAspect::clicked,
this,
&QuickRefactorSettings::resetSettingsToDefaults);
connect(&readFullFile, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
if (readFullFile.volatileValue()) {
readFileParts.setValue(false);
writeSettings();
}
});
connect(&readFileParts, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
if (readFileParts.volatileValue()) {
readFullFile.setValue(false);
writeSettings();
}
});
}
void QuickRefactorSettings::resetSettingsToDefaults()
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(
Core::ICore::dialogParent(),
Tr::tr("Reset Settings"),
Tr::tr("Are you sure you want to reset all settings to default values?"),
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
resetAspect(temperature);
resetAspect(maxTokens);
resetAspect(useTopP);
resetAspect(topP);
resetAspect(useTopK);
resetAspect(topK);
resetAspect(usePresencePenalty);
resetAspect(presencePenalty);
resetAspect(useFrequencyPenalty);
resetAspect(frequencyPenalty);
resetAspect(ollamaLivetime);
resetAspect(contextWindow);
resetAspect(useTools);
resetAspect(useThinking);
resetAspect(thinkingBudgetTokens);
resetAspect(thinkingMaxTokens);
resetAspect(readFullFile);
resetAspect(readFileParts);
resetAspect(readStringsBeforeCursor);
resetAspect(readStringsAfterCursor);
resetAspect(systemPrompt);
writeSettings();
}
}
class QuickRefactorSettingsPage : public Core::IOptionsPage
{
public:
QuickRefactorSettingsPage()
{
setId(Constants::QODE_ASSIST_QUICK_REFACTOR_SETTINGS_PAGE_ID);
setDisplayName(Tr::tr("Quick Refactor"));
setCategory(Constants::QODE_ASSIST_GENERAL_OPTIONS_CATEGORY);
setSettingsProvider([] { return &quickRefactorSettings(); });
}
};
const QuickRefactorSettingsPage quickRefactorSettingsPage;
} // namespace QodeAssist::Settings

View File

@ -0,0 +1,81 @@
/*
* Copyright (C) 2024-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 <utils/aspects.h>
#include "ButtonAspect.hpp"
namespace QodeAssist::Settings {
class QuickRefactorSettings : public Utils::AspectContainer
{
public:
QuickRefactorSettings();
ButtonAspect resetToDefaults{this};
// General Parameters Settings
Utils::DoubleAspect temperature{this};
Utils::IntegerAspect maxTokens{this};
// Advanced Parameters
Utils::BoolAspect useTopP{this};
Utils::DoubleAspect topP{this};
Utils::BoolAspect useTopK{this};
Utils::IntegerAspect topK{this};
Utils::BoolAspect usePresencePenalty{this};
Utils::DoubleAspect presencePenalty{this};
Utils::BoolAspect useFrequencyPenalty{this};
Utils::DoubleAspect frequencyPenalty{this};
// Ollama Settings
Utils::StringAspect ollamaLivetime{this};
Utils::IntegerAspect contextWindow{this};
// Tools Settings
Utils::BoolAspect useTools{this};
// Thinking Settings
Utils::BoolAspect useThinking{this};
Utils::IntegerAspect thinkingBudgetTokens{this};
Utils::IntegerAspect thinkingMaxTokens{this};
// Context Settings
Utils::BoolAspect readFullFile{this};
Utils::BoolAspect readFileParts{this};
Utils::IntegerAspect readStringsBeforeCursor{this};
Utils::IntegerAspect readStringsAfterCursor{this};
// Prompt Settings
Utils::StringAspect systemPrompt{this};
private:
void setupConnections();
void resetSettingsToDefaults();
};
QuickRefactorSettings &quickRefactorSettings();
} // namespace QodeAssist::Settings

View File

@ -49,6 +49,17 @@ const char CA_ENDPOINT_MODE[] = "QodeAssist.caEndpointMode";
const char CA_CUSTOM_ENDPOINT[] = "QodeAssist.caCustomEndpoint";
const char CA_CUSTOM_ENDPOINT_HISTORY[] = "QodeAssist.caCustomEndpointHistory";
// quick refactor settings
const char QR_PROVIDER[] = "QodeAssist.qrProvider";
const char QR_MODEL[] = "QodeAssist.qrModel";
const char QR_MODEL_HISTORY[] = "QodeAssist.qrModelHistory";
const char QR_TEMPLATE[] = "QodeAssist.qrTemplate";
const char QR_URL[] = "QodeAssist.qrUrl";
const char QR_URL_HISTORY[] = "QodeAssist.qrUrlHistory";
const char QR_ENDPOINT_MODE[] = "QodeAssist.qrEndpointMode";
const char QR_CUSTOM_ENDPOINT[] = "QodeAssist.qrCustomEndpoint";
const char QR_CUSTOM_ENDPOINT_HISTORY[] = "QodeAssist.qrCustomEndpointHistory";
const char CC_SPECIFY_PRESET1[] = "QodeAssist.ccSpecifyPreset1";
const char CC_PRESET1_LANGUAGE[] = "QodeAssist.ccPreset1Language";
const char CC_PRESET1_PROVIDER[] = "QodeAssist.ccPreset1Provider";
@ -98,14 +109,16 @@ const char QODE_ASSIST_CODE_COMPLETION_SETTINGS_PAGE_ID[]
= "QodeAssist.2CodeCompletionSettingsPageId";
const char QODE_ASSIST_CHAT_ASSISTANT_SETTINGS_PAGE_ID[]
= "QodeAssist.3ChatAssistantSettingsPageId";
const char QODE_ASSIST_TOOLS_SETTINGS_PAGE_ID[] = "QodeAssist.4ToolsSettingsPageId";
const char QODE_ASSIST_CUSTOM_PROMPT_SETTINGS_PAGE_ID[] = "QodeAssist.5CustomPromptSettingsPageId";
const char QODE_ASSIST_QUICK_REFACTOR_SETTINGS_PAGE_ID[]
= "QodeAssist.4QuickRefactorSettingsPageId";
const char QODE_ASSIST_TOOLS_SETTINGS_PAGE_ID[] = "QodeAssist.5ToolsSettingsPageId";
const char QODE_ASSIST_CUSTOM_PROMPT_SETTINGS_PAGE_ID[] = "QodeAssist.6CustomPromptSettingsPageId";
const char QODE_ASSIST_GENERAL_OPTIONS_CATEGORY[] = "QodeAssist.Category";
const char QODE_ASSIST_GENERAL_OPTIONS_DISPLAY_CATEGORY[] = "QodeAssist";
// Provider Settings Page ID
const char QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID[] = "QodeAssist.6ProviderSettingsPageId";
const char QODE_ASSIST_PROVIDER_SETTINGS_PAGE_ID[] = "QodeAssist.7ProviderSettingsPageId";
// Provider API Keys
const char OPEN_ROUTER_API_KEY[] = "QodeAssist.openRouterApiKey";
@ -178,4 +191,26 @@ const char CA_CODE_FONT_SIZE[] = "QodeAssist.caCodeFontSize";
const char CA_TEXT_FORMAT[] = "QodeAssist.caTextFormat";
const char CA_CHAT_RENDERER[] = "QodeAssist.caChatRenderer";
// quick refactor preset prompt settings
const char QR_TEMPERATURE[] = "QodeAssist.qrTemperature";
const char QR_MAX_TOKENS[] = "QodeAssist.qrMaxTokens";
const char QR_USE_TOP_P[] = "QodeAssist.qrUseTopP";
const char QR_TOP_P[] = "QodeAssist.qrTopP";
const char QR_USE_TOP_K[] = "QodeAssist.qrUseTopK";
const char QR_TOP_K[] = "QodeAssist.qrTopK";
const char QR_USE_PRESENCE_PENALTY[] = "QodeAssist.qrUsePresencePenalty";
const char QR_PRESENCE_PENALTY[] = "QodeAssist.qrPresencePenalty";
const char QR_USE_FREQUENCY_PENALTY[] = "QodeAssist.qrUseFrequencyPenalty";
const char QR_FREQUENCY_PENALTY[] = "QodeAssist.qrFrequencyPenalty";
const char QR_OLLAMA_LIVETIME[] = "QodeAssist.qrOllamaLivetime";
const char QR_OLLAMA_CONTEXT_WINDOW[] = "QodeAssist.qrOllamaContextWindow";
const char QR_USE_TOOLS[] = "QodeAssist.qrUseTools";
const char QR_USE_THINKING[] = "QodeAssist.qrUseThinking";
const char QR_THINKING_BUDGET_TOKENS[] = "QodeAssist.qrThinkingBudgetTokens";
const char QR_THINKING_MAX_TOKENS[] = "QodeAssist.qrThinkingMaxTokens";
const char QR_READ_FULL_FILE[] = "QodeAssist.qrReadFullFile";
const char QR_READ_STRINGS_BEFORE_CURSOR[] = "QodeAssist.qrReadStringsBeforeCursor";
const char QR_READ_STRINGS_AFTER_CURSOR[] = "QodeAssist.qrReadStringsAfterCursor";
const char QR_SYSTEM_PROMPT[] = "QodeAssist.qrSystemPrompt";
} // namespace QodeAssist::Constants

View File

@ -48,6 +48,7 @@ inline const char *ENDPOINT_MODE = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Endpoin
inline const char *CODE_COMPLETION = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Code Completion");
inline const char *CHAT_ASSISTANT = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Chat Assistant");
inline const char *QUICK_REFACTOR = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Quick Refactor");
inline const char *RESET_SETTINGS = QT_TRANSLATE_NOOP("QtC::QodeAssist", "Reset Settings");
inline const char *CONFIRMATION = QT_TRANSLATE_NOOP(
"QtC::QodeAssist", "Are you sure you want to reset all settings to default values?");