mirror of
https://github.com/fralx/LimeReport.git
synced 2025-11-25 00:18:06 +03:00
Define code style and format all source file using clang-format-14
except those placed in 3rdparty directories.
This commit is contained in:
@@ -1,45 +1,45 @@
|
||||
#include "lrcodeeditor.h"
|
||||
|
||||
#include <QAbstractItemView>
|
||||
#include <QWidget>
|
||||
#include <QCompleter>
|
||||
#include <QKeyEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QPainter>
|
||||
#include <QTextBlock>
|
||||
#include <QDebug>
|
||||
|
||||
#include "lrscripthighlighter.h"
|
||||
#include "lrglobal.h"
|
||||
#include "lrscripthighlighter.h"
|
||||
|
||||
namespace LimeReport{
|
||||
#include <QAbstractItemView>
|
||||
#include <QCompleter>
|
||||
#include <QDebug>
|
||||
#include <QKeyEvent>
|
||||
#include <QPainter>
|
||||
#include <QScrollBar>
|
||||
#include <QTextBlock>
|
||||
#include <QWidget>
|
||||
|
||||
CodeEditor::CodeEditor(QWidget *parent)
|
||||
: QPlainTextEdit(parent), m_completer(0)
|
||||
namespace LimeReport {
|
||||
|
||||
CodeEditor::CodeEditor(QWidget* parent): QPlainTextEdit(parent), m_completer(0)
|
||||
{
|
||||
lineNumberArea = new LineNumberArea(this);
|
||||
|
||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
|
||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
|
||||
connect(this, SIGNAL(updateRequest(QRect, int)), this, SLOT(updateLineNumberArea(QRect, int)));
|
||||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
|
||||
|
||||
updateLineNumberAreaWidth(0);
|
||||
highlightCurrentLine();
|
||||
new ScriptHighlighter(document());
|
||||
connect(this, SIGNAL(cursorPositionChanged()),
|
||||
this, SLOT(matchParentheses()));
|
||||
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(matchParentheses()));
|
||||
}
|
||||
|
||||
void CodeEditor::setCompleter(QCompleter *value)
|
||||
void CodeEditor::setCompleter(QCompleter* value)
|
||||
{
|
||||
if (value) disconnect(value,0,this,0);
|
||||
if (value)
|
||||
disconnect(value, 0, this, 0);
|
||||
m_completer = value;
|
||||
if (!m_completer) return;
|
||||
if (!m_completer)
|
||||
return;
|
||||
m_completer->setWidget(this);
|
||||
m_completer->setCompletionMode(QCompleter::PopupCompletion);
|
||||
m_completer->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
|
||||
connect(m_completer,SIGNAL(activated(QString)),this,SLOT(insertCompletion(QString)));
|
||||
connect(m_completer, SIGNAL(activated(QString)), this, SLOT(insertCompletion(QString)));
|
||||
}
|
||||
|
||||
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event)
|
||||
@@ -47,14 +47,14 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event)
|
||||
QPainter painter(lineNumberArea);
|
||||
QStyleOption option;
|
||||
option.initFrom(this);
|
||||
//painter.fillRect(event->rect(), QPalette().window().color());
|
||||
// painter.fillRect(event->rect(), QPalette().window().color());
|
||||
QColor bg = option.palette.window().color().darker(150);
|
||||
painter.fillRect(event->rect(), bg);
|
||||
|
||||
QTextBlock block = firstVisibleBlock();
|
||||
int blockNumber = block.blockNumber();
|
||||
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
|
||||
int bottom = top + (int) blockBoundingRect(block).height();
|
||||
int top = (int)blockBoundingGeometry(block).translated(contentOffset()).top();
|
||||
int bottom = top + (int)blockBoundingRect(block).height();
|
||||
|
||||
while (block.isValid() && top <= event->rect().bottom()) {
|
||||
if (block.isVisible() && bottom >= event->rect().top()) {
|
||||
@@ -66,7 +66,7 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event)
|
||||
|
||||
block = block.next();
|
||||
top = bottom;
|
||||
bottom = top + (int) blockBoundingRect(block).height();
|
||||
bottom = top + (int)blockBoundingRect(block).height();
|
||||
++blockNumber;
|
||||
}
|
||||
}
|
||||
@@ -80,12 +80,13 @@ int CodeEditor::lineNumberAreaWidth()
|
||||
++digits;
|
||||
}
|
||||
|
||||
int space = fontMetrics().boundingRect(QLatin1Char('9')).width()*2 + fontMetrics().boundingRect(QLatin1Char('9')).width() * digits;
|
||||
int space = fontMetrics().boundingRect(QLatin1Char('9')).width() * 2
|
||||
+ fontMetrics().boundingRect(QLatin1Char('9')).width() * digits;
|
||||
|
||||
return space;
|
||||
}
|
||||
|
||||
void CodeEditor::keyPressEvent(QKeyEvent *e)
|
||||
void CodeEditor::keyPressEvent(QKeyEvent* e)
|
||||
{
|
||||
if (m_completer && m_completer->popup()->isVisible()) {
|
||||
switch (e->key()) {
|
||||
@@ -106,7 +107,8 @@ void CodeEditor::keyPressEvent(QKeyEvent *e)
|
||||
}
|
||||
|
||||
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_Space);
|
||||
if (!m_completer || !isShortcut) QPlainTextEdit::keyPressEvent(e);
|
||||
if (!m_completer || !isShortcut)
|
||||
QPlainTextEdit::keyPressEvent(e);
|
||||
|
||||
const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
|
||||
if (!m_completer || (ctrlOrShift && e->text().isEmpty()))
|
||||
@@ -116,10 +118,9 @@ void CodeEditor::keyPressEvent(QKeyEvent *e)
|
||||
|
||||
QString completionPrefix = textUnderCursor();
|
||||
|
||||
if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3
|
||||
|| Const::EOW.contains(e->text().right(1)))
|
||||
)
|
||||
{
|
||||
if (!isShortcut
|
||||
&& (hasModifier || e->text().isEmpty() || completionPrefix.length() < 3
|
||||
|| Const::EOW.contains(e->text().right(1)))) {
|
||||
m_completer->popup()->hide();
|
||||
return;
|
||||
}
|
||||
@@ -129,8 +130,9 @@ void CodeEditor::keyPressEvent(QKeyEvent *e)
|
||||
m_completer->popup()->setCurrentIndex(m_completer->completionModel()->index(0, 0));
|
||||
}
|
||||
|
||||
QModelIndex ci = m_completer->completionModel()->index(0,0);
|
||||
if (ci.isValid() && m_completer->completionModel()->data(ci).toString().compare(completionPrefix) == 0){
|
||||
QModelIndex ci = m_completer->completionModel()->index(0, 0);
|
||||
if (ci.isValid()
|
||||
&& m_completer->completionModel()->data(ci).toString().compare(completionPrefix) == 0) {
|
||||
m_completer->popup()->hide();
|
||||
return;
|
||||
}
|
||||
@@ -140,16 +142,15 @@ void CodeEditor::keyPressEvent(QKeyEvent *e)
|
||||
+ m_completer->popup()->verticalScrollBar()->sizeHint().width());
|
||||
m_completer->complete(cr);
|
||||
|
||||
if (!completionPrefix.isEmpty() &&
|
||||
completionPrefix.at(completionPrefix.length()-1) == '.')
|
||||
{
|
||||
if (!completionPrefix.isEmpty() && completionPrefix.at(completionPrefix.length() - 1) == '.') {
|
||||
m_completer->popup();
|
||||
}
|
||||
}
|
||||
|
||||
void CodeEditor::focusInEvent(QFocusEvent *e)
|
||||
void CodeEditor::focusInEvent(QFocusEvent* e)
|
||||
{
|
||||
if (m_completer) m_completer->setWidget(this);
|
||||
if (m_completer)
|
||||
m_completer->setWidget(this);
|
||||
QPlainTextEdit::focusInEvent(e);
|
||||
}
|
||||
|
||||
@@ -164,39 +165,40 @@ QString CodeEditor::textUnderCursor() const
|
||||
{
|
||||
QTextCursor tc = textCursor();
|
||||
QString currentText;
|
||||
tc.movePosition(QTextCursor::StartOfBlock,QTextCursor::KeepAnchor);
|
||||
tc.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor);
|
||||
QString blockText = tc.selectedText();
|
||||
for(int i = blockText.length(); i>0; --i){
|
||||
if (!Const::EOW.contains(blockText.at(i-1)))
|
||||
currentText = blockText.at(i-1) + currentText;
|
||||
else break;
|
||||
for (int i = blockText.length(); i > 0; --i) {
|
||||
if (!Const::EOW.contains(blockText.at(i - 1)))
|
||||
currentText = blockText.at(i - 1) + currentText;
|
||||
else
|
||||
break;
|
||||
}
|
||||
return currentText.trimmed();
|
||||
}
|
||||
|
||||
bool CodeEditor::matchLeftParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i, int numLeftParentheses)
|
||||
bool CodeEditor::matchLeftParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i,
|
||||
int numLeftParentheses)
|
||||
{
|
||||
TextBlockData *data = static_cast<TextBlockData *>(currentBlock.userData());
|
||||
if (data){
|
||||
QVector<ParenthesisInfo *> infos = data->parentheses();
|
||||
TextBlockData* data = static_cast<TextBlockData*>(currentBlock.userData());
|
||||
if (data) {
|
||||
QVector<ParenthesisInfo*> infos = data->parentheses();
|
||||
|
||||
int docPos = currentBlock.position();
|
||||
for (; i < infos.size(); ++i) {
|
||||
ParenthesisInfo *info = infos.at(i);
|
||||
ParenthesisInfo* info = infos.at(i);
|
||||
|
||||
if (info->character == parenthesisType) {
|
||||
++numLeftParentheses;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (info->character == getParenthesisReverceChar(parenthesisType)){
|
||||
if (info->character == getParenthesisReverceChar(parenthesisType)) {
|
||||
if (numLeftParentheses == 0) {
|
||||
createParenthesisSelection(docPos + info->position);
|
||||
return true;
|
||||
} else
|
||||
--numLeftParentheses;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,20 +209,22 @@ bool CodeEditor::matchLeftParenthesis(QTextBlock currentBlock, QChar parenthesis
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CodeEditor::matchRightParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i, int numRightParentheses)
|
||||
bool CodeEditor::matchRightParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i,
|
||||
int numRightParentheses)
|
||||
{
|
||||
TextBlockData *data = static_cast<TextBlockData *>(currentBlock.userData());
|
||||
if (data){
|
||||
QVector<ParenthesisInfo *> parentheses = data->parentheses();
|
||||
TextBlockData* data = static_cast<TextBlockData*>(currentBlock.userData());
|
||||
if (data) {
|
||||
QVector<ParenthesisInfo*> parentheses = data->parentheses();
|
||||
int docPos = currentBlock.position();
|
||||
if (i == -2) i = parentheses.size()-1;
|
||||
if (i == -2)
|
||||
i = parentheses.size() - 1;
|
||||
for (; i > -1 && parentheses.size() > 0; --i) {
|
||||
ParenthesisInfo *info = parentheses.at(i);
|
||||
ParenthesisInfo* info = parentheses.at(i);
|
||||
if (info->character == parenthesisType) {
|
||||
++numRightParentheses;
|
||||
continue;
|
||||
}
|
||||
if (info->character == getParenthesisReverceChar(parenthesisType)){
|
||||
if (info->character == getParenthesisReverceChar(parenthesisType)) {
|
||||
if (numRightParentheses == 0) {
|
||||
createParenthesisSelection(docPos + info->position);
|
||||
return true;
|
||||
@@ -259,7 +263,7 @@ void CodeEditor::createParenthesisSelection(int pos)
|
||||
|
||||
bool CodeEditor::charIsParenthesis(QChar character, ParenthesisType type)
|
||||
{
|
||||
for (int i = 0; i < PARENHEIS_COUNT; ++i){
|
||||
for (int i = 0; i < PARENHEIS_COUNT; ++i) {
|
||||
if (character == parenthesisCharacters[type][i])
|
||||
return true;
|
||||
}
|
||||
@@ -268,27 +272,27 @@ bool CodeEditor::charIsParenthesis(QChar character, ParenthesisType type)
|
||||
|
||||
QChar CodeEditor::getParenthesisReverceChar(QChar parenthesisChar)
|
||||
{
|
||||
for (int i = 0; i < PARENHEIS_COUNT; ++i){
|
||||
if ( parenthesisCharacters[RightParenthesis][i] == parenthesisChar)
|
||||
for (int i = 0; i < PARENHEIS_COUNT; ++i) {
|
||||
if (parenthesisCharacters[RightParenthesis][i] == parenthesisChar)
|
||||
return parenthesisCharacters[LeftParenthesis][i];
|
||||
if ( parenthesisCharacters[LeftParenthesis][i] == parenthesisChar)
|
||||
if (parenthesisCharacters[LeftParenthesis][i] == parenthesisChar)
|
||||
return parenthesisCharacters[RightParenthesis][i];
|
||||
}
|
||||
return ' ';
|
||||
}
|
||||
|
||||
void CodeEditor::insertCompletion(const QString &completion)
|
||||
void CodeEditor::insertCompletion(const QString& completion)
|
||||
{
|
||||
if (m_completer->widget() != this)
|
||||
return;
|
||||
return;
|
||||
QTextCursor tc = textCursor();
|
||||
// QString prefix = m_completer->completionPrefix();
|
||||
// int extra = completion.length() - prefix.length();
|
||||
for (int i=0; i < m_completer->completionPrefix().length(); ++i ) {
|
||||
// QString prefix = m_completer->completionPrefix();
|
||||
// int extra = completion.length() - prefix.length();
|
||||
for (int i = 0; i < m_completer->completionPrefix().length(); ++i) {
|
||||
tc.deletePreviousChar();
|
||||
}
|
||||
tc.insertText(completion);
|
||||
// tc.insertText(completion.right(extra));
|
||||
// tc.insertText(completion.right(extra));
|
||||
setTextCursor(tc);
|
||||
}
|
||||
|
||||
@@ -332,27 +336,28 @@ void CodeEditor::matchParentheses()
|
||||
QList<QTextEdit::ExtraSelection> selections;
|
||||
setExtraSelections(selections);
|
||||
|
||||
TextBlockData *data = static_cast<TextBlockData *>(textCursor().block().userData());
|
||||
TextBlockData* data = static_cast<TextBlockData*>(textCursor().block().userData());
|
||||
|
||||
if (data) {
|
||||
QVector<ParenthesisInfo *> infos = data->parentheses();
|
||||
QVector<ParenthesisInfo*> infos = data->parentheses();
|
||||
|
||||
int pos = textCursor().block().position();
|
||||
for (int i = 0; i < infos.size(); ++i) {
|
||||
ParenthesisInfo *info = infos.at(i);
|
||||
ParenthesisInfo* info = infos.at(i);
|
||||
|
||||
int curPos = textCursor().position() - textCursor().block().position();
|
||||
|
||||
if ( (info->position == (curPos - 1)) && charIsParenthesis(info->character, LeftParenthesis))
|
||||
{
|
||||
if ((info->position == (curPos - 1))
|
||||
&& charIsParenthesis(info->character, LeftParenthesis)) {
|
||||
if (matchLeftParenthesis(textCursor().block(), info->character, i + 1, 0))
|
||||
createParenthesisSelection(pos + info->position);
|
||||
} else if ( (info->position == (curPos - 1)) && charIsParenthesis(info->character, RightParenthesis)) {
|
||||
} else if ((info->position == (curPos - 1))
|
||||
&& charIsParenthesis(info->character, RightParenthesis)) {
|
||||
if (matchRightParenthesis(textCursor().block(), info->character, i - 1, 0))
|
||||
createParenthesisSelection(pos + info->position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace LimeReport
|
||||
} // namespace LimeReport
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#ifndef LRCODEEDITOR_H
|
||||
#define LRCODEEDITOR_H
|
||||
|
||||
#include "lrscripthighlighter.h"
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include "lrscripthighlighter.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QWidget;
|
||||
@@ -12,58 +13,54 @@ class QKeyEvent;
|
||||
class QScrollBar;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
class CodeEditor :public QPlainTextEdit
|
||||
{
|
||||
class CodeEditor: public QPlainTextEdit {
|
||||
Q_OBJECT
|
||||
public:
|
||||
CodeEditor(QWidget* parent=0);
|
||||
CodeEditor(QWidget* parent = 0);
|
||||
void setCompleter(QCompleter* value);
|
||||
QCompleter* compleater() const{ return m_completer;}
|
||||
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
||||
QCompleter* compleater() const { return m_completer; }
|
||||
void lineNumberAreaPaintEvent(QPaintEvent* event);
|
||||
int lineNumberAreaWidth();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
void focusInEvent(QFocusEvent *e);
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void keyPressEvent(QKeyEvent* e);
|
||||
void focusInEvent(QFocusEvent* e);
|
||||
void resizeEvent(QResizeEvent* event);
|
||||
|
||||
private:
|
||||
QString textUnderCursor() const;
|
||||
bool matchLeftParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i, int numLeftParentheses);
|
||||
bool matchRightParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i, int numRightParentheses);
|
||||
void createParenthesisSelection(int pos);
|
||||
bool charIsParenthesis(QChar character, ParenthesisType type);
|
||||
QChar getParenthesisReverceChar(QChar parenthesisChar);
|
||||
bool matchLeftParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i,
|
||||
int numLeftParentheses);
|
||||
bool matchRightParenthesis(QTextBlock currentBlock, QChar parenthesisType, int i,
|
||||
int numRightParentheses);
|
||||
void createParenthesisSelection(int pos);
|
||||
bool charIsParenthesis(QChar character, ParenthesisType type);
|
||||
QChar getParenthesisReverceChar(QChar parenthesisChar);
|
||||
private slots:
|
||||
void insertCompletion(const QString& completion);
|
||||
void updateLineNumberAreaWidth(int newBlockCount);
|
||||
void highlightCurrentLine();
|
||||
void updateLineNumberArea(const QRect &rect, int dy);
|
||||
void updateLineNumberArea(const QRect& rect, int dy);
|
||||
void matchParentheses();
|
||||
|
||||
private:
|
||||
QCompleter* m_completer;
|
||||
QWidget *lineNumberArea;
|
||||
QWidget* lineNumberArea;
|
||||
};
|
||||
|
||||
|
||||
class LineNumberArea : public QWidget
|
||||
{
|
||||
class LineNumberArea: public QWidget {
|
||||
public:
|
||||
LineNumberArea(CodeEditor *editor) : QWidget(editor) {
|
||||
codeEditor = editor;
|
||||
}
|
||||
LineNumberArea(CodeEditor* editor): QWidget(editor) { codeEditor = editor; }
|
||||
|
||||
QSize sizeHint() const {
|
||||
return QSize(codeEditor->lineNumberAreaWidth(), 0);
|
||||
}
|
||||
QSize sizeHint() const { return QSize(codeEditor->lineNumberAreaWidth(), 0); }
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) {
|
||||
codeEditor->lineNumberAreaPaintEvent(event);
|
||||
}
|
||||
void paintEvent(QPaintEvent* event) { codeEditor->lineNumberAreaPaintEvent(event); }
|
||||
|
||||
private:
|
||||
CodeEditor *codeEditor;
|
||||
CodeEditor* codeEditor;
|
||||
};
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
@@ -1,74 +1,78 @@
|
||||
#include "lrcompletermodel.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
CompleterModel::CompleterModel(QObject *parent) : QAbstractItemModel(parent){m_root.setModel(this);}
|
||||
|
||||
QModelIndex CompleterModel::index(int row, int column, const QModelIndex &parent) const
|
||||
CompleterModel::CompleterModel(QObject* parent): QAbstractItemModel(parent)
|
||||
{
|
||||
CompleterItem const *parentItem;
|
||||
m_root.setModel(this);
|
||||
}
|
||||
|
||||
QModelIndex CompleterModel::index(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
CompleterItem const* parentItem;
|
||||
if (!parent.isValid())
|
||||
parentItem = &m_root;
|
||||
else
|
||||
parentItem = static_cast<CompleterItem*>(parent.internalPointer());
|
||||
|
||||
if ((parentItem == nullptr)
|
||||
|| (row < 0)
|
||||
|| (column < 0)
|
||||
|| (row >= parentItem->rowCount())
|
||||
|| (column >= 1))
|
||||
{
|
||||
if ((parentItem == nullptr) || (row < 0) || (column < 0) || (row >= parentItem->rowCount())
|
||||
|| (column >= 1)) {
|
||||
return QModelIndex();
|
||||
}
|
||||
return createIndex(row, column, parentItem->child(row));
|
||||
}
|
||||
|
||||
QModelIndex CompleterModel::parent(const QModelIndex &child) const {
|
||||
if(child.isValid()) {
|
||||
if(CompleterItem *childItem = static_cast<CompleterItem *>(child.internalPointer());
|
||||
childItem) {
|
||||
CompleterItem *parentItem = childItem->parent();
|
||||
if(parentItem != &m_root) {
|
||||
return indexFromItem(parentItem);
|
||||
}
|
||||
QModelIndex CompleterModel::parent(const QModelIndex& child) const
|
||||
{
|
||||
if (child.isValid()) {
|
||||
if (CompleterItem* childItem = static_cast<CompleterItem*>(child.internalPointer());
|
||||
childItem) {
|
||||
CompleterItem* parentItem = childItem->parent();
|
||||
if (parentItem != &m_root) {
|
||||
return indexFromItem(parentItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return QModelIndex();
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
int CompleterModel::rowCount(const QModelIndex &parent) const
|
||||
int CompleterModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
if (parent.isValid()){
|
||||
CompleterItem *parentItem = static_cast<CompleterItem*>(parent.internalPointer());
|
||||
if (parent.isValid()) {
|
||||
CompleterItem* parentItem = static_cast<CompleterItem*>(parent.internalPointer());
|
||||
return parentItem->rowCount();
|
||||
}
|
||||
return m_root.rowCount();
|
||||
}
|
||||
|
||||
int CompleterModel::columnCount(const QModelIndex &parent) const
|
||||
int CompleterModel::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return 1;
|
||||
}
|
||||
|
||||
QVariant CompleterModel::data(const QModelIndex &index, int role) const
|
||||
QVariant CompleterModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (index.isValid()){
|
||||
if (index.isValid()) {
|
||||
CompleterItem* item = static_cast<CompleterItem*>(index.internalPointer());
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case Qt::EditRole:
|
||||
if (!item) return QVariant();
|
||||
if (!item)
|
||||
return QVariant();
|
||||
|
||||
if (index.column()==0){
|
||||
if (index.column() == 0) {
|
||||
return item->text();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
case Qt::DecorationRole :
|
||||
if (!item) return QIcon();
|
||||
if (index.column()==0){
|
||||
case Qt::DecorationRole:
|
||||
if (!item)
|
||||
return QIcon();
|
||||
if (index.column() == 0) {
|
||||
return item->icon();
|
||||
} else return QIcon();
|
||||
} else
|
||||
return QIcon();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
@@ -76,10 +80,11 @@ QVariant CompleterModel::data(const QModelIndex &index, int role) const
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QList<CompleterItem *> CompleterModel::findItems(const QString &text, Qt::MatchFlags flags, int column) const
|
||||
QList<CompleterItem*> CompleterModel::findItems(const QString& text, Qt::MatchFlags flags,
|
||||
int column) const
|
||||
{
|
||||
QModelIndexList indexes = match(index(0, column, QModelIndex()),
|
||||
Qt::DisplayRole, text, -1, flags);
|
||||
QModelIndexList indexes
|
||||
= match(index(0, column, QModelIndex()), Qt::DisplayRole, text, -1, flags);
|
||||
QList<CompleterItem*> items;
|
||||
const int numIndexes = indexes.size();
|
||||
items.reserve(numIndexes);
|
||||
@@ -95,49 +100,45 @@ void CompleterModel::clear()
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
CompleterItem *CompleterModel::itemFromIndex(const QModelIndex index) const
|
||||
CompleterItem* CompleterModel::itemFromIndex(const QModelIndex index) const
|
||||
{
|
||||
if ((index.row() < 0) || (index.column() < 0) || (index.model() != this))
|
||||
return nullptr;
|
||||
CompleterItem *parent = static_cast<CompleterItem*>(index.internalPointer());
|
||||
return nullptr;
|
||||
CompleterItem* parent = static_cast<CompleterItem*>(index.internalPointer());
|
||||
if (parent == nullptr)
|
||||
return nullptr;
|
||||
CompleterItem *item = parent->child(index.row());
|
||||
return nullptr;
|
||||
CompleterItem* item = parent->child(index.row());
|
||||
return item;
|
||||
}
|
||||
|
||||
QModelIndex CompleterModel::indexFromItem(CompleterItem *item) const
|
||||
QModelIndex CompleterModel::indexFromItem(CompleterItem* item) const
|
||||
{
|
||||
if (item && item->parent()){
|
||||
if (item && item->parent()) {
|
||||
return createIndex(item->row(), 0, item);
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
CompleterItem::~CompleterItem(){}
|
||||
CompleterItem::~CompleterItem() { }
|
||||
|
||||
void CompleterItem::setIcon(const QIcon &newIcon)
|
||||
void CompleterItem::setIcon(const QIcon& newIcon) { m_icon = newIcon; }
|
||||
|
||||
void CompleterItem::setText(const QString& newText) { m_text = newText; }
|
||||
|
||||
void CompleterItem::appendRow(CompleterItem* child)
|
||||
{
|
||||
m_icon = newIcon;
|
||||
}
|
||||
|
||||
void CompleterItem::setText(const QString &newText)
|
||||
{
|
||||
m_text = newText;
|
||||
}
|
||||
|
||||
void CompleterItem::appendRow(CompleterItem *child){
|
||||
child->m_parent = this;
|
||||
child->m_model = this->m_model;
|
||||
m_children.append(QSharedPointer<CompleterItem>(child));
|
||||
if (m_model){
|
||||
if (m_model) {
|
||||
QModelIndex start = m_model->indexFromItem(child);
|
||||
emit m_model->dataChanged(start, start);
|
||||
}
|
||||
}
|
||||
|
||||
void CompleterItem::appendRows(const QList<CompleterItem*> &children){
|
||||
foreach(CompleterItem* item, children){
|
||||
void CompleterItem::appendRows(const QList<CompleterItem*>& children)
|
||||
{
|
||||
foreach (CompleterItem* item, children) {
|
||||
appendRow(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,66 +8,70 @@ class CompleterModel;
|
||||
|
||||
class CompleterItem {
|
||||
public:
|
||||
CompleterItem():m_parent(0), m_model(0){}
|
||||
CompleterItem(QString text, QIcon icon):m_parent(0), m_text(text), m_icon(icon), m_model(0){}
|
||||
CompleterItem(): m_parent(0), m_model(0) { }
|
||||
CompleterItem(QString text, QIcon icon): m_parent(0), m_text(text), m_icon(icon), m_model(0) { }
|
||||
~CompleterItem();
|
||||
int rowCount() const {return m_children.count();}
|
||||
CompleterItem *child(int row) const {
|
||||
return m_children.count() > row ? m_children.at(row).data() : nullptr;
|
||||
int rowCount() const { return m_children.count(); }
|
||||
CompleterItem* child(int row) const
|
||||
{
|
||||
return m_children.count() > row ? m_children.at(row).data() : nullptr;
|
||||
}
|
||||
CompleterItem* parent() const {return m_parent;}
|
||||
int row() const{
|
||||
if (m_parent){
|
||||
for(int i=0; i < m_parent->m_children.count(); ++i){
|
||||
CompleterItem* parent() const { return m_parent; }
|
||||
int row() const
|
||||
{
|
||||
if (m_parent) {
|
||||
for (int i = 0; i < m_parent->m_children.count(); ++i) {
|
||||
CompleterItem* c = m_parent->m_children.at(i).data();
|
||||
if (c == this) return i;
|
||||
if (c == this)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
QString text(){return m_text;}
|
||||
QIcon icon() {return m_icon;}
|
||||
QString text() { return m_text; }
|
||||
QIcon icon() { return m_icon; }
|
||||
|
||||
void setIcon(const QIcon &newIcon);
|
||||
void setText(const QString &newText);
|
||||
void setModel(CompleterModel* model){m_model=model;}
|
||||
void clear(){m_children.clear();}
|
||||
void setIcon(const QIcon& newIcon);
|
||||
void setText(const QString& newText);
|
||||
void setModel(CompleterModel* model) { m_model = model; }
|
||||
void clear() { m_children.clear(); }
|
||||
void appendRow(CompleterItem* child);
|
||||
void appendRows(const QList<CompleterItem *> &children);
|
||||
void appendRows(const QList<CompleterItem*>& children);
|
||||
|
||||
private:
|
||||
CompleterItem* m_parent{nullptr};
|
||||
QVector<QSharedPointer<CompleterItem> > m_children;
|
||||
CompleterItem* m_parent { nullptr };
|
||||
QVector<QSharedPointer<CompleterItem>> m_children;
|
||||
QString m_text;
|
||||
QIcon m_icon;
|
||||
CompleterModel* m_model;
|
||||
};
|
||||
|
||||
|
||||
class CompleterModel : public QAbstractItemModel
|
||||
{
|
||||
class CompleterModel: public QAbstractItemModel {
|
||||
friend CompleterItem;
|
||||
|
||||
public:
|
||||
explicit CompleterModel(QObject *parent = nullptr);
|
||||
explicit CompleterModel(QObject* parent = nullptr);
|
||||
|
||||
// QAbstractItemModel interface
|
||||
public:
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent) const;
|
||||
QModelIndex parent(const QModelIndex &child) const;
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
int columnCount(const QModelIndex &parent) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
CompleterItem* invisibleRootItem(){return &m_root;}
|
||||
QList<CompleterItem*> findItems(const QString &text,
|
||||
Qt::MatchFlags flags = Qt::MatchExactly,
|
||||
QModelIndex index(int row, int column, const QModelIndex& parent) const;
|
||||
QModelIndex parent(const QModelIndex& child) const;
|
||||
int rowCount(const QModelIndex& parent) const;
|
||||
int columnCount(const QModelIndex& parent) const;
|
||||
QVariant data(const QModelIndex& index, int role) const;
|
||||
CompleterItem* invisibleRootItem() { return &m_root; }
|
||||
QList<CompleterItem*> findItems(const QString& text, Qt::MatchFlags flags = Qt::MatchExactly,
|
||||
int column = 0) const;
|
||||
void clear();
|
||||
|
||||
private:
|
||||
CompleterItem *itemFromIndex(const QModelIndex index) const;
|
||||
QModelIndex indexFromItem(CompleterItem *item) const;
|
||||
CompleterItem* itemFromIndex(const QModelIndex index) const;
|
||||
QModelIndex indexFromItem(CompleterItem* item) const;
|
||||
|
||||
private:
|
||||
CompleterItem m_root;
|
||||
public:
|
||||
|
||||
public:
|
||||
};
|
||||
|
||||
#endif // COMPLETERMODEL_H
|
||||
|
||||
@@ -5,34 +5,36 @@
|
||||
#include <QJSValueIterator>
|
||||
#endif
|
||||
|
||||
#include "lrdatasourcemanager.h"
|
||||
#include "lrscriptenginemanager.h"
|
||||
#include "lrdatadesignintf.h"
|
||||
#include "lrdatasourcemanager.h"
|
||||
#include "lrreportengine_p.h"
|
||||
#include "lrscriptenginemanager.h"
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
ScriptEditor::ScriptEditor(QWidget *parent) :
|
||||
ScriptEditor::ScriptEditor(QWidget* parent):
|
||||
QWidget(parent),
|
||||
ui(new Ui::ScriptEditor), m_reportEngine(0), m_page(0), m_tabIndention(4)
|
||||
ui(new Ui::ScriptEditor),
|
||||
m_reportEngine(0),
|
||||
m_page(0),
|
||||
m_tabIndention(4)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setFocusProxy(ui->textEdit);
|
||||
m_completer = new ReportStructureCompleater(this);
|
||||
ui->textEdit->setCompleter(m_completer);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,12,3)
|
||||
ui->textEdit->setTabStopWidth(ui->textEdit->fontMetrics().boundingRect("0").width()*m_tabIndention);
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 3)
|
||||
ui->textEdit->setTabStopWidth(ui->textEdit->fontMetrics().boundingRect("0").width()
|
||||
* m_tabIndention);
|
||||
#else
|
||||
ui->textEdit->setTabStopDistance(ui->textEdit->fontMetrics().boundingRect("0").width()*m_tabIndention);
|
||||
ui->textEdit->setTabStopDistance(ui->textEdit->fontMetrics().boundingRect("0").width()
|
||||
* m_tabIndention);
|
||||
#endif
|
||||
connect(ui->splitter, SIGNAL(splitterMoved(int,int)), this, SIGNAL(splitterMoved(int,int)));
|
||||
connect(ui->splitter, SIGNAL(splitterMoved(int, int)), this, SIGNAL(splitterMoved(int, int)));
|
||||
connect(ui->textEdit, SIGNAL(textChanged()), this, SIGNAL(textChanged()));
|
||||
}
|
||||
|
||||
ScriptEditor::~ScriptEditor()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
ScriptEditor::~ScriptEditor() { delete ui; }
|
||||
|
||||
void ScriptEditor::initEditor(DataSourceManager* dm)
|
||||
{
|
||||
@@ -41,16 +43,17 @@ void ScriptEditor::initEditor(DataSourceManager* dm)
|
||||
|
||||
initCompleter();
|
||||
|
||||
if (dm){
|
||||
if (dm) {
|
||||
if (dm->isNeedUpdateDatasourceModel())
|
||||
dm->updateDatasourceModel();
|
||||
dm->updateDatasourceModel();
|
||||
ui->twData->setModel(dm->datasourcesModel());
|
||||
ui->twScriptEngine->setModel(se.model());
|
||||
}
|
||||
|
||||
if (ui->twScriptEngine->selectionModel()){
|
||||
connect(ui->twScriptEngine->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||
this, SLOT(slotOnCurrentChanged(QModelIndex,QModelIndex)));
|
||||
if (ui->twScriptEngine->selectionModel()) {
|
||||
connect(ui->twScriptEngine->selectionModel(),
|
||||
SIGNAL(currentChanged(QModelIndex, QModelIndex)), this,
|
||||
SLOT(slotOnCurrentChanged(QModelIndex, QModelIndex)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,29 +61,29 @@ void ScriptEditor::setReportEngine(ReportEnginePrivateInterface* reportEngine)
|
||||
{
|
||||
m_reportEngine = reportEngine;
|
||||
DataSourceManager* dm = m_reportEngine->dataManager();
|
||||
if (dm) initEditor(dm);
|
||||
else ui->tabWidget->setVisible(false);
|
||||
if (dm)
|
||||
initEditor(dm);
|
||||
else
|
||||
ui->tabWidget->setVisible(false);
|
||||
}
|
||||
|
||||
void ScriptEditor::setReportPage(PageDesignIntf* page)
|
||||
{
|
||||
m_page = page;
|
||||
DataSourceManager* dm = page->datasourceManager();
|
||||
if (dm) initEditor(dm);
|
||||
else ui->tabWidget->setVisible(false);
|
||||
if (dm)
|
||||
initEditor(dm);
|
||||
else
|
||||
ui->tabWidget->setVisible(false);
|
||||
}
|
||||
|
||||
void ScriptEditor::setPageBand(BandDesignIntf* band)
|
||||
{
|
||||
if (band && ui->twData->model() && !band->datasourceName().isEmpty()){
|
||||
QModelIndexList nodes = ui->twData->model()->match(
|
||||
ui->twData->model()->index(0,0),
|
||||
Qt::DisplayRole,
|
||||
band->datasourceName(),
|
||||
2,
|
||||
Qt::MatchRecursive
|
||||
);
|
||||
if (!nodes.isEmpty()){
|
||||
if (band && ui->twData->model() && !band->datasourceName().isEmpty()) {
|
||||
QModelIndexList nodes
|
||||
= ui->twData->model()->match(ui->twData->model()->index(0, 0), Qt::DisplayRole,
|
||||
band->datasourceName(), 2, Qt::MatchRecursive);
|
||||
if (!nodes.isEmpty()) {
|
||||
ui->twData->expand(nodes.at(0).parent());
|
||||
ui->twData->expand(nodes.at(0));
|
||||
}
|
||||
@@ -89,11 +92,13 @@ void ScriptEditor::setPageBand(BandDesignIntf* band)
|
||||
|
||||
void ScriptEditor::setTabIndention(int charCount)
|
||||
{
|
||||
if (m_tabIndention != charCount){
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,12,3)
|
||||
ui->textEdit->setTabStopWidth(ui->textEdit->fontMetrics().boundingRect("W").width()*charCount);
|
||||
if (m_tabIndention != charCount) {
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 3)
|
||||
ui->textEdit->setTabStopWidth(ui->textEdit->fontMetrics().boundingRect("W").width()
|
||||
* charCount);
|
||||
#else
|
||||
ui->textEdit->setTabStopDistance(ui->textEdit->fontMetrics().boundingRect("W").width()*charCount);
|
||||
ui->textEdit->setTabStopDistance(ui->textEdit->fontMetrics().boundingRect("W").width()
|
||||
* charCount);
|
||||
#endif
|
||||
m_tabIndention = charCount;
|
||||
}
|
||||
@@ -107,68 +112,55 @@ void ScriptEditor::initCompleter()
|
||||
m_completer->updateCompleaterModel(m_page->datasourceManager());
|
||||
}
|
||||
|
||||
QByteArray ScriptEditor::saveState()
|
||||
{
|
||||
return ui->splitter->saveState();
|
||||
}
|
||||
QByteArray ScriptEditor::saveState() { return ui->splitter->saveState(); }
|
||||
|
||||
void ScriptEditor::restoreState(QByteArray state)
|
||||
{
|
||||
ui->splitter->restoreState(state);
|
||||
}
|
||||
void ScriptEditor::restoreState(QByteArray state) { ui->splitter->restoreState(state); }
|
||||
|
||||
void ScriptEditor::setPlainText(const QString& text)
|
||||
{
|
||||
ui->textEdit->setPlainText(text);
|
||||
}
|
||||
void ScriptEditor::setPlainText(const QString& text) { ui->textEdit->setPlainText(text); }
|
||||
|
||||
void ScriptEditor::setEditorFont(QFont font)
|
||||
{
|
||||
ui->textEdit->setFont(font);
|
||||
}
|
||||
void ScriptEditor::setEditorFont(QFont font) { ui->textEdit->setFont(font); }
|
||||
|
||||
QFont ScriptEditor::editorFont()
|
||||
{
|
||||
return ui->textEdit->font();
|
||||
}
|
||||
QFont ScriptEditor::editorFont() { return ui->textEdit->font(); }
|
||||
|
||||
QString ScriptEditor::toPlainText()
|
||||
{
|
||||
return ui->textEdit->toPlainText();
|
||||
}
|
||||
QString ScriptEditor::toPlainText() { return ui->textEdit->toPlainText(); }
|
||||
|
||||
void ScriptEditor::on_twData_doubleClicked(const QModelIndex &index)
|
||||
void ScriptEditor::on_twData_doubleClicked(const QModelIndex& index)
|
||||
{
|
||||
if (!index.isValid()) return;
|
||||
if (!index.isValid())
|
||||
return;
|
||||
LimeReport::DataNode* node = static_cast<LimeReport::DataNode*>(index.internalPointer());
|
||||
if (node->type()==LimeReport::DataNode::Field){
|
||||
ui->textEdit->insertPlainText(QString("$D{%1.%2}").arg(node->parent()->name()).arg(node->name()));
|
||||
if (node->type() == LimeReport::DataNode::Field) {
|
||||
ui->textEdit->insertPlainText(
|
||||
QString("$D{%1.%2}").arg(node->parent()->name()).arg(node->name()));
|
||||
}
|
||||
if (node->type()==LimeReport::DataNode::Variable){
|
||||
if (node->type() == LimeReport::DataNode::Variable) {
|
||||
ui->textEdit->insertPlainText(QString("$V{%1}").arg(node->name()));
|
||||
}
|
||||
ui->textEdit->setFocus();
|
||||
}
|
||||
|
||||
void ScriptEditor::on_twScriptEngine_doubleClicked(const QModelIndex &index)
|
||||
void ScriptEditor::on_twScriptEngine_doubleClicked(const QModelIndex& index)
|
||||
{
|
||||
if (!index.isValid()) return;
|
||||
LimeReport::ScriptEngineNode* node = static_cast<LimeReport::ScriptEngineNode*>(index.internalPointer());
|
||||
if (node->type()==LimeReport::ScriptEngineNode::Function){
|
||||
ui->textEdit->insertPlainText(node->name()+"()");
|
||||
if (!index.isValid())
|
||||
return;
|
||||
LimeReport::ScriptEngineNode* node
|
||||
= static_cast<LimeReport::ScriptEngineNode*>(index.internalPointer());
|
||||
if (node->type() == LimeReport::ScriptEngineNode::Function) {
|
||||
ui->textEdit->insertPlainText(node->name() + "()");
|
||||
}
|
||||
ui->textEdit->setFocus();
|
||||
}
|
||||
|
||||
void ScriptEditor::slotOnCurrentChanged(const QModelIndex &to, const QModelIndex &)
|
||||
void ScriptEditor::slotOnCurrentChanged(const QModelIndex& to, const QModelIndex&)
|
||||
{
|
||||
LimeReport::ScriptEngineNode* node = static_cast<LimeReport::ScriptEngineNode*>(to.internalPointer());
|
||||
if (node->type()==LimeReport::ScriptEngineNode::Function){
|
||||
ui->lblDescription->setText(node->description());
|
||||
LimeReport::ScriptEngineNode* node
|
||||
= static_cast<LimeReport::ScriptEngineNode*>(to.internalPointer());
|
||||
if (node->type() == LimeReport::ScriptEngineNode::Function) {
|
||||
ui->lblDescription->setText(node->description());
|
||||
}
|
||||
}
|
||||
|
||||
QString ReportStructureCompleater::pathFromIndex(const QModelIndex &index) const
|
||||
QString ReportStructureCompleater::pathFromIndex(const QModelIndex& index) const
|
||||
{
|
||||
QStringList dataList;
|
||||
for (QModelIndex i = index; i.isValid(); i = i.parent()) {
|
||||
@@ -177,18 +169,20 @@ QString ReportStructureCompleater::pathFromIndex(const QModelIndex &index) const
|
||||
return dataList.join(".");
|
||||
}
|
||||
|
||||
QStringList ReportStructureCompleater::splitPath(const QString &path) const
|
||||
QStringList ReportStructureCompleater::splitPath(const QString& path) const
|
||||
{
|
||||
return path.split(".");
|
||||
}
|
||||
|
||||
void ReportStructureCompleater::addAdditionalDatawords(CompleterModel* model, DataSourceManager* dataManager){
|
||||
void ReportStructureCompleater::addAdditionalDatawords(CompleterModel* model,
|
||||
DataSourceManager* dataManager)
|
||||
{
|
||||
|
||||
foreach(const QString &dsName,dataManager->dataSourceNames()){
|
||||
foreach (const QString& dsName, dataManager->dataSourceNames()) {
|
||||
CompleterItem* dsNode = new CompleterItem;
|
||||
dsNode->setText(dsName);
|
||||
model->invisibleRootItem()->appendRow(dsNode);
|
||||
foreach(const QString &field, dataManager->fieldNames(dsName)){
|
||||
foreach (const QString& field, dataManager->fieldNames(dsName)) {
|
||||
CompleterItem* fieldNode = new CompleterItem;
|
||||
fieldNode->setText(field);
|
||||
dsNode->appendRow(fieldNode);
|
||||
@@ -205,29 +199,32 @@ void ReportStructureCompleater::addAdditionalDatawords(CompleterModel* model, Da
|
||||
ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
|
||||
QJSValue globalObject = se.scriptEngine()->globalObject();
|
||||
QJSValueIterator it(globalObject);
|
||||
while (it.hasNext()){
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.value().isCallable() ){
|
||||
if (it.value().isCallable()) {
|
||||
CompleterItem* itemNode = new CompleterItem;
|
||||
itemNode->setText(it.name()+"()");
|
||||
itemNode->setText(it.name() + "()");
|
||||
model->invisibleRootItem()->appendRow(itemNode);
|
||||
}
|
||||
if (it.value().isQObject()){
|
||||
if (it.value().toQObject()){
|
||||
if (model->findItems(it.name()).isEmpty()){
|
||||
if (it.value().isQObject()) {
|
||||
if (it.value().toQObject()) {
|
||||
if (model->findItems(it.name()).isEmpty()) {
|
||||
CompleterItem* objectNode = new CompleterItem;
|
||||
objectNode->setText(it.name());
|
||||
objectNode->setIcon(QIcon(":/report/images/object"));
|
||||
|
||||
for (int i = 0; i< it.value().toQObject()->metaObject()->methodCount();++i){
|
||||
if (it.value().toQObject()->metaObject()->method(i).methodType() == QMetaMethod::Method){
|
||||
for (int i = 0; i < it.value().toQObject()->metaObject()->methodCount(); ++i) {
|
||||
if (it.value().toQObject()->metaObject()->method(i).methodType()
|
||||
== QMetaMethod::Method) {
|
||||
CompleterItem* methodNode = new CompleterItem;
|
||||
QMetaMethod m = it.value().toQObject()->metaObject()->method(i);
|
||||
QString methodSignature = m.name() + "(";
|
||||
bool isFirst = true;
|
||||
for (int j = 0; j < m.parameterCount(); ++j){
|
||||
methodSignature += (isFirst ? "" : ",") + m.parameterTypes()[j]+" "+m.parameterNames()[j];
|
||||
if (isFirst) isFirst = false;
|
||||
for (int j = 0; j < m.parameterCount(); ++j) {
|
||||
methodSignature += (isFirst ? "" : ",") + m.parameterTypes()[j]
|
||||
+ " " + m.parameterNames()[j];
|
||||
if (isFirst)
|
||||
isFirst = false;
|
||||
}
|
||||
methodSignature += ")";
|
||||
methodNode->setText(methodSignature);
|
||||
@@ -240,18 +237,17 @@ void ReportStructureCompleater::addAdditionalDatawords(CompleterModel* model, Da
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void ReportStructureCompleater::updateCompleaterModel(ReportEnginePrivateInterface* report)
|
||||
{
|
||||
if (report){
|
||||
if (report) {
|
||||
m_newModel.clear();
|
||||
|
||||
QIcon signalIcon(":/report/images/signal");
|
||||
QIcon propertyIcon(":/report/images/property");
|
||||
|
||||
for ( int i = 0; i < report->pageCount(); ++i){
|
||||
for (int i = 0; i < report->pageCount(); ++i) {
|
||||
PageDesignIntf* page = report->pageAt(i);
|
||||
|
||||
CompleterItem* itemNode = new CompleterItem;
|
||||
@@ -259,21 +255,21 @@ void ReportStructureCompleater::updateCompleaterModel(ReportEnginePrivateInterfa
|
||||
itemNode->setIcon(QIcon(":/report/images/object"));
|
||||
|
||||
QStringList items = extractSignalNames(page->pageItem());
|
||||
foreach(QString slotName, items){
|
||||
foreach (QString slotName, items) {
|
||||
CompleterItem* slotItem = new CompleterItem;
|
||||
slotItem->setText(slotName);
|
||||
slotItem->setIcon(signalIcon);
|
||||
itemNode->appendRow(slotItem);
|
||||
}
|
||||
items = extractProperties(page->pageItem());
|
||||
foreach(QString propertyName, items){
|
||||
foreach (QString propertyName, items) {
|
||||
CompleterItem* properyItem = new CompleterItem;
|
||||
properyItem->setText(propertyName);
|
||||
properyItem->setIcon(propertyIcon);
|
||||
itemNode->appendRow(properyItem);
|
||||
}
|
||||
|
||||
foreach (BaseDesignIntf* item, page->pageItem()->childBaseItems()){
|
||||
foreach (BaseDesignIntf* item, page->pageItem()->childBaseItems()) {
|
||||
addChildItem(item, itemNode->text(), m_newModel.invisibleRootItem());
|
||||
}
|
||||
|
||||
@@ -285,20 +281,20 @@ void ReportStructureCompleater::updateCompleaterModel(ReportEnginePrivateInterfa
|
||||
}
|
||||
}
|
||||
|
||||
void ReportStructureCompleater::updateCompleaterModel(DataSourceManager *dataManager)
|
||||
void ReportStructureCompleater::updateCompleaterModel(DataSourceManager* dataManager)
|
||||
{
|
||||
m_newModel.clear();
|
||||
addAdditionalDatawords(&m_newModel, dataManager);
|
||||
}
|
||||
|
||||
QStringList ReportStructureCompleater::extractSignalNames(BaseDesignIntf *item)
|
||||
QStringList ReportStructureCompleater::extractSignalNames(BaseDesignIntf* item)
|
||||
{
|
||||
QStringList result;
|
||||
if (!item) return result;
|
||||
QMetaObject const * mo = item->metaObject();
|
||||
while (mo){
|
||||
for(int i = mo->methodOffset(); i < mo->methodCount(); ++i)
|
||||
{
|
||||
if (!item)
|
||||
return result;
|
||||
QMetaObject const* mo = item->metaObject();
|
||||
while (mo) {
|
||||
for (int i = mo->methodOffset(); i < mo->methodCount(); ++i) {
|
||||
if (mo->method(i).methodType() == QMetaMethod::Signal) {
|
||||
#ifndef HAVE_QT4
|
||||
result.append(QString::fromLatin1(mo->method(i).name()));
|
||||
@@ -313,15 +309,15 @@ QStringList ReportStructureCompleater::extractSignalNames(BaseDesignIntf *item)
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList ReportStructureCompleater::extractProperties(BaseDesignIntf *item)
|
||||
QStringList ReportStructureCompleater::extractProperties(BaseDesignIntf* item)
|
||||
{
|
||||
QStringList result;
|
||||
if (!item) return result;
|
||||
QMetaObject const * mo = item->metaObject();
|
||||
while (mo){
|
||||
for(int i = mo->propertyOffset(); i < mo->propertyCount(); ++i)
|
||||
{
|
||||
result.append(QString::fromLatin1(mo->property(i).name()));
|
||||
if (!item)
|
||||
return result;
|
||||
QMetaObject const* mo = item->metaObject();
|
||||
while (mo) {
|
||||
for (int i = mo->propertyOffset(); i < mo->propertyCount(); ++i) {
|
||||
result.append(QString::fromLatin1(mo->property(i).name()));
|
||||
}
|
||||
mo = mo->superClass();
|
||||
}
|
||||
@@ -329,74 +325,70 @@ QStringList ReportStructureCompleater::extractProperties(BaseDesignIntf *item)
|
||||
return result;
|
||||
}
|
||||
|
||||
void ReportStructureCompleater::addChildItem(BaseDesignIntf *item, const QString &pageName, CompleterItem *parent)
|
||||
void ReportStructureCompleater::addChildItem(BaseDesignIntf* item, const QString& pageName,
|
||||
CompleterItem* parent)
|
||||
{
|
||||
if (!item) return;
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
QIcon signalIcon(":/report/images/signal");
|
||||
QIcon propertyIcon(":/report/images/property");
|
||||
|
||||
CompleterItem* itemNode = new CompleterItem;
|
||||
itemNode->setText(pageName+"_"+item->objectName());
|
||||
itemNode->setText(pageName + "_" + item->objectName());
|
||||
itemNode->setIcon(QIcon(":/report/images/object"));
|
||||
parent->appendRow(itemNode);
|
||||
|
||||
// if (m_cache.contains(item->metaObject()->className())){
|
||||
// if (m_cache.contains(item->metaObject()->className())){
|
||||
|
||||
// QSharedPointer<CacheItem> cacheItem = m_cache.value(item->metaObject()->className());
|
||||
// itemNode->appendRows(cacheItem->slotsItems);
|
||||
// itemNode->appendRows(cacheItem->propsItems);
|
||||
// QSharedPointer<CacheItem> cacheItem =
|
||||
// m_cache.value(item->metaObject()->className());
|
||||
// itemNode->appendRows(cacheItem->slotsItems);
|
||||
// itemNode->appendRows(cacheItem->propsItems);
|
||||
|
||||
// } else {
|
||||
// } else {
|
||||
|
||||
// QSharedPointer<CacheItem> cacheItem = QSharedPointer<CacheItem>(new CacheItem);
|
||||
// QSharedPointer<CacheItem> cacheItem = QSharedPointer<CacheItem>(new CacheItem);
|
||||
|
||||
QStringList items;
|
||||
if (!m_signals.contains(item->metaObject()->className())){
|
||||
items = extractSignalNames(item);
|
||||
m_signals.insert(item->metaObject()->className(),items);
|
||||
} else {
|
||||
items = m_signals.value(item->metaObject()->className());
|
||||
}
|
||||
QStringList items;
|
||||
if (!m_signals.contains(item->metaObject()->className())) {
|
||||
items = extractSignalNames(item);
|
||||
m_signals.insert(item->metaObject()->className(), items);
|
||||
} else {
|
||||
items = m_signals.value(item->metaObject()->className());
|
||||
}
|
||||
|
||||
foreach(QString slotName, items){
|
||||
CompleterItem* slotItem = new CompleterItem;
|
||||
slotItem->setText(slotName);
|
||||
slotItem->setIcon(signalIcon);
|
||||
//cacheItem->slotsItems.append(QSharedPointer<CompleterItem>(slotItem));
|
||||
itemNode->appendRow(slotItem);
|
||||
foreach (QString slotName, items) {
|
||||
CompleterItem* slotItem = new CompleterItem;
|
||||
slotItem->setText(slotName);
|
||||
slotItem->setIcon(signalIcon);
|
||||
// cacheItem->slotsItems.append(QSharedPointer<CompleterItem>(slotItem));
|
||||
itemNode->appendRow(slotItem);
|
||||
}
|
||||
|
||||
}
|
||||
if (!m_properties.contains(item->metaObject()->className())) {
|
||||
items = extractProperties(item);
|
||||
m_properties.insert(item->metaObject()->className(), items);
|
||||
} else {
|
||||
items = m_properties.value(item->metaObject()->className());
|
||||
}
|
||||
|
||||
if (!m_properties.contains(item->metaObject()->className())){
|
||||
items = extractProperties(item);
|
||||
m_properties.insert(item->metaObject()->className(),items);
|
||||
} else {
|
||||
items = m_properties.value(item->metaObject()->className());
|
||||
}
|
||||
foreach (QString propertyName, items) {
|
||||
CompleterItem* properyItem = new CompleterItem;
|
||||
properyItem->setText(propertyName);
|
||||
properyItem->setIcon(propertyIcon);
|
||||
itemNode->appendRow(properyItem);
|
||||
// cacheItem->propsItems.append(QSharedPointer<CompleterItem>(properyItem));
|
||||
}
|
||||
|
||||
foreach(QString propertyName, items){
|
||||
CompleterItem* properyItem = new CompleterItem;
|
||||
properyItem->setText(propertyName);
|
||||
properyItem->setIcon(propertyIcon);
|
||||
itemNode->appendRow(properyItem);
|
||||
//cacheItem->propsItems.append(QSharedPointer<CompleterItem>(properyItem));
|
||||
}
|
||||
|
||||
//m_cache.insert(item->metaObject()->className(), cacheItem);
|
||||
//itemNode->appendRows(cacheItem->slotsItems);
|
||||
//itemNode->appendRows(cacheItem->propsItems);
|
||||
// m_cache.insert(item->metaObject()->className(), cacheItem);
|
||||
// itemNode->appendRows(cacheItem->slotsItems);
|
||||
// itemNode->appendRows(cacheItem->propsItems);
|
||||
//}
|
||||
|
||||
foreach (BaseDesignIntf* child, item->childBaseItems()){
|
||||
foreach (BaseDesignIntf* child, item->childBaseItems()) {
|
||||
addChildItem(child, pageName, parent);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace LimeReport
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
#ifndef LRSCRIPTEDITOR_H
|
||||
#define LRSCRIPTEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "lrcompletermodel.h"
|
||||
|
||||
#include <QCompleter>
|
||||
#include <QTextEdit>
|
||||
#include <QKeyEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QStandardItemModel>
|
||||
#include "lrcompletermodel.h"
|
||||
#include <QTextEdit>
|
||||
#include <QWidget>
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
class ReportEnginePrivateInterface;
|
||||
class BaseDesignIntf;
|
||||
@@ -18,7 +19,7 @@ class BandDesignIntf;
|
||||
class DataSourceManager;
|
||||
|
||||
namespace Ui {
|
||||
class ScriptEditor;
|
||||
class ScriptEditor;
|
||||
}
|
||||
|
||||
struct CacheItem {
|
||||
@@ -26,34 +27,42 @@ struct CacheItem {
|
||||
QList<QSharedPointer<CompleterItem>> slotsItems;
|
||||
};
|
||||
|
||||
class ReportStructureCompleater : public QCompleter{
|
||||
class ReportStructureCompleater: public QCompleter {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ReportStructureCompleater(QObject* parent = 0): QCompleter(parent){ setModel(&m_newModel);}
|
||||
explicit ReportStructureCompleater(QAbstractItemModel* model, QObject* parent = 0)
|
||||
:QCompleter(model, parent){ setModel(&m_newModel);}
|
||||
explicit ReportStructureCompleater(QObject* parent = 0): QCompleter(parent)
|
||||
{
|
||||
setModel(&m_newModel);
|
||||
}
|
||||
explicit ReportStructureCompleater(QAbstractItemModel* model, QObject* parent = 0):
|
||||
QCompleter(model, parent)
|
||||
{
|
||||
setModel(&m_newModel);
|
||||
}
|
||||
|
||||
public:
|
||||
// QCompleter interface
|
||||
QString pathFromIndex(const QModelIndex& index) const;
|
||||
QStringList splitPath(const QString& path) const;
|
||||
void updateCompleaterModel(ReportEnginePrivateInterface* report);
|
||||
void updateCompleaterModel(DataSourceManager* dataManager);
|
||||
|
||||
protected:
|
||||
QStringList extractSignalNames(BaseDesignIntf* item);
|
||||
QStringList extractProperties(BaseDesignIntf* item);
|
||||
void addChildItem(BaseDesignIntf *item, const QString &pageName, CompleterItem *parent);
|
||||
void addAdditionalDatawords(CompleterModel *model, DataSourceManager *dataManager);
|
||||
void addChildItem(BaseDesignIntf* item, const QString& pageName, CompleterItem* parent);
|
||||
void addAdditionalDatawords(CompleterModel* model, DataSourceManager* dataManager);
|
||||
|
||||
private:
|
||||
CompleterModel m_newModel;
|
||||
QMap<QString, QStringList> m_properties;
|
||||
QMap<QString, QStringList> m_signals;
|
||||
};
|
||||
|
||||
class ScriptEditor : public QWidget
|
||||
{
|
||||
class ScriptEditor: public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScriptEditor(QWidget *parent = 0);
|
||||
explicit ScriptEditor(QWidget* parent = 0);
|
||||
~ScriptEditor();
|
||||
void setReportEngine(LimeReport::ReportEnginePrivateInterface* reportEngine);
|
||||
void setReportPage(PageDesignIntf* page);
|
||||
@@ -62,7 +71,7 @@ public:
|
||||
void initCompleter();
|
||||
QByteArray saveState();
|
||||
void restoreState(QByteArray state);
|
||||
void setPlainText(const QString &text);
|
||||
void setPlainText(const QString& text);
|
||||
void setEditorFont(QFont font);
|
||||
QFont editorFont();
|
||||
QString toPlainText();
|
||||
@@ -71,16 +80,17 @@ public:
|
||||
signals:
|
||||
void splitterMoved(int, int);
|
||||
void textChanged();
|
||||
|
||||
protected:
|
||||
void initEditor(DataSourceManager* dm);
|
||||
|
||||
private slots:
|
||||
void on_twData_doubleClicked(const QModelIndex &index);
|
||||
void on_twScriptEngine_doubleClicked(const QModelIndex &index);
|
||||
void on_twData_doubleClicked(const QModelIndex& index);
|
||||
void on_twScriptEngine_doubleClicked(const QModelIndex& index);
|
||||
void slotOnCurrentChanged(const QModelIndex& to, const QModelIndex&);
|
||||
|
||||
private:
|
||||
Ui::ScriptEditor *ui;
|
||||
Ui::ScriptEditor* ui;
|
||||
ReportEnginePrivateInterface* m_reportEngine;
|
||||
PageDesignIntf* m_page;
|
||||
ReportStructureCompleater* m_completer;
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
#include "lrscripthighlighter.h"
|
||||
|
||||
#include "lrglobal.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPalette>
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
#define KEYWORDS_COUNT 60
|
||||
|
||||
static const char *const keywords[KEYWORDS_COUNT] = {
|
||||
"do","if","in","for","int","new","try","var","byte","case","char","else","enum",
|
||||
"goto","long","null","this","true","void","with","break","catch","class","const",
|
||||
"false","final","float","short","super","throw","while","delete","double","export",
|
||||
"import","native","public","return","static","switch","throws","typeof","boolean",
|
||||
"default","extends","finally","package","private","abstract","continue","debugger",
|
||||
"function","volatile","interface","protected","transient","implements","instanceof",
|
||||
"synchronized","let"
|
||||
};
|
||||
static const char* const keywords[KEYWORDS_COUNT]
|
||||
= { "do", "if", "in", "for", "int", "new",
|
||||
"try", "var", "byte", "case", "char", "else",
|
||||
"enum", "goto", "long", "null", "this", "true",
|
||||
"void", "with", "break", "catch", "class", "const",
|
||||
"false", "final", "float", "short", "super", "throw",
|
||||
"while", "delete", "double", "export", "import", "native",
|
||||
"public", "return", "static", "switch", "throws", "typeof",
|
||||
"boolean", "default", "extends", "finally", "package", "private",
|
||||
"abstract", "continue", "debugger", "function", "volatile", "interface",
|
||||
"protected", "transient", "implements", "instanceof", "synchronized", "let" };
|
||||
|
||||
enum LiteralsType {
|
||||
SpaceFound,
|
||||
@@ -50,11 +54,12 @@ enum States {
|
||||
StatesCount
|
||||
};
|
||||
|
||||
void ScriptHighlighter::createParentheisisInfo(const char& literal, TextBlockData *data, const QString& text)
|
||||
void ScriptHighlighter::createParentheisisInfo(const char& literal, TextBlockData* data,
|
||||
const QString& text)
|
||||
{
|
||||
int pos = text.indexOf(literal);
|
||||
while (pos != -1) {
|
||||
ParenthesisInfo *info = new ParenthesisInfo;
|
||||
ParenthesisInfo* info = new ParenthesisInfo;
|
||||
info->character = literal;
|
||||
info->position = pos;
|
||||
data->insert(info);
|
||||
@@ -70,73 +75,97 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
||||
States state = prevState != Undefined ? (States)prevState : Start;
|
||||
States oldState = Undefined;
|
||||
const States stateMaschine[StatesCount][LiteralsCount] = {
|
||||
// Space Alpahabet Number Hash Slash Asterix, Bracket, Quotation, Apostrophe, Apostrophe2 Separator, Back Slash
|
||||
{Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Separator},
|
||||
{Separator, MayBeKeyWord, Code, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Separator},
|
||||
{Separator, Code, Code, Separator, Separator, Separator, Separator, String, String2, String3, Separator, Separator},
|
||||
{Separator, Code, MayBeNumber, Code, Comment, Comment2, Code, String, String2, String3, Separator, Code},
|
||||
{Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment},
|
||||
{Comment2, Comment2, Comment2, Comment2, Comment2, MayBeComment2End, Comment2, Comment2, Comment2, Comment2, Comment2, Comment2},
|
||||
{Comment2, Comment2, Comment2, Comment2, Separator, Comment2, Comment2, Comment2, Comment2, Comment2, Comment2, Comment2},
|
||||
{String, String, String, String, String, String, String, Separator, String, String, String, String},
|
||||
{String2, String2, String2, String2, String2, String2, String2, String2, Separator, String2, String2, String2},
|
||||
{String3, String3, String3, String3, String3, String3, String3, String3, String3, Separator, String3, String3},
|
||||
{Separator, Code, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Code},
|
||||
{Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Separator},
|
||||
// Space Alpahabet Number Hash Slash Asterix,
|
||||
// Bracket, Quotation, Apostrophe, Apostrophe2 Separator, Back Slash
|
||||
{ Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator,
|
||||
String, String2, String3, Separator, Separator },
|
||||
{ Separator, MayBeKeyWord, Code, Separator, MayBeComment, Separator, Separator, String,
|
||||
String2, String3, Separator, Separator },
|
||||
{ Separator, Code, Code, Separator, Separator, Separator, Separator, String, String2,
|
||||
String3, Separator, Separator },
|
||||
{ Separator, Code, MayBeNumber, Code, Comment, Comment2, Code, String, String2, String3,
|
||||
Separator, Code },
|
||||
{ Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment, Comment,
|
||||
Comment, Comment },
|
||||
{ Comment2, Comment2, Comment2, Comment2, Comment2, MayBeComment2End, Comment2, Comment2,
|
||||
Comment2, Comment2, Comment2, Comment2 },
|
||||
{ Comment2, Comment2, Comment2, Comment2, Separator, Comment2, Comment2, Comment2, Comment2,
|
||||
Comment2, Comment2, Comment2 },
|
||||
{ String, String, String, String, String, String, String, Separator, String, String, String,
|
||||
String },
|
||||
{ String2, String2, String2, String2, String2, String2, String2, String2, Separator,
|
||||
String2, String2, String2 },
|
||||
{ String3, String3, String3, String3, String3, String3, String3, String3, String3,
|
||||
Separator, String3, String3 },
|
||||
{ Separator, Code, MayBeNumber, Separator, MayBeComment, Separator, Separator, String,
|
||||
String2, String3, Separator, Code },
|
||||
{ Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator,
|
||||
String, String2, String3, Separator, Separator },
|
||||
};
|
||||
|
||||
QString buffer;
|
||||
|
||||
setCurrentBlockState(Undefined);
|
||||
|
||||
if (text.isEmpty())
|
||||
{
|
||||
if (text.isEmpty()) {
|
||||
if (prevState == Comment2)
|
||||
setCurrentBlockState(Comment2);
|
||||
return;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (;;){
|
||||
for (;;) {
|
||||
QChar currentChar = text.at(i);
|
||||
switch(currentChar.toLatin1()){
|
||||
case ' ':
|
||||
literal = SpaceFound;
|
||||
break;
|
||||
case '/':
|
||||
literal = SlashFound;
|
||||
break;
|
||||
case '*':
|
||||
literal = AsterixFound;
|
||||
break;
|
||||
case '#':
|
||||
literal = HashFound;
|
||||
break;
|
||||
case '\'':
|
||||
literal = ApostropheFound;
|
||||
break;
|
||||
case '\\':
|
||||
literal = BackSlashFound;
|
||||
break;
|
||||
case '"':
|
||||
literal = QuotationFound;
|
||||
break;
|
||||
case '`':
|
||||
literal = Apostrophe2Found;
|
||||
break;
|
||||
case '{': case '[': case '(':
|
||||
case '}': case ']': case ')':
|
||||
literal = BracketFound;
|
||||
break;
|
||||
case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9': case '0':
|
||||
literal = NumberFound;
|
||||
break;
|
||||
default:
|
||||
if (currentChar.isLetter())
|
||||
literal = AlpahabetFound;
|
||||
else
|
||||
literal = SeparatorFound;
|
||||
switch (currentChar.toLatin1()) {
|
||||
case ' ':
|
||||
literal = SpaceFound;
|
||||
break;
|
||||
case '/':
|
||||
literal = SlashFound;
|
||||
break;
|
||||
case '*':
|
||||
literal = AsterixFound;
|
||||
break;
|
||||
case '#':
|
||||
literal = HashFound;
|
||||
break;
|
||||
case '\'':
|
||||
literal = ApostropheFound;
|
||||
break;
|
||||
case '\\':
|
||||
literal = BackSlashFound;
|
||||
break;
|
||||
case '"':
|
||||
literal = QuotationFound;
|
||||
break;
|
||||
case '`':
|
||||
literal = Apostrophe2Found;
|
||||
break;
|
||||
case '{':
|
||||
case '[':
|
||||
case '(':
|
||||
case '}':
|
||||
case ']':
|
||||
case ')':
|
||||
literal = BracketFound;
|
||||
break;
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
case '0':
|
||||
literal = NumberFound;
|
||||
break;
|
||||
default:
|
||||
if (currentChar.isLetter())
|
||||
literal = AlpahabetFound;
|
||||
else
|
||||
literal = SeparatorFound;
|
||||
};
|
||||
|
||||
lastWasBackSlash = !lastWasBackSlash && currentChar == QLatin1Char('\\');
|
||||
@@ -147,85 +176,83 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
||||
buffer += currentChar;
|
||||
|
||||
if (oldState != state) {
|
||||
switch( state ){
|
||||
case MayBeComment:
|
||||
if (oldState == MayBeNumber){
|
||||
setFormat(i-(buffer.length()-1), buffer.length()-1, m_formats[NumberFormat]);
|
||||
switch (state) {
|
||||
case MayBeComment:
|
||||
if (oldState == MayBeNumber) {
|
||||
setFormat(i - (buffer.length() - 1), buffer.length() - 1,
|
||||
m_formats[NumberFormat]);
|
||||
}
|
||||
buffer.clear();
|
||||
buffer += currentChar;
|
||||
break;
|
||||
case String:
|
||||
case String2:
|
||||
case String3:
|
||||
buffer.clear();
|
||||
buffer += currentChar;
|
||||
break;
|
||||
case MayBeKeyWord:
|
||||
case MayBeNumber:
|
||||
buffer.clear();
|
||||
buffer += currentChar;
|
||||
break;
|
||||
case Comment2:
|
||||
setCurrentBlockState(Comment2);
|
||||
case Separator:
|
||||
switch (oldState) {
|
||||
case MayBeComment2End:
|
||||
setFormat(i - (buffer.length() - 1), buffer.length(), m_formats[CommentFormat]);
|
||||
setCurrentBlockState(Undefined);
|
||||
buffer.clear();
|
||||
break;
|
||||
case MayBeKeyWord:
|
||||
if (isKeyWord(buffer.left(buffer.length() - 1))) {
|
||||
setFormat(i - (buffer.length() - 1), buffer.length() - 1,
|
||||
m_formats[KeywordFormat]);
|
||||
}
|
||||
buffer.clear();
|
||||
buffer += currentChar;
|
||||
break;
|
||||
case MayBeNumber:
|
||||
setFormat(i - (buffer.length() - 1), buffer.length() - 1,
|
||||
m_formats[NumberFormat]);
|
||||
buffer.clear();
|
||||
case String:
|
||||
case String2:
|
||||
case String3:
|
||||
setFormat(i - (buffer.length() - 1), buffer.length(), m_formats[StringFormat]);
|
||||
buffer.clear();
|
||||
buffer += currentChar;
|
||||
break;
|
||||
case MayBeKeyWord:
|
||||
case MayBeNumber:
|
||||
buffer.clear();
|
||||
buffer += currentChar;
|
||||
break;
|
||||
case Comment2:
|
||||
setCurrentBlockState(Comment2);
|
||||
case Separator:
|
||||
switch(oldState){
|
||||
case MayBeComment2End:
|
||||
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[CommentFormat]);
|
||||
setCurrentBlockState(Undefined);
|
||||
buffer.clear();
|
||||
break;
|
||||
case MayBeKeyWord:
|
||||
if (isKeyWord(buffer.left(buffer.length()-1))){
|
||||
setFormat(i-(buffer.length()-1), buffer.length()-1, m_formats[KeywordFormat]);
|
||||
}
|
||||
buffer.clear();
|
||||
break;
|
||||
case MayBeNumber:
|
||||
setFormat(i-(buffer.length()-1), buffer.length()-1, m_formats[NumberFormat]);
|
||||
buffer.clear();
|
||||
case String:
|
||||
case String2:
|
||||
case String3:
|
||||
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[StringFormat]);
|
||||
buffer.clear();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (state == Comment2)
|
||||
{
|
||||
} else if (state == Comment2) {
|
||||
setCurrentBlockState(Comment2);
|
||||
}
|
||||
|
||||
if ( state == Comment || state == Comment2 ){
|
||||
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[CommentFormat]);
|
||||
if (state == Comment || state == Comment2) {
|
||||
setFormat(i - (buffer.length() - 1), buffer.length(), m_formats[CommentFormat]);
|
||||
}
|
||||
|
||||
if ( state == String || state == String2 || state == String3 ){
|
||||
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[StringFormat]);
|
||||
if (state == String || state == String2 || state == String3) {
|
||||
setFormat(i - (buffer.length() - 1), buffer.length(), m_formats[StringFormat]);
|
||||
}
|
||||
|
||||
i++;
|
||||
if ( i>= text.length()) break;
|
||||
if (i >= text.length())
|
||||
break;
|
||||
}
|
||||
|
||||
if (buffer.length())
|
||||
{
|
||||
if (state == MayBeKeyWord)
|
||||
{
|
||||
if (buffer.length()) {
|
||||
if (state == MayBeKeyWord) {
|
||||
if (isKeyWord(buffer))
|
||||
setFormat(i - buffer.length(), buffer.length(), m_formats[KeywordFormat]);
|
||||
}
|
||||
else if (state == MayBeNumber)
|
||||
{
|
||||
setFormat(i - buffer.length(), buffer.length(), m_formats[KeywordFormat]);
|
||||
} else if (state == MayBeNumber) {
|
||||
setFormat(i - buffer.length(), buffer.length(), m_formats[NumberFormat]);
|
||||
}
|
||||
}
|
||||
|
||||
TextBlockData *data = new TextBlockData;
|
||||
TextBlockData* data = new TextBlockData;
|
||||
|
||||
for (int i = 0; i < PARENHEIS_COUNT; ++i) {
|
||||
createParentheisisInfo(parenthesisCharacters[LeftParenthesis][i].toLatin1(), data, text);
|
||||
@@ -235,19 +262,15 @@ void ScriptHighlighter::highlightBlock(const QString& text)
|
||||
setCurrentBlockUserData(data);
|
||||
}
|
||||
|
||||
bool ScriptHighlighter::isKeyWord(const QString& word)
|
||||
{
|
||||
return m_keywords.contains(word);
|
||||
}
|
||||
bool ScriptHighlighter::isKeyWord(const QString& word) { return m_keywords.contains(word); }
|
||||
|
||||
ScriptHighlighter::ScriptHighlighter(QTextDocument* parent):
|
||||
QSyntaxHighlighter(parent)
|
||||
ScriptHighlighter::ScriptHighlighter(QTextDocument* parent): QSyntaxHighlighter(parent)
|
||||
{
|
||||
for(int i=0; i<KEYWORDS_COUNT; ++i){
|
||||
for (int i = 0; i < KEYWORDS_COUNT; ++i) {
|
||||
m_keywords.insert(keywords[i]);
|
||||
}
|
||||
|
||||
if ( isColorDark(QPalette().window().color())){
|
||||
if (isColorDark(QPalette().window().color())) {
|
||||
m_formats[NumberFormat].setForeground(QColor("#45c6d1"));
|
||||
m_formats[StringFormat].setForeground(Qt::darkGreen);
|
||||
m_formats[KeywordFormat].setForeground(QColor("#cd5125"));
|
||||
@@ -264,21 +287,17 @@ ScriptHighlighter::ScriptHighlighter(QTextDocument* parent):
|
||||
|
||||
TextBlockData::~TextBlockData()
|
||||
{
|
||||
foreach(ParenthesisInfo* info, m_parentheses){
|
||||
foreach (ParenthesisInfo* info, m_parentheses) {
|
||||
delete info;
|
||||
}
|
||||
}
|
||||
|
||||
QVector<ParenthesisInfo*> TextBlockData::parentheses()
|
||||
{
|
||||
return m_parentheses;
|
||||
}
|
||||
QVector<ParenthesisInfo*> TextBlockData::parentheses() { return m_parentheses; }
|
||||
|
||||
void TextBlockData::insert(ParenthesisInfo* info)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < m_parentheses.size() &&
|
||||
info->position > m_parentheses.at(i)->position)
|
||||
while (i < m_parentheses.size() && info->position > m_parentheses.at(i)->position)
|
||||
++i;
|
||||
|
||||
m_parentheses.insert(i, info);
|
||||
|
||||
@@ -1,53 +1,57 @@
|
||||
#ifndef LRSCRIPTHIGHLIGHTER_H
|
||||
#define LRSCRIPTHIGHLIGHTER_H
|
||||
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QSet>
|
||||
#include <QSyntaxHighlighter>
|
||||
|
||||
namespace LimeReport{
|
||||
namespace LimeReport {
|
||||
|
||||
enum ParenthesisType {LeftParenthesis, RightParenthesis, ParenthesisTypeCount};
|
||||
|
||||
#define PARENHEIS_COUNT 3
|
||||
const QChar parenthesisCharacters[ParenthesisTypeCount][PARENHEIS_COUNT] = {
|
||||
{'(', '{', '['},
|
||||
{')', '}', ']'}
|
||||
enum ParenthesisType {
|
||||
LeftParenthesis,
|
||||
RightParenthesis,
|
||||
ParenthesisTypeCount
|
||||
};
|
||||
|
||||
struct ParenthesisInfo
|
||||
{
|
||||
#define PARENHEIS_COUNT 3
|
||||
const QChar parenthesisCharacters[ParenthesisTypeCount][PARENHEIS_COUNT]
|
||||
= { { '(', '{', '[' }, { ')', '}', ']' } };
|
||||
|
||||
struct ParenthesisInfo {
|
||||
char character;
|
||||
int position;
|
||||
};
|
||||
|
||||
class TextBlockData : public QTextBlockUserData
|
||||
{
|
||||
class TextBlockData: public QTextBlockUserData {
|
||||
public:
|
||||
TextBlockData(){}
|
||||
TextBlockData() { }
|
||||
~TextBlockData();
|
||||
QVector<ParenthesisInfo *> parentheses();
|
||||
void insert(ParenthesisInfo *info);
|
||||
QVector<ParenthesisInfo*> parentheses();
|
||||
void insert(ParenthesisInfo* info);
|
||||
|
||||
private:
|
||||
QVector<ParenthesisInfo *> m_parentheses;
|
||||
QVector<ParenthesisInfo*> m_parentheses;
|
||||
};
|
||||
|
||||
class ScriptHighlighter : QSyntaxHighlighter{
|
||||
class ScriptHighlighter: QSyntaxHighlighter {
|
||||
public:
|
||||
ScriptHighlighter(QTextDocument* parent);
|
||||
|
||||
protected:
|
||||
void highlightBlock(const QString& text);
|
||||
enum ScriptFormats {
|
||||
NumberFormat, StringFormat, KeywordFormat,
|
||||
CommentFormat, FormatsCount
|
||||
NumberFormat,
|
||||
StringFormat,
|
||||
KeywordFormat,
|
||||
CommentFormat,
|
||||
FormatsCount
|
||||
};
|
||||
QTextCharFormat m_formats[FormatsCount];
|
||||
bool isKeyWord(const QString& word);
|
||||
void createParentheisisInfo(const char& literal, TextBlockData *data, const QString& text);
|
||||
void createParentheisisInfo(const char& literal, TextBlockData* data, const QString& text);
|
||||
|
||||
private:
|
||||
QSet<QString> m_keywords;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace LimeReport
|
||||
#endif // LRSCRIPTHIGHLIGHTER_H
|
||||
|
||||
Reference in New Issue
Block a user