QmlDesigner: Add code preview indentation

Task-number: QDS-10680
Change-Id: I61528f517ed4baef2115fbddf1b014b9f7f966d2
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Aleksei German
2023-09-15 16:17:37 +02:00
parent 516a2238e2
commit 4949c1911e
3 changed files with 22 additions and 4 deletions

View File

@@ -223,7 +223,7 @@ Column {
id: code
anchors.fill: parent
anchors.margins: 4
text: backend.source
text: backend.indentedSource
color: StudioTheme.Values.themeTextColor
font.pixelSize: StudioTheme.Values.myFontSize
wrapMode: Text.WordWrap

View File

@@ -11,18 +11,21 @@
#include <nodeabstractproperty.h>
#include <nodelistproperty.h>
#include <nodemetainfo.h>
#include <qmldesignerconstants.h>
#include <qmldesignerplugin.h>
#include <plaintexteditmodifier.h>
#include <rewritertransaction.h>
#include <rewriterview.h>
#include <signalhandlerproperty.h>
#include <variantproperty.h>
#include <qmldesignerconstants.h>
#include <qmldesignerplugin.h>
#include <utils/qtcassert.h>
#include <QStandardItemModel>
#include <QMessageBox>
#include <QStandardItemModel>
#include <QTableView>
#include <QTextCursor>
#include <QTextDocument>
#include <QTimer>
namespace {
@@ -911,6 +914,19 @@ ConditionListModel *ConnectionModelBackendDelegate::conditionListModel()
return &m_conditionListModel;
}
QString ConnectionModelBackendDelegate::indentedSource() const
{
if (m_source.isEmpty())
return {};
QTextDocument doc(m_source);
QTextCursor cursor(&doc);
IndentingTextEditModifier mod(&doc, cursor);
mod.indent(0, m_source.length() - 1);
return mod.text();
}
QString ConnectionModelBackendDelegate::source() const
{
return m_source;

View File

@@ -266,6 +266,7 @@ class ConnectionModelBackendDelegate : public QObject
Q_PROPERTY(bool hasCondition READ hasCondition NOTIFY hasConditionChanged)
Q_PROPERTY(bool hasElse READ hasElse NOTIFY hasElseChanged)
Q_PROPERTY(QString source READ source NOTIFY sourceChanged)
Q_PROPERTY(QString indentedSource READ indentedSource NOTIFY sourceChanged)
Q_PROPERTY(PropertyTreeModel *propertyTreeModel READ propertyTreeModel CONSTANT)
Q_PROPERTY(PropertyListProxyModel *propertyListProxyModel READ propertyListProxyModel CONSTANT)
@@ -308,6 +309,7 @@ private:
ConnectionModelStatementDelegate *okStatement();
ConnectionModelStatementDelegate *koStatement();
ConditionListModel *conditionListModel();
QString indentedSource() const;
QString source() const;
void setSource(const QString &source);