2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-07-07 11:45:18 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-07-07 11:45:18 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-07-07 11:45:18 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-07-07 11:45:18 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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
|
|
|
}
|