2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2010-07-07 11:45:18 +02:00
|
|
|
|
2010-11-11 10:05:05 +01:00
|
|
|
#include "qmljsqtstylecodeformatter.h"
|
2010-07-07 11:45:18 +02:00
|
|
|
|
2010-08-12 14:00:15 +02:00
|
|
|
#include <texteditor/tabsettings.h>
|
|
|
|
|
|
2010-07-07 11:45:18 +02:00
|
|
|
using namespace QmlJS;
|
2010-11-11 10:05:05 +01:00
|
|
|
using namespace QmlJSTools;
|
2010-07-07 11:45:18 +02:00
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
2018-11-24 10:22:37 +01:00
|
|
|
CreatorCodeFormatter::CreatorCodeFormatter() = default;
|
2010-07-07 11:45:18 +02:00
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
CreatorCodeFormatter::CreatorCodeFormatter(const TabSettings &tabSettings)
|
2010-08-12 14:00:15 +02:00
|
|
|
{
|
|
|
|
|
setTabSize(tabSettings.m_tabSize);
|
2011-10-17 13:56:48 +02:00
|
|
|
setIndentSize(tabSettings.m_indentSize);
|
2010-08-12 14:00:15 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-17 13:56:48 +02:00
|
|
|
void CreatorCodeFormatter::saveBlockData(QTextBlock *block, const BlockData &data) const
|
2010-07-07 11:45:18 +02:00
|
|
|
{
|
2014-09-26 09:14:03 +02:00
|
|
|
TextBlockUserData *userData = TextDocumentLayout::userData(*block);
|
2018-11-24 10:22:37 +01:00
|
|
|
auto cppData = static_cast<QmlJSCodeFormatterData *>(userData->codeFormatterData());
|
2010-07-07 11:45:18 +02:00
|
|
|
if (!cppData) {
|
|
|
|
|
cppData = new QmlJSCodeFormatterData;
|
|
|
|
|
userData->setCodeFormatterData(cppData);
|
|
|
|
|
}
|
|
|
|
|
cppData->m_data = data;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-17 13:56:48 +02:00
|
|
|
bool CreatorCodeFormatter::loadBlockData(const QTextBlock &block, BlockData *data) const
|
2010-07-07 11:45:18 +02:00
|
|
|
{
|
2019-12-04 08:19:53 +01:00
|
|
|
TextBlockUserData *userData = TextDocumentLayout::textUserData(block);
|
2010-07-07 11:45:18 +02:00
|
|
|
if (!userData)
|
|
|
|
|
return false;
|
2018-11-24 10:22:37 +01:00
|
|
|
auto cppData = static_cast<const QmlJSCodeFormatterData *>(userData->codeFormatterData());
|
2010-07-07 11:45:18 +02:00
|
|
|
if (!cppData)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
*data = cppData->m_data;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-17 13:56:48 +02:00
|
|
|
void CreatorCodeFormatter::saveLexerState(QTextBlock *block, int state) const
|
2010-07-07 11:45:18 +02:00
|
|
|
{
|
2014-09-26 09:14:03 +02:00
|
|
|
TextDocumentLayout::setLexerState(*block, state);
|
2010-07-07 11:45:18 +02:00
|
|
|
}
|
|
|
|
|
|
2011-10-17 13:56:48 +02:00
|
|
|
int CreatorCodeFormatter::loadLexerState(const QTextBlock &block) const
|
2010-07-07 11:45:18 +02:00
|
|
|
{
|
2014-09-26 09:14:03 +02:00
|
|
|
return TextDocumentLayout::lexerState(block);
|
2010-07-07 11:45:18 +02:00
|
|
|
}
|