forked from qt-creator/qt-creator
QmlDesigner: Move code to compile time
Instead of initialize code at run runtime we can do that already at compile time. And because Qt has already QStringView overloads we can use them. Change-Id: I2a6a2c45d6c5cd1af2c64e32deeb3d4ff81c9ee0 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -41,7 +41,8 @@ using namespace QmlDesigner::Internal;
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
const char annotationsEscapeSequence[] = "##^##";
|
constexpr QStringView annotationsStart{u"/*##^##"};
|
||||||
|
constexpr QStringView annotationsEnd{u"##^##*/"};
|
||||||
|
|
||||||
bool debugQmlPuppet(const DesignerSettings &settings)
|
bool debugQmlPuppet(const DesignerSettings &settings)
|
||||||
{
|
{
|
||||||
@@ -1103,29 +1104,17 @@ void RewriterView::delayedSetup()
|
|||||||
m_textToModelMerger->delayedSetup();
|
m_textToModelMerger->delayedSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString annotationsEnd()
|
|
||||||
{
|
|
||||||
const static QString end = QString("%1*/").arg(annotationsEscapeSequence);
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString annotationsStart()
|
|
||||||
{
|
|
||||||
const static QString start = QString("/*%1").arg(annotationsEscapeSequence);
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString RewriterView::getRawAuxiliaryData() const
|
QString RewriterView::getRawAuxiliaryData() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_textModifier, return {});
|
QTC_ASSERT(m_textModifier, return {});
|
||||||
|
|
||||||
const QString oldText = m_textModifier->text();
|
const QString oldText = m_textModifier->text();
|
||||||
|
|
||||||
int startIndex = oldText.indexOf(annotationsStart());
|
int startIndex = oldText.indexOf(annotationsStart);
|
||||||
int endIndex = oldText.indexOf(annotationsEnd());
|
int endIndex = oldText.indexOf(annotationsEnd);
|
||||||
|
|
||||||
if (startIndex > 0 && endIndex > 0)
|
if (startIndex > 0 && endIndex > 0)
|
||||||
return oldText.mid(startIndex, endIndex - startIndex + annotationsEnd().length());
|
return oldText.mid(startIndex, endIndex - startIndex + annotationsEnd.length());
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -1136,8 +1125,8 @@ void RewriterView::writeAuxiliaryData()
|
|||||||
|
|
||||||
const QString oldText = m_textModifier->text();
|
const QString oldText = m_textModifier->text();
|
||||||
|
|
||||||
const int startIndex = oldText.indexOf(annotationsStart());
|
const int startIndex = oldText.indexOf(annotationsStart);
|
||||||
const int endIndex = oldText.indexOf(annotationsEnd());
|
const int endIndex = oldText.indexOf(annotationsEnd);
|
||||||
|
|
||||||
QString auxData = auxiliaryDataAsQML();
|
QString auxData = auxiliaryDataAsQML();
|
||||||
|
|
||||||
@@ -1145,16 +1134,16 @@ void RewriterView::writeAuxiliaryData()
|
|||||||
|
|
||||||
if (!auxData.isEmpty()) {
|
if (!auxData.isEmpty()) {
|
||||||
auxData.prepend("\n");
|
auxData.prepend("\n");
|
||||||
auxData.prepend(annotationsStart());
|
auxData.prepend(annotationsStart);
|
||||||
if (!replace)
|
if (!replace)
|
||||||
auxData.prepend("\n");
|
auxData.prepend("\n");
|
||||||
auxData.append(annotationsEnd());
|
auxData.append(annotationsEnd);
|
||||||
if (!replace)
|
if (!replace)
|
||||||
auxData.append("\n");
|
auxData.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (replace)
|
if (replace)
|
||||||
m_textModifier->replace(startIndex, endIndex - startIndex + annotationsEnd().length(), auxData);
|
m_textModifier->replace(startIndex, endIndex - startIndex + annotationsEnd.length(), auxData);
|
||||||
else
|
else
|
||||||
m_textModifier->replace(oldText.length(), 0, auxData);
|
m_textModifier->replace(oldText.length(), 0, auxData);
|
||||||
}
|
}
|
||||||
@@ -1222,12 +1211,12 @@ void RewriterView::restoreAuxiliaryData()
|
|||||||
|
|
||||||
const QString text = m_textModifier->text();
|
const QString text = m_textModifier->text();
|
||||||
|
|
||||||
int startIndex = text.indexOf(annotationsStart());
|
int startIndex = text.indexOf(annotationsStart);
|
||||||
int endIndex = text.indexOf(annotationsEnd());
|
int endIndex = text.indexOf(annotationsEnd);
|
||||||
|
|
||||||
if (startIndex > 0 && endIndex > 0) {
|
if (startIndex > 0 && endIndex > 0) {
|
||||||
const QString auxSource = text.mid(startIndex + annotationsStart().length(),
|
const QString auxSource = text.mid(startIndex + annotationsStart.length(),
|
||||||
endIndex - startIndex - annotationsStart().length());
|
endIndex - startIndex - annotationsStart.length());
|
||||||
QmlJS::SimpleReader reader;
|
QmlJS::SimpleReader reader;
|
||||||
checkChildNodes(reader.readFromSource(auxSource), this);
|
checkChildNodes(reader.readFromSource(auxSource), this);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user