0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00

Initial commit

This commit is contained in:
Arin Alexander 2017-09-13 17:16:54 +03:00
parent c9b6078fa8
commit 090477fa68
7 changed files with 404 additions and 3 deletions

View File

@ -33,7 +33,6 @@
#include "lrdatasourcemanager.h"
#include "lrscriptenginemanager.h"
#include "lrdatadesignintf.h"
#include "lrdatasourcemanager.h"
#include <QMenu>
#include <QScrollBar>

View File

@ -59,6 +59,7 @@ SOURCES += \
$$REPORT_PATH/objectinspector/lrpropertydelegate.cpp \
$$REPORT_PATH/objectsbrowser/lrobjectbrowser.cpp \
$$REPORT_PATH/scriptbrowser/lrscriptbrowser.cpp \
$$REPORT_PATH/scripteditor/lrscripteditor.cpp \
$$REPORT_PATH/items/lrsubitemparentpropitem.cpp \
$$REPORT_PATH/items/lralignpropitem.cpp \
$$REPORT_PATH/items/lrhorizontallayout.cpp \
@ -161,6 +162,7 @@ HEADERS += \
$$REPORT_PATH/objectinspector/lrpropertydelegate.h \
$$REPORT_PATH/objectsbrowser/lrobjectbrowser.h \
$$REPORT_PATH/scriptbrowser/lrscriptbrowser.h \
$$REPORT_PATH/scripteditor/lrscripteditor.h \
$$REPORT_PATH/items/editors/lritemeditorwidget.h \
$$REPORT_PATH/items/editors/lrfonteditorwidget.h \
$$REPORT_PATH/items/editors/lrtextalignmenteditorwidget.h \
@ -235,7 +237,8 @@ FORMS += \
$$REPORT_PATH/scriptbrowser/lrscriptbrowser.ui \
$$REPORT_PATH/items/lrchartitemeditor.ui \
$$REPORT_PATH/translationeditor/translationeditor.ui \
$$PWD/translationeditor/languageselectdialog.ui
$$REPORT_PATH/translationeditor/languageselectdialog.ui
$$REPORT_PATH/scripteditor/lrscripteditor.ui
RESOURCES += \
$$REPORT_PATH/objectinspector/lobjectinspector.qrc \

View File

@ -35,6 +35,7 @@
#include "lrsettingdialog.h"
#include "dialogdesigner/lrdialogdesigner.h"
#include "translationeditor/translationeditor.h"
#include "scripteditor/lrscripteditor.h"
#include <QDebug>
#include <QObject>
@ -246,6 +247,12 @@ void ReportDesignWidget::createTabs(){
m_tabWidget->setTabWhatsThis(pageIndex,"script");
m_tabWidget->setCurrentIndex(0);
m_newScriptEditor = new ScriptEditor(this);
m_newScriptEditor->setReportEngine(m_report);
pageIndex = m_tabWidget->addTab(m_newScriptEditor,QIcon(),tr("New Script Editor"));
m_tabWidget->setTabWhatsThis(pageIndex,"script");
m_tabWidget->setCurrentIndex(0);
#ifdef HAVE_QTDESIGNER_INTEGRATION
QWidget* dialogDesigner;
foreach(DialogDescriber::Ptr dialogDesc, m_report->scriptContext()->dialogDescribers()){
@ -787,6 +794,11 @@ void ReportDesignWidget::slotCurrentTabChanged(int index)
if (activeTabType() == Translations){
m_traslationEditor->setReportEngine(report());
}
if (activeTabType() == Script){
m_newScriptEditor->initCompleter();
}
emit activePageChanged();
}

View File

@ -51,6 +51,8 @@ class ReportDesignWindow;
class DialogDesignerManager;
class DialogDesigner;
class TranslationEditor;
class ScriptEditor;
class ReportDesignWidget : public QWidget
{
@ -190,6 +192,7 @@ private:
ReportEnginePrivate* m_report;
QGraphicsView *m_view;
QTextEdit* m_scriptEditor;
ScriptEditor* m_newScriptEditor;
TranslationEditor* m_traslationEditor;
#ifdef HAVE_QTDESIGNER_INTEGRATION
DialogDesignerManager* m_dialogDesignerManager;
@ -205,5 +208,5 @@ private:
bool m_dialogChanged;
};
}
} // namespace LimeReport
#endif // LRREPORTDESIGNWIDGET_H

View File

@ -0,0 +1,189 @@
#include "lrscripteditor.h"
#include "ui_lrscripteditor.h"
#include <QJSValueIterator>
#include "lrdatasourcemanager.h"
#include "lrscriptenginemanager.h"
#include "lrdatadesignintf.h"
#include "lrreportengine_p.h"
namespace LimeReport{
TextEditorWithCompleater::TextEditorWithCompleater(QWidget *parent)
: QTextEdit(parent),m_compleater(0)
{
}
void TextEditorWithCompleater::setCompleter(QCompleter *value)
{
if (value) disconnect(value,0,this,0);
m_compleater = value;
if (!m_compleater) return;
m_compleater->setWidget(this);
m_compleater->setCompletionMode(QCompleter::PopupCompletion);
m_compleater->setCaseSensitivity(Qt::CaseInsensitive);
connect(m_compleater,SIGNAL(activated(QString)),this,SLOT(insertCompletion(QString)));
}
void TextEditorWithCompleater::keyPressEvent(QKeyEvent *e)
{
if (m_compleater && m_compleater->popup()->isVisible()) {
switch (e->key()) {
case Qt::Key_Enter:
case Qt::Key_Return:
case Qt::Key_Escape:
case Qt::Key_Tab:
case Qt::Key_Backtab:
e->ignore();
return;
default:
break;
}
}
bool isShortcut = ((e->modifiers() & Qt::ControlModifier) && e->key() == Qt::Key_Space);
if (!m_compleater || !isShortcut) QTextEdit::keyPressEvent(e);
const bool ctrlOrShift = e->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
if (!m_compleater || (ctrlOrShift && e->text().isEmpty()))
return;
static QString eow("~!@#$%^&*()_+{}|:\"<>?,./;'[]\\-="); // end of word
bool hasModifier = (e->modifiers() != Qt::NoModifier) && !ctrlOrShift;
QString completionPrefix = textUnderCursor();
if (!isShortcut && (hasModifier || e->text().isEmpty()|| completionPrefix.length() < 3
|| eow.contains(e->text().right(1)))) {
m_compleater->popup()->hide();
return;
}
if (completionPrefix != m_compleater->completionPrefix()) {
m_compleater->setCompletionPrefix(completionPrefix);
m_compleater->popup()->setCurrentIndex(m_compleater->completionModel()->index(0, 0));
}
QRect cr = cursorRect();
cr.setWidth(m_compleater->popup()->sizeHintForColumn(0)
+ m_compleater->popup()->verticalScrollBar()->sizeHint().width());
m_compleater->complete(cr);
}
void TextEditorWithCompleater::focusInEvent(QFocusEvent *e)
{
if (m_compleater) m_compleater->setWidget(this);
QTextEdit::focusInEvent(e);
}
QString TextEditorWithCompleater::textUnderCursor() const
{
QTextCursor tc = textCursor();
tc.select(QTextCursor::WordUnderCursor);
return tc.selectedText();
}
void TextEditorWithCompleater::insertCompletion(const QString &completion)
{
if (m_compleater->widget() != this)
return;
QTextCursor tc = textCursor();
int extra = completion.length() - m_compleater->completionPrefix().length();
tc.movePosition(QTextCursor::Left);
tc.movePosition(QTextCursor::EndOfWord);
tc.insertText(completion.right(extra));
setTextCursor(tc);
}
ScriptEditor::ScriptEditor(QWidget *parent) :
QWidget(parent),
ui(new Ui::ScriptEditor)
{
ui->setupUi(this);
m_completer = new QCompleter(this);
ui->textEdit->setCompleter(m_completer);
}
ScriptEditor::~ScriptEditor()
{
delete ui;
}
void ScriptEditor::setReportEngine(ReportEnginePrivate* reportEngine)
{
m_reportEngine = reportEngine;
DataSourceManager* dm = m_reportEngine->dataManager();
ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
se.setDataManager(dm);
initCompleter();
if (dm){
if (dm->isNeedUpdateDatasourceModel())
dm->updateDatasourceModel();
ui->twData->setModel(dm->datasourcesModel());
ui->twScriptEngine->setModel(se.model());
}
}
void ScriptEditor::initCompleter()
{
QStringList dataWords;
DataSourceManager* dm = m_reportEngine->dataManager();
ScriptEngineManager& se = LimeReport::ScriptEngineManager::instance();
QJSValue globalObject = se.scriptEngine()->globalObject();
QJSValueIterator it(globalObject);
while (it.hasNext()){
it.next();
if (it.value().isCallable() ){
dataWords << it.name();
}
}
foreach(const QString &dsName,dm->dataSourceNames()){
dataWords << dsName;
foreach(const QString &field, dm->fieldNames(dsName)){
dataWords<<dsName+"."+field;
}
}
foreach (QString varName, dm->variableNames()) {
dataWords << varName.remove("#");
}
for ( int i = 0; i < m_reportEngine->pageCount(); ++i){
PageDesignIntf* page = m_reportEngine->pageAt(i);
dataWords << page->pageItem()->objectName();
foreach (BaseDesignIntf* item, page->pageItem()->childBaseItems()){
addItemToCompleater(page->pageItem()->objectName(), item, dataWords);
}
}
m_completer->setModel(new QStringListModel(dataWords,m_completer));
}
void ScriptEditor::addItemToCompleater(const QString& pageName, BaseDesignIntf* item, QStringList& dataWords)
{
BandDesignIntf* band = dynamic_cast<BandDesignIntf*>(item);
if (band){
dataWords << band->objectName();
dataWords << pageName+"_"+band->objectName();
dataWords << pageName+"_"+band->objectName()+".beforeRender";
dataWords << pageName+"_"+item->objectName()+".afterData";
dataWords << pageName+"_"+band->objectName()+".afterRender";
foreach (BaseDesignIntf* child, band->childBaseItems()){
addItemToCompleater(pageName, child, dataWords);
}
} else {
dataWords << item->objectName();
dataWords << pageName+"_"+item->objectName();
dataWords << pageName+"_"+item->objectName()+".beforeRender";
dataWords << pageName+"_"+item->objectName()+".afterData";
dataWords << pageName+"_"+item->objectName()+".afterRender";
}
}
} // namespace LimeReport

View File

@ -0,0 +1,56 @@
#ifndef LRSCRIPTEDITOR_H
#define LRSCRIPTEDITOR_H
#include <QWidget>
#include <QCompleter>
#include <QTextEdit>
#include <QKeyEvent>
#include <QScrollBar>
namespace LimeReport{
class ReportEnginePrivate;
class BaseDesignIntf;
class TextEditorWithCompleater :public QTextEdit
{
Q_OBJECT
public:
TextEditorWithCompleater(QWidget* parent=0);
void setCompleter(QCompleter* value);
QCompleter* compleater() const{ return m_compleater;}
protected:
virtual void keyPressEvent(QKeyEvent *e);
virtual void focusInEvent(QFocusEvent *e);
private:
QString textUnderCursor() const;
private slots:
void insertCompletion(const QString& completion);
private:
QCompleter* m_compleater;
};
namespace Ui {
class ScriptEditor;
}
class ScriptEditor : public QWidget
{
Q_OBJECT
public:
explicit ScriptEditor(QWidget *parent = 0);
~ScriptEditor();
void setReportEngine(ReportEnginePrivate* reportEngine);
void initCompleter();
private:
void addItemToCompleater(const QString& pageName, BaseDesignIntf* item, QStringList& dataWords);
private:
Ui::ScriptEditor *ui;
ReportEnginePrivate* m_reportEngine;
QCompleter* m_completer;
};
} // namespace LimeReport
#endif // LRSCRIPTEDITOR_H

View File

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScriptEditor</class>
<widget class="QWidget" name="ScriptEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>706</width>
<height>541</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Content</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="TextEditorWithCompleater" name="textEdit">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Data</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QTreeView" name="twData">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Functions</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QTreeView" name="twScriptEngine">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
<widget class="QLabel" name="lblDescription">
<property name="text">
<string/>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>TextEditorWithCompleater</class>
<extends>QTextEdit</extends>
<header>lrscripteditor.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>