Version 1.4 initial commit

This commit is contained in:
Arin Alexander
2016-06-10 19:05:18 +04:00
parent 6a507e5b61
commit fecf863f7c
61 changed files with 2019 additions and 276 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 576 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

View File

@@ -0,0 +1,195 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#include "lrscriptbrowser.h"
#include "ui_lrscriptbrowser.h"
#ifdef HAVE_UI_LOADER
#include <QFileDialog>
#include <QUiLoader>
#endif
#include <QMessageBox>
namespace LimeReport{
ScriptBrowser::ScriptBrowser(QWidget *parent) :
QWidget(parent),
ui(new Ui::ScriptBrowser)
{
ui->setupUi(this);
#ifndef HAVE_UI_LOADER
ui->tpDialogs->setVisible(false);
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tpDialogs));
#endif
}
ScriptBrowser::~ScriptBrowser()
{
delete ui;
}
void ScriptBrowser::setReportEditor(ReportDesignWidget* report)
{
m_report=report;
connect(m_report,SIGNAL(cleared()),this,SLOT(slotClear()));
connect(m_report,SIGNAL(loaded()),this,SLOT(slotUpdate()));
updateFunctionTree();
}
void ScriptBrowser::updateFunctionTree()
{
ScriptEngineManager* sm = reportEditor()->scriptManager();
QMap<QString,QTreeWidgetItem*> categ;
foreach(ScriptFunctionDesc fd, sm->functionsDescriber()){
QString functionCategory = (fd.category!="") ? fd.category : tr("NO CATEGORY");
if (categ.contains(functionCategory)){
QTreeWidgetItem* item = new QTreeWidgetItem(categ.value(fd.category),QStringList(fd.name));
item->setIcon(0,QIcon(":/report/images/function"));
} else {
QTreeWidgetItem* categItem = new QTreeWidgetItem(ui->twFunctions,QStringList(functionCategory));
categItem->setIcon(0,QIcon(":/report/images/folder"));
categ.insert(functionCategory,categItem);
QTreeWidgetItem* item = new QTreeWidgetItem(categItem,QStringList(fd.name));
item->setIcon(0,QIcon(":/report/images/function"));
}
}
}
#ifdef HAVE_UI_LOADER
void ScriptBrowser::fillProperties(QTreeWidgetItem* objectItem, QObject* item){
for(int i=0; i<item->metaObject()->propertyCount(); ++i){
QStringList row;
row<<item->metaObject()->property(i).typeName()<<item->metaObject()->property(i).name();
/*QTreeWidgetItem* propItem = */new QTreeWidgetItem(objectItem,row);
}
}
void ScriptBrowser::fillDialog(QTreeWidgetItem* dialogItem,const QString& description){
QUiLoader loader;
QByteArray baDesc = description.toUtf8();
QBuffer buff(&baDesc);
buff.open(QIODevice::ReadOnly);
QDialog* dialog = dynamic_cast<QDialog*>(loader.load(&buff));
if (dialog){
foreach (QObject* child, dialog->children()) {
if (!child->objectName().isEmpty()){
QStringList row;
row<<child->metaObject()->className()<<child->objectName();
QTreeWidgetItem* item = new QTreeWidgetItem(dialogItem,row);
item->setIcon(0,QIcon(":/scriptbrowser/images/item"));
fillProperties(item,child);
}
}
delete dialog;
}
}
void ScriptBrowser::updateDialogsTree()
{
ui->twDialogs->clear();
ScriptEngineContext* sc = reportEditor()->scriptContext();
foreach(DialogDescriber::Ptr dc, sc->dialogsDescriber()){
QTreeWidgetItem* dialogItem = new QTreeWidgetItem(ui->twDialogs,QStringList(dc->name()));
dialogItem->setIcon(0,QIcon(":/scriptbrowser/images/dialog"));
fillDialog(dialogItem,dc->description());
}
}
#endif
void ScriptBrowser::slotClear()
{
ui->twDialogs->clear();
ui->twFunctions->clear();
}
void ScriptBrowser::slotUpdate()
{
#ifdef HAVE_UI_LOADER
updateDialogsTree();
#endif
updateFunctionTree();
}
#ifdef HAVE_UI_LOADER
void ScriptBrowser::on_tbAddDialog_clicked()
{
QFileDialog fileDialog(this);
if (fileDialog.exec()==QDialog::Accepted){
QStringList fileNames = fileDialog.selectedFiles();
QUiLoader loader;
if (!fileNames.isEmpty()){
foreach (QString fileName, fileNames) {
QFile file(fileName);
file.open(QIODevice::ReadOnly);
if (file.isOpen()){
QWidget* widget = loader.load(&file);
QDialog* dialog = dynamic_cast<QDialog*>(widget);
if (dialog){
if (!m_report->scriptContext()->containsDialog(dialog->objectName())){
file.seek(0);
m_report->scriptContext()->addDialog(dialog->objectName(),file.readAll());
updateDialogsTree();
} else {
QMessageBox::critical(this,tr("Error"),tr("Dialog with name: %1 already exists").arg(dialog->objectName()));
}
} else {
if (widget)
QMessageBox::critical(this,tr("Error"),tr("ui file must cointain QDialog instead QWidget or QMainWindow"));
else
QMessageBox::critical(this,tr("Error"),tr("wrong file format"));
}
if (widget) delete widget;
}
}
}
}
}
void ScriptBrowser::on_tbRunDialog_clicked()
{
if (ui->twDialogs->currentItem()&& ui->twDialogs->currentItem()->parent()==0){
m_report->scriptContext()->previewDialog(ui->twDialogs->currentItem()->text(0));
}
}
void ScriptBrowser::on_tbDeleteDialog_clicked()
{
if (ui->twDialogs->currentItem()&& ui->twDialogs->currentItem()->parent()==0){
m_report->scriptContext()->deleteDialog(ui->twDialogs->currentItem()->text(0));
updateDialogsTree();
}
}
#endif
} //namespace LimeReport

View File

@@ -0,0 +1,77 @@
/***************************************************************************
* This file is part of the Lime Report project *
* Copyright (C) 2015 by Alexander Arin *
* arin_a@bk.ru *
* *
** GNU General Public License Usage **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
** GNU Lesser General Public License **
* *
* This library is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
****************************************************************************/
#ifndef LRSCRIPTBROWSER_H
#define LRSCRIPTBROWSER_H
#include <QWidget>
#include <QMainWindow>
#include <QTreeWidgetItem>
#include "lrreportdesignwidget.h"
namespace LimeReport{
namespace Ui {
class ScriptBrowser;
}
class ScriptBrowser : public QWidget
{
Q_OBJECT
public:
explicit ScriptBrowser(QWidget *parent = 0);
~ScriptBrowser();
void setReportEditor(LimeReport::ReportDesignWidget* report);
inline ReportDesignWidget* reportEditor(){return m_report;}
void updateFunctionTree();
#ifdef HAVE_UI_LOADER
void updateDialogsTree();
#endif
protected:
#ifdef HAVE_UI_LOADER
void fillDialog(QTreeWidgetItem *dialogItem, const QString &description);
void fillProperties(QTreeWidgetItem *objectItem, QObject *item);
#endif
private slots:
void slotClear();
void slotUpdate();
#ifdef HAVE_UI_LOADER
void on_tbAddDialog_clicked();
void on_tbRunDialog_clicked();
void on_tbDeleteDialog_clicked();
#endif
private:
Ui::ScriptBrowser *ui;
ReportDesignWidget* m_report;
};
} // namespace LimeReport
#endif // LRSCRIPTBROWSER_H

View File

@@ -0,0 +1,14 @@
<RCC>
<qresource prefix="/scriptbrowser">
<file alias="/images/dialog">images/Dialog.png</file>
<file alias="/images/dialog_add">images/Dialog_add.png</file>
<file alias="/images/dialog_delete">images/Dialog_delete.png</file>
<file alias="/images/dialog_run">images/Dialog_run.png</file>
<file alias="/images/function">images/function3.png</file>
<file alias="/images/function_add">images/function_add.png</file>
<file alias="/images/function_delete">images/function_delete.png</file>
<file alias="/images/function_edit">images/function_edit.png</file>
<file>images/green_cube.png</file>
<file alias="/images/item">images/green_cube1.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,287 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LimeReport::ScriptBrowser</class>
<widget class="QWidget" name="LimeReport::ScriptBrowser">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="tabPosition">
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tpFunctions">
<attribute name="title">
<string>Functions</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<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>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_2">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrscriptbrowser.qrc">
<normaloff>:/scriptbrowser/images/function_add</normaloff>:/scriptbrowser/images/function_add</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrscriptbrowser.qrc">
<normaloff>:/scriptbrowser/images/function_edit</normaloff>:/scriptbrowser/images/function_edit</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_3">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrscriptbrowser.qrc">
<normaloff>:/scriptbrowser/images/function_delete</normaloff>:/scriptbrowser/images/function_delete</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTreeWidget" name="twFunctions">
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tpDialogs">
<attribute name="title">
<string>Dialogs</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<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>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="tbAddDialog">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrscriptbrowser.qrc">
<normaloff>:/scriptbrowser/images/dialog_add</normaloff>:/scriptbrowser/images/dialog_add</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tbRunDialog">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrscriptbrowser.qrc">
<normaloff>:/scriptbrowser/images/dialog_run</normaloff>:/scriptbrowser/images/dialog_run</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tbDeleteDialog">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="lrscriptbrowser.qrc">
<normaloff>:/scriptbrowser/images/dialog_delete</normaloff>:/scriptbrowser/images/dialog_delete</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QTreeWidget" name="twDialogs">
<property name="columnCount">
<number>2</number>
</property>
<attribute name="headerDefaultSectionSize">
<number>131</number>
</attribute>
<attribute name="headerMinimumSectionSize">
<number>100</number>
</attribute>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="lrscriptbrowser.qrc"/>
</resources>
<connections/>
</ui>