This commit is contained in:
Sergey Popovichev 2016-02-17 10:19:50 +03:00
parent 81d855f52c
commit 0a16bed249
55 changed files with 906 additions and 193 deletions

BIN
demo/r1/lr1.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

BIN
demo/r1/lr6.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 KiB

View File

@ -65,7 +65,8 @@ MainWindow::MainWindow(QWidget *parent) :
m_customers->first(); m_customers->first();
m_orders = new QSqlQuery(m_db); m_orders = new QSqlQuery(m_db);
m_orders->prepare("Select * from orders where CustomerID = :id"); m_orders->prepare("Select * from orders where CustomerID = :id");
m_orders->bindValue(":id",m_customers->value("CustomerID")); int index = m_customers->record().indexOf("CustomerID");
m_orders->bindValue(":id",m_customers->value(index));
m_orders->exec(); m_orders->exec();
}; };
} }
@ -160,7 +161,7 @@ void MainWindow::prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVari
data = ds->record().fieldName(info.index); data = ds->record().fieldName(info.index);
break; break;
case LimeReport::CallbackInfo::ColumnData: case LimeReport::CallbackInfo::ColumnData:
data = ds->value(info.columnName); data = ds->value(ds->record().indexOf(info.columnName));
break; break;
} }
} }
@ -177,7 +178,7 @@ void MainWindow::slotChangePos(const LimeReport::CallbackInfo::ChangePosType &ty
if (!ds) return; if (!ds) return;
if (type == LimeReport::CallbackInfo::First) result = ds->first(); if (type == LimeReport::CallbackInfo::First) result = ds->first();
else result = ds->next(); else result = ds->next();
m_orders->bindValue(":id",m_customers->value("CustomerID")); m_orders->bindValue(":id",m_customers->value(m_customers->record().indexOf("CustomerID")));
m_orders->exec(); m_orders->exec();
} }

View File

@ -42,19 +42,29 @@
#endif #endif
namespace LimeReport { namespace LimeReport {
namespace Const{
int const RESIZE_HANDLE_SIZE = 10;
int const SELECTION_PEN_SIZE = 4;
int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE;
int const MINIMUM_ITEM_HEIGHT = 2*RESIZE_HANDLE_SIZE;
double const RESIZE_ZONE_OPACITY = 0.5;
double const SELECTED_RESIZE_ZONE_OPACITY = 0.6;
Qt::GlobalColor const RESIZE_ZONE_COLOR = Qt::green;
Qt::GlobalColor const SELECTION_COLOR = Qt::red;
double const SELECTION_COLOR_OPACITY = 0.9;
const qreal fontFACTOR = 3.5; const qreal fontFACTOR = 3.5;
const int mmFACTOR = 10; const int mmFACTOR = 10;
const int itemPaleteIconSize = 24; const int itemPaleteIconSize = 24;
const qreal minSpaceBorder = 10; const qreal minSpaceBorder = 10;
QString extractClassName(QString className);
const QString bandTAG = "band"; const QString bandTAG = "band";
const Qt::GlobalColor BAND_NAME_LABEL_COLOR = Qt::yellow;
const Qt::GlobalColor BAND_NAME_BORDER_COLOR = Qt::darkYellow;
const qreal BAND_MARKER_OPACITY = 1; const qreal BAND_MARKER_OPACITY = 1;
const qreal LAYOUT_MARKER_OPACITY = 0.3; const qreal LAYOUT_MARKER_OPACITY = 0.3;
const qreal BAND_NAME_AREA_OPACITY = 0.3; const qreal BAND_NAME_AREA_OPACITY = 0.3;
const qreal BAND_NAME_TEXT_OPACITY = 0.6; const qreal BAND_NAME_TEXT_OPACITY = 0.6;
const qreal SELECTION_OPACITY = 0.3; const qreal SELECTION_OPACITY = 0.3;
enum RenderPass {FirstPass, SecondPass};
enum ArrangeType {AsNeeded, Force};
const QString FIELD_RX = "\\$D\\s*\\{\\s*([^\\s{}]*)\\s*\\}"; const QString FIELD_RX = "\\$D\\s*\\{\\s*([^\\s{}]*)\\s*\\}";
const QString VARIABLE_RX = "\\$V\\s*\\{\\s*([^\\s{}]*)\\s*\\}"; const QString VARIABLE_RX = "\\$V\\s*\\{\\s*([^\\s{}]*)\\s*\\}";
const QString SCRIPT_RX = "\\$S\\s*\\{(.*)\\}"; const QString SCRIPT_RX = "\\$S\\s*\\{(.*)\\}";
@ -64,6 +74,10 @@ namespace LimeReport {
const QString GROUP_FUNCTION_RX = "(%1\\s*"+GROUP_FUNCTION_PARAM_RX+")"; const QString GROUP_FUNCTION_RX = "(%1\\s*"+GROUP_FUNCTION_PARAM_RX+")";
const QString GROUP_FUNCTION_NAME_RX = "%1\\s*\\((.*[^\\)])\\)"; const QString GROUP_FUNCTION_NAME_RX = "%1\\s*\\((.*[^\\)])\\)";
const int SCENE_MARGIN = 50; const int SCENE_MARGIN = 50;
}
QString extractClassName(QString className);
enum RenderPass {FirstPass, SecondPass};
enum ArrangeType {AsNeeded, Force};
class ReportError : public std::runtime_error{ class ReportError : public std::runtime_error{
public: public:
ReportError(const QString& message):std::runtime_error(message.toStdString()){} ReportError(const QString& message):std::runtime_error(message.toStdString()){}

View File

@ -37,13 +37,11 @@
#include "lrglobal.h" #include "lrglobal.h"
#include "lrdatasourcemanagerintf.h" #include "lrdatasourcemanagerintf.h"
#include "lrscriptenginemanagerintf.h" #include "lrscriptenginemanagerintf.h"
//#include "lrreportrender.h"
class QPrinter; class QPrinter;
namespace LimeReport { namespace LimeReport {
class PrintRange{ class PrintRange{
public: public:
int fromPage() const { return m_fromPage;} int fromPage() const { return m_fromPage;}
@ -61,7 +59,6 @@ private:
class DataSourceManager; class DataSourceManager;
class ReportEnginePrivate; class ReportEnginePrivate;
//class PageDesignIntf;
class LIMEREPORT_EXPORT ReportEngine : public QObject{ class LIMEREPORT_EXPORT ReportEngine : public QObject{
Q_OBJECT Q_OBJECT
@ -71,9 +68,8 @@ public:
explicit ReportEngine(QObject *parent = 0); explicit ReportEngine(QObject *parent = 0);
~ReportEngine(); ~ReportEngine();
bool printReport(QPrinter *printer=0); bool printReport(QPrinter *printer=0);
//void printReport(ReportPages pages, QPrinter &printer);
void printToFile(const QString& fileName); void printToFile(const QString& fileName);
//PageDesignIntf *createPreviewScene(QObject *parent = 0); bool printToPDF(const QString& fileName);
void previewReport(); void previewReport();
void designReport(); void designReport();
void setShowProgressDialog(bool value); void setShowProgressDialog(bool value);

View File

@ -1,5 +1,5 @@
#CONFIG +=zint #CONFIG +=zint
QMAKE_CFLAGS += -std=c99 #QMAKE_CFLAGS += -std=c99
#ZINT_PATH = $$PWD/../zint-2.4.3 #ZINT_PATH = $$PWD/../zint-2.4.3
#ZINT_VERSION = 2.4.3 #ZINT_VERSION = 2.4.3
#include(qzint.pri) #include(qzint.pri)

View File

@ -2,7 +2,7 @@ QT += script xml sql
REPORT_PATH = $$PWD REPORT_PATH = $$PWD
LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MAJOR = 1
LIMEREPORT_VERSION_MINOR = 0 LIMEREPORT_VERSION_MINOR = 3
LIMEREPORT_VERSION_RELEASE = 1 LIMEREPORT_VERSION_RELEASE = 1
LIMEREPORT_VERSION = '\\"$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}\\"' LIMEREPORT_VERSION = '\\"$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}\\"'

View File

@ -49,17 +49,17 @@ LimeReport::BaseDesignIntf * createFooter(QObject* owner, LimeReport::BaseDesign
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator( bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTag, xmlTag,
LimeReport::ItemAttribs(QObject::tr("Data"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("Data"),LimeReport::Const::bandTAG),
createBand createBand
); );
bool registredHeader = LimeReport::DesignElementsFactory::instance().registerCreator( bool registredHeader = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTagHeader, xmlTagHeader,
LimeReport::ItemAttribs(QObject::tr("DataHeader"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("DataHeader"),LimeReport::Const::bandTAG),
createHeader createHeader
); );
bool registredFooter = LimeReport::DesignElementsFactory::instance().registerCreator( bool registredFooter = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTagFooter, xmlTagFooter,
LimeReport::ItemAttribs(QObject::tr("DataFooter"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("DataFooter"),LimeReport::Const::bandTAG),
createFooter createFooter
); );

View File

@ -43,7 +43,7 @@ LimeReport::BaseDesignIntf* createHeader(QObject* owner, LimeReport::BaseDesignI
bool registredHeader = LimeReport::DesignElementsFactory::instance().registerCreator( bool registredHeader = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTagHeader, xmlTagHeader,
LimeReport::ItemAttribs(QObject::tr("GroupHeader"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("GroupHeader"),LimeReport::Const::bandTAG),
createHeader createHeader
); );
@ -53,7 +53,7 @@ LimeReport::BaseDesignIntf * createFooter(QObject* owner, LimeReport::BaseDesign
bool registredFooter = LimeReport::DesignElementsFactory::instance().registerCreator( bool registredFooter = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTagFooter, xmlTagFooter,
LimeReport::ItemAttribs(QObject::tr("GroupFooter"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("GroupFooter"),LimeReport::Const::bandTAG),
createFooter createFooter
); );

View File

@ -40,7 +40,7 @@ LimeReport::BaseDesignIntf * createBand(QObject* owner, LimeReport::BaseDesignIn
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator( bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTag, xmlTag,
LimeReport::ItemAttribs(QObject::tr("Page Footer"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("Page Footer"),LimeReport::Const::bandTAG),
createBand createBand
); );
} }

View File

@ -44,7 +44,7 @@ LimeReport::BaseDesignIntf * createBand(QObject* owner, LimeReport::BaseDesignIn
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator( bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTag, xmlTag,
LimeReport::ItemAttribs(QObject::tr("Page Header"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("Page Header"),LimeReport::Const::bandTAG),
createBand createBand
); );
} }

View File

@ -40,7 +40,7 @@ LimeReport::BaseDesignIntf * createBand(QObject* owner, LimeReport::BaseDesignIn
} }
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator( bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTag, xmlTag,
LimeReport::ItemAttribs(QObject::tr("Report Footer"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("Report Footer"),LimeReport::Const::bandTAG),
createBand createBand
); );
} }

View File

@ -39,7 +39,7 @@ LimeReport::BaseDesignIntf * createBand(QObject* owner, LimeReport::BaseDesignIn
} }
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator( bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTag, xmlTag,
LimeReport::ItemAttribs(QObject::tr("Report Header"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("Report Header"),LimeReport::Const::bandTAG),
createBand createBand
); );
} }

View File

@ -45,7 +45,7 @@ LimeReport::BaseDesignIntf * createBand(QObject* owner, LimeReport::BaseDesignIn
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator( bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTagBand, xmlTagBand,
LimeReport::ItemAttribs(QObject::tr("SubDetail"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("SubDetail"),LimeReport::Const::bandTAG),
createBand createBand
); );
@ -55,7 +55,7 @@ LimeReport::BaseDesignIntf * createHeader(QObject* owner, LimeReport::BaseDesign
bool registredHeader = LimeReport::DesignElementsFactory::instance().registerCreator( bool registredHeader = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTagHeader, xmlTagHeader,
LimeReport::ItemAttribs(QObject::tr("SubDetailHeader"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("SubDetailHeader"),LimeReport::Const::bandTAG),
createHeader createHeader
); );
@ -65,7 +65,7 @@ LimeReport::BaseDesignIntf * createFooter(QObject* owner, LimeReport::BaseDesign
bool registredFooter = LimeReport::DesignElementsFactory::instance().registerCreator( bool registredFooter = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTagFooter, xmlTagFooter,
LimeReport::ItemAttribs(QObject::tr("SubDetailFooter"),LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("SubDetailFooter"),LimeReport::Const::bandTAG),
createFooter createFooter
); );

View File

@ -192,7 +192,7 @@ void DataBrowser::updateDataTree()
} else item->setIcon(0,QIcon(":/databrowser/images/table_error")); } else item->setIcon(0,QIcon(":/databrowser/images/table_error"));
} catch(ReportError& exception) { } catch(ReportError& /*exception*/) {
item->setIcon(0,QIcon(":/databrowser/images/table_error")); item->setIcon(0,QIcon(":/databrowser/images/table_error"));
//qDebug()<<exception.what(); //qDebug()<<exception.what();
} }
@ -414,6 +414,8 @@ QDockWidget *DataBrowser::createDataWindow(QString datasourceName)
//TODO: exception or message ? //TODO: exception or message ?
try { try {
IDataSourceHolder* holder = m_report->dataManager()->dataSourceHolder(datasourceName);
if (holder) holder->update();
IDataSource* datasource = m_report->dataManager()->dataSource(datasourceName); IDataSource* datasource = m_report->dataManager()->dataSource(datasourceName);
if (datasource){ if (datasource){
tableView->setModel(datasource->model()); tableView->setModel(datasource->model());
@ -594,6 +596,7 @@ void DataBrowser::addConnectionDesc(ConnectionDesc *connection)
void DataBrowser::changeConnectionDesc(ConnectionDesc *connection) void DataBrowser::changeConnectionDesc(ConnectionDesc *connection)
{ {
Q_UNUSED(connection) Q_UNUSED(connection)
if (connection->autoconnect()) m_report->dataManager()->connectConnection(connection->name());
updateDataTree(); updateDataTree();
} }

View File

@ -38,10 +38,10 @@ QMimeData *DataBrowserTree::mimeData(const QList<QTreeWidgetItem *> items) const
{ {
QMimeData* result = QTreeWidget::mimeData(items); QMimeData* result = QTreeWidget::mimeData(items);
if (items.at(0)->type()==Row){ if (items.at(0)->type()==Row){
result->setText("$D{"+items.at(0)->parent()->text(0)+"."+items.at(0)->data(0,Qt::DisplayRole).toString()+"}"); result->setText("field:$D{"+items.at(0)->parent()->text(0)+"."+items.at(0)->data(0,Qt::DisplayRole).toString()+"}");
} }
if (items.at(0)->type()==Variable){ if (items.at(0)->type()==Variable){
result->setText("$V{"+items.at(0)->text(0)+"}"); result->setText("variable:$V{"+items.at(0)->text(0)+"}");
} }
return result; return result;
} }

View File

@ -296,7 +296,7 @@ void SQLEditDialog::slotPreviewData()
QMessageBox::critical(this,tr("Attention"),tr("Connection is not specified")); QMessageBox::critical(this,tr("Attention"),tr("Connection is not specified"));
return; return;
} }
m_previewModel = m_datasources->previewSQL(ui->cbbConnection->currentText(),ui->textEditSQL->toPlainText()); m_previewModel = m_datasources->previewSQL(ui->cbbConnection->currentText(),ui->textEditSQL->toPlainText(),ui->leMaster->text());
if (m_previewModel){ if (m_previewModel){
ui->tvPreview->setModel(m_previewModel.data()); ui->tvPreview->setModel(m_previewModel.data());
ui->gbDataPreview->setVisible(true); ui->gbDataPreview->setVisible(true);

BIN
src/images/PDF1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
src/images/PDF2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
src/images/empty.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

View File

@ -73,7 +73,7 @@ void BarcodeItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *opti
bc.setSecurityLevel(m_securityLevel); bc.setSecurityLevel(m_securityLevel);
bc.setPdf417CodeWords(m_pdf417CodeWords); bc.setPdf417CodeWords(m_pdf417CodeWords);
if (isSelected()) ppainter->setOpacity(SELECTION_OPACITY); if (isSelected()) ppainter->setOpacity(Const::SELECTION_OPACITY);
QRectF bcRect; QRectF bcRect;

View File

@ -47,7 +47,7 @@ LimeReport::BaseDesignIntf *createHLayout(QObject *owner, LimeReport::BaseDesign
} }
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator( bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTag, xmlTag,
LimeReport::ItemAttribs(QObject::tr("HLayout"), LimeReport::bandTAG), LimeReport::ItemAttribs(QObject::tr("HLayout"), LimeReport::Const::bandTAG),
createHLayout createHLayout
); );
} }
@ -376,7 +376,7 @@ LayoutMarker::LayoutMarker(HorizontalLayout *layout, QGraphicsItem *parent)
void LayoutMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) void LayoutMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{ {
painter->save(); painter->save();
painter->setOpacity(LAYOUT_MARKER_OPACITY); painter->setOpacity(Const::LAYOUT_MARKER_OPACITY);
painter->fillRect(boundingRect(),m_color); painter->fillRect(boundingRect(),m_color);
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);

View File

@ -185,7 +185,7 @@ void ImageItem::setDatasource(const QString &datasource)
void ImageItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget) void ImageItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
ppainter->save(); ppainter->save();
if (isSelected()) ppainter->setOpacity(SELECTION_OPACITY); if (isSelected()) ppainter->setOpacity(Const::SELECTION_OPACITY);
else ppainter->setOpacity(qreal(opacity())/100); else ppainter->setOpacity(qreal(opacity())/100);
QPointF point = rect().topLeft(); QPointF point = rect().topLeft();

View File

@ -70,6 +70,7 @@ protected:
BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent); BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
void updateItemSize(RenderPass, int); void updateItemSize(RenderPass, int);
bool isNeedUpdateSize(RenderPass) const; bool isNeedUpdateSize(RenderPass) const;
bool drawDesignBorders() const {return m_picture.isNull();}
private: private:
QImage m_picture; QImage m_picture;
QString m_content; QString m_content;

View File

@ -64,7 +64,8 @@ public:
void setOpacity(int opacity); void setOpacity(int opacity);
protected: protected:
virtual BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent); BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
bool drawDesignBorders() const {return false;}
private: private:
ShapeType m_shape; ShapeType m_shape;
QColor m_shapeColor; QColor m_shapeColor;

View File

@ -47,7 +47,7 @@ QRectF BandMarker::boundingRect() const
void BandMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem* /**option*/, QWidget* /*widget*/) void BandMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem* /**option*/, QWidget* /*widget*/)
{ {
painter->save(); painter->save();
painter->setOpacity(BAND_MARKER_OPACITY); painter->setOpacity(Const::BAND_MARKER_OPACITY);
painter->fillRect(boundingRect(),m_color); painter->fillRect(boundingRect(),m_color);
painter->setOpacity(1); painter->setOpacity(1);
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
@ -155,6 +155,10 @@ BandDesignIntf::BandDesignIntf(BandsType bandType, const QString &xmlTypeName, Q
m_bandMarker->setHeight(height()); m_bandMarker->setHeight(height());
m_bandMarker->setPos(pos().x()-m_bandMarker->width(),pos().y()); m_bandMarker->setPos(pos().x()-m_bandMarker->width(),pos().y());
if (scene()) scene()->addItem(m_bandMarker); if (scene()) scene()->addItem(m_bandMarker);
m_bandNameLabel = new BandNameLabel(this);
m_bandNameLabel->setVisible(false);
if (scene()) scene()->addItem(m_bandNameLabel);
} }
BandDesignIntf::~BandDesignIntf() BandDesignIntf::~BandDesignIntf()
@ -169,6 +173,9 @@ BandDesignIntf::~BandDesignIntf()
if (m_bandMarker) { if (m_bandMarker) {
delete m_bandMarker; delete m_bandMarker;
} }
if (m_bandNameLabel){
delete m_bandNameLabel;
}
} }
void BandDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget) void BandDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget)
@ -180,7 +187,7 @@ void BandDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *o
ppainter->save(); ppainter->save();
QString bandText = objectName(); QString bandText = objectName();
if (parentBand()) bandText+=QLatin1String(" connected to ")+parentBand()->objectName(); if (parentBand()) bandText+=QLatin1String(" connected to ")+parentBand()->objectName();
QFont font("Arial",7*fontFACTOR,-1,true); QFont font("Arial",7*Const::fontFACTOR,-1,true);
QFontMetrics fontMetrics(font); QFontMetrics fontMetrics(font);
QVector<QRectF> bandNameRects; QVector<QRectF> bandNameRects;
@ -195,14 +202,14 @@ void BandDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *o
ppainter->setFont(font); ppainter->setFont(font);
for (int i=0;i<bandNameRects.count();i++){ for (int i=0;i<bandNameRects.count();i++){
QRectF labelRect = bandNameRects[i].adjusted(-2,-2,2,2); QRectF labelRect = bandNameRects[i].adjusted(-2,-2,2,2);
if ((labelRect.height())<height()){ if ((labelRect.height())<height() && (childBaseItems().isEmpty()) && !isSelected()){
ppainter->setRenderHint(QPainter::Antialiasing); ppainter->setRenderHint(QPainter::Antialiasing);
ppainter->setBrush(bandColor()); ppainter->setBrush(bandColor());
ppainter->setOpacity(BAND_NAME_AREA_OPACITY); ppainter->setOpacity(Const::BAND_NAME_AREA_OPACITY);
ppainter->drawRoundedRect(labelRect,8,8); ppainter->drawRoundedRect(labelRect,8,8);
ppainter->setOpacity(BAND_NAME_TEXT_OPACITY); ppainter->setOpacity(Const::BAND_NAME_TEXT_OPACITY);
ppainter->setPen(Qt::black); ppainter->setPen(Qt::black);
ppainter->drawText(bandNameRects[i]," "+bandText+" "); ppainter->drawText(bandNameRects[i],Qt::AlignHCenter,bandText);
} }
} }
ppainter->restore(); ppainter->restore();
@ -217,7 +224,9 @@ BandDesignIntf::BandsType BandDesignIntf::bandType() const
QString BandDesignIntf::bandTitle() const QString BandDesignIntf::bandTitle() const
{ {
return m_bandTypeText; QString result = objectName();
if (parentBand()) result +=tr(" connected to ")+parentBand()->objectName();
return result;
} }
QIcon BandDesignIntf::bandIcon() const QIcon BandDesignIntf::bandIcon() const
@ -323,7 +332,7 @@ bool BandDesignIntf::canBeSplitted(int height) const
if ((item->minHeight()>height) && (item->minHeight()>(this->height()-height))) return false; if ((item->minHeight()>height) && (item->minHeight()>(this->height()-height))) return false;
} }
} }
return true; return isSplittable();
} }
bool BandDesignIntf::isEmpty() const bool BandDesignIntf::isEmpty() const
@ -561,6 +570,11 @@ void BandDesignIntf::trimToMaxHeight(int maxHeight)
} }
} }
void BandDesignIntf::setBandTypeText(const QString &value){
m_bandTypeText=value;
m_bandNameLabel->updateLabel();
}
QSet<BandDesignIntf::BandsType> BandDesignIntf::groupBands() QSet<BandDesignIntf::BandsType> BandDesignIntf::groupBands()
{ {
QSet<BandDesignIntf::BandsType> result; QSet<BandDesignIntf::BandsType> result;
@ -611,6 +625,9 @@ QVariant BandDesignIntf::itemChange(QGraphicsItem::GraphicsItemChange change, co
m_bandMarker->update(0,0, m_bandMarker->update(0,0,
m_bandMarker->boundingRect().width(), m_bandMarker->boundingRect().width(),
m_bandMarker->boundingRect().width()); m_bandMarker->boundingRect().width());
m_bandNameLabel->updateLabel();
m_bandNameLabel->setVisible(value.toBool());
} }
} }
return BaseDesignIntf::itemChange(change,value); return BaseDesignIntf::itemChange(change,value);
@ -720,6 +737,52 @@ DataBandDesignIntf::DataBandDesignIntf(BandDesignIntf::BandsType bandType, QStri
{ {
} }
BandNameLabel::BandNameLabel(BandDesignIntf *band, QGraphicsItem *parent)
:QGraphicsItem(parent),m_rect(5,5,30,30),m_band(band)
{
setAcceptHoverEvents(true);
}
void BandNameLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setFont(QFont("Arial",7*Const::fontFACTOR,-1,true));
painter->setOpacity(1);
QPen pen(Const::BAND_NAME_BORDER_COLOR);
pen.setWidth(2);
painter->setBrush(Qt::yellow);
painter->setPen(pen);
painter->drawRect(m_rect);
painter->setOpacity(0.8);
painter->setPen(Qt::black);
painter->drawText(m_rect,Qt::AlignCenter,m_band->bandTitle());
Q_UNUSED(option)
Q_UNUSED(widget)
}
QRectF BandNameLabel::boundingRect() const
{
return m_rect;
}
void BandNameLabel::updateLabel()
{
QFont font("Arial",7*Const::fontFACTOR,-1,true);
QFontMetrics fontMetrics(font);
prepareGeometryChange();
m_rect = QRectF(
m_band->pos().x()+10,
m_band->pos().y()-(fontMetrics.height()+10),
fontMetrics.width(m_band->bandTitle())+20,fontMetrics.height()+10
);
update();
}
void BandNameLabel::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
setVisible(false);
Q_UNUSED(event)
}
} }

View File

@ -50,8 +50,8 @@ class BandDesignIntf;
class BandMarker : public QGraphicsItem{ class BandMarker : public QGraphicsItem{
public: public:
explicit BandMarker(BandDesignIntf* band, QGraphicsItem *parent=0); explicit BandMarker(BandDesignIntf* band, QGraphicsItem *parent=0);
virtual QRectF boundingRect() const; QRectF boundingRect() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
void setHeight(qreal height); void setHeight(qreal height);
void setWidth(qreal width); void setWidth(qreal width);
void setColor(QColor color); void setColor(QColor color);
@ -65,6 +65,19 @@ private:
BandDesignIntf* m_band; BandDesignIntf* m_band;
}; };
class BandNameLabel : public QGraphicsItem{
public:
explicit BandNameLabel(BandDesignIntf* band, QGraphicsItem* parent=0);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const;
void updateLabel();
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
private:
QRectF m_rect;
QColor m_color;
BandDesignIntf* m_band;
};
struct ItemSortContainer; struct ItemSortContainer;
typedef QSharedPointer< ItemSortContainer > PItemSortContainer; typedef QSharedPointer< ItemSortContainer > PItemSortContainer;
class BandDesignIntf : public BaseDesignIntf class BandDesignIntf : public BaseDesignIntf
@ -77,6 +90,7 @@ class BandDesignIntf : public BaseDesignIntf
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
Q_PROPERTY(bool printIfEmpty READ printIfEmpty WRITE setPrintIfEmpty) Q_PROPERTY(bool printIfEmpty READ printIfEmpty WRITE setPrintIfEmpty)
friend class BandMarker; friend class BandMarker;
friend class BandNameLabel;
public: public:
enum BandsType { enum BandsType {
@ -180,7 +194,7 @@ protected:
void setAutoHeight(bool value){m_autoHeight=value;} void setAutoHeight(bool value){m_autoHeight=value;}
bool autoHeight(){return m_autoHeight;} bool autoHeight(){return m_autoHeight;}
void setBandTypeText(const QString& value){m_bandTypeText=value;} void setBandTypeText(const QString& value);
QString bandTypeText(){return m_bandTypeText;} QString bandTypeText(){return m_bandTypeText;}
virtual void moveDown(){} virtual void moveDown(){}
virtual void moveUp(){} virtual void moveUp(){}
@ -213,6 +227,7 @@ private:
int m_maxScalePercent; int m_maxScalePercent;
bool m_sliceLastRow; bool m_sliceLastRow;
bool m_printIfEmpty; bool m_printIfEmpty;
BandNameLabel* m_bandNameLabel;
}; };
class DataBandDesignIntf : public BandDesignIntf{ class DataBandDesignIntf : public BandDesignIntf{

View File

@ -49,7 +49,7 @@ QStringList BandsManager::bandNames()
<<QObject::tr("Data")<<QObject::tr("SubDetail"); <<QObject::tr("Data")<<QObject::tr("SubDetail");
foreach(ItemAttribs attr,LimeReport::DesignElementsFactory::instance().attribsMap().values()){ foreach(ItemAttribs attr,LimeReport::DesignElementsFactory::instance().attribsMap().values()){
if ((attr.m_tag==LimeReport::bandTAG)&&(!bandsList.contains(attr.m_alias))) if ((attr.m_tag==LimeReport::Const::bandTAG)&&(!bandsList.contains(attr.m_alias)))
bandsList.append(attr.m_alias); bandsList.append(attr.m_alias);
} }
@ -58,7 +58,7 @@ QStringList BandsManager::bandNames()
BandDesignIntf* BandsManager::createBand(const QString &type, QObject *owner, LimeReport::BaseDesignIntf *parent) BandDesignIntf* BandsManager::createBand(const QString &type, QObject *owner, LimeReport::BaseDesignIntf *parent)
{ {
QString identity = LimeReport::DesignElementsFactory::instance().attribsMap().key(LimeReport::ItemAttribs(type,LimeReport::bandTAG)); QString identity = LimeReport::DesignElementsFactory::instance().attribsMap().key(LimeReport::ItemAttribs(type,LimeReport::Const::bandTAG));
return dynamic_cast<LimeReport::BandDesignIntf*>(LimeReport::DesignElementsFactory::instance().objectCreator(identity)(owner,parent)); return dynamic_cast<LimeReport::BandDesignIntf*>(LimeReport::DesignElementsFactory::instance().objectCreator(identity)(owner,parent));
} }

View File

@ -50,15 +50,15 @@ namespace LimeReport
BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, QGraphicsItem *parent) : BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, QGraphicsItem *parent) :
QObject(owner), QGraphicsItem(parent), QObject(owner), QGraphicsItem(parent),
m_resizeHandleSize(Consts::RESIZE_HANDLE_SIZE), m_resizeHandleSize(Const::RESIZE_HANDLE_SIZE),
m_selectionPenSize(Consts::SELECTION_PEN_SIZE), m_selectionPenSize(Const::SELECTION_PEN_SIZE),
m_posibleResizeDirectionFlags(ResizeTop | ResizeBottom | ResizeLeft | ResizeRight), m_posibleResizeDirectionFlags(ResizeTop | ResizeBottom | ResizeLeft | ResizeRight),
m_posibleMoveDirectionFlags(All), m_posibleMoveDirectionFlags(All),
m_resizeDirectionFlags(0), m_resizeDirectionFlags(0),
m_width(200), m_width(200),
m_height(50), m_height(50),
m_fontColor(Qt::black), m_fontColor(Qt::black),
m_mmFactor(mmFACTOR), m_mmFactor(Const::mmFACTOR),
m_fixedPos(false), m_fixedPos(false),
m_BGMode(OpaqueMode), m_BGMode(OpaqueMode),
m_opacity(100), m_opacity(100),
@ -80,7 +80,7 @@ BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, Q
} }
initFlags(); initFlags();
m_selectionMarker = new SelectionMarker(this); m_selectionMarker = new SelectionMarker(this);
m_selectionMarker->setColor(Consts::SELECTION_COLOR); m_selectionMarker->setColor(Const::SELECTION_COLOR);
m_selectionMarker->setVisible(false); m_selectionMarker->setVisible(false);
//connect(this,SIGNAL(objectNameChanged(QString)),this,SLOT(slotObjectNameChanged(QString))); //connect(this,SIGNAL(objectNameChanged(QString)),this,SLOT(slotObjectNameChanged(QString)));
} }
@ -184,7 +184,7 @@ void BaseDesignIntf::setHeight(qreal height)
QFont BaseDesignIntf::transformToSceneFont(const QFont& value) const QFont BaseDesignIntf::transformToSceneFont(const QFont& value) const
{ {
QFont f = value; QFont f = value;
f.setPixelSize(f.pointSize()*fontFACTOR); f.setPixelSize(f.pointSize()*Const::fontFACTOR);
return f; return f;
} }
@ -304,6 +304,18 @@ void BaseDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *o
drawResizeZone(ppainter); drawResizeZone(ppainter);
} }
QColor calcColor(QColor color){
int R = color.red();
int G = color.green();
int B = color.blue();
if (0.222*R + 0.707*G + 0.071*B <= 127)
return Qt::white;
else
return Qt::black;
};
void BaseDesignIntf::prepareRect(QPainter *ppainter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) void BaseDesignIntf::prepareRect(QPainter *ppainter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{ {
ppainter->save(); ppainter->save();
@ -314,6 +326,9 @@ void BaseDesignIntf::prepareRect(QPainter *ppainter, const QStyleOptionGraphicsI
if (m_BGMode == OpaqueMode) { if (m_BGMode == OpaqueMode) {
ppainter->setOpacity(qreal(m_opacity) / 100); ppainter->setOpacity(qreal(m_opacity) / 100);
ppainter->fillRect(rect(), QBrush(m_backgroundBrushcolor)); ppainter->fillRect(rect(), QBrush(m_backgroundBrushcolor));
} else if (itemMode() & DesignMode){
ppainter->setOpacity(0.1);
ppainter->fillRect(rect(), QBrush(QPixmap(":/report/empty")));
} }
} }
ppainter->restore(); ppainter->restore();
@ -353,8 +368,8 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if (m_resizeDirectionFlags & ResizeLeft) { if (m_resizeDirectionFlags & ResizeLeft) {
if ((event->scenePos().x()) <= (mapToScene(0, 0).x() + (width() - Consts::MINIMUM_ITEM_WIDTH)) && if ((event->scenePos().x()) <= (mapToScene(0, 0).x() + (width() - Const::MINIMUM_ITEM_WIDTH)) &&
(width() + (event->lastScenePos().x() - event->scenePos().x()) > Consts::MINIMUM_ITEM_WIDTH) (width() + (event->lastScenePos().x() - event->scenePos().x()) > Const::MINIMUM_ITEM_WIDTH)
) { ) {
qreal posRightConner = mapToScene(0, 0).x() + width(); qreal posRightConner = mapToScene(0, 0).x() + width();
setItemPos(mapToParent(mapFromScene(div(event->scenePos().x(), 2).quot * 2, y())).x(), y()); setItemPos(mapToParent(mapFromScene(div(event->scenePos().x(), 2).quot * 2, y())).x(), y());
@ -363,7 +378,7 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
} }
if (m_resizeDirectionFlags & ResizeRight) { if (m_resizeDirectionFlags & ResizeRight) {
if ((event->scenePos().x() >= (mapToScene(0, 0).x() + Consts::MINIMUM_ITEM_WIDTH)) || if ((event->scenePos().x() >= (mapToScene(0, 0).x() + Const::MINIMUM_ITEM_WIDTH)) ||
(event->scenePos().x() >= (mapToScene(0, 0).x() + width()))) { (event->scenePos().x() >= (mapToScene(0, 0).x() + width()))) {
setWidth(div(int(event->scenePos().x()) - int(mapToScene(0, 0).x()), 2).quot * 2); setWidth(div(int(event->scenePos().x()) - int(mapToScene(0, 0).x()), 2).quot * 2);
} }
@ -371,7 +386,7 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (m_resizeDirectionFlags & ResizeBottom) { if (m_resizeDirectionFlags & ResizeBottom) {
if ((event->scenePos().y() > (mapToScene(0, 0).y() + height())) || if ((event->scenePos().y() > (mapToScene(0, 0).y() + height())) ||
(event->scenePos().y() > (mapToScene(0, 0).y() + Consts::MINIMUM_ITEM_HEIGHT)) (event->scenePos().y() > (mapToScene(0, 0).y() + Const::MINIMUM_ITEM_HEIGHT))
) { ) {
setHeight(div(int(event->scenePos().y()) - int(mapToScene(0, 0).y()), 2).quot * 2); setHeight(div(int(event->scenePos().y()) - int(mapToScene(0, 0).y()), 2).quot * 2);
} }
@ -379,8 +394,8 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (m_resizeDirectionFlags & ResizeTop) { if (m_resizeDirectionFlags & ResizeTop) {
if ((event->scenePos().y()) <= (mapToScene(0, 0).y() + (height() - Consts::MINIMUM_ITEM_HEIGHT)) && if ((event->scenePos().y()) <= (mapToScene(0, 0).y() + (height() - Const::MINIMUM_ITEM_HEIGHT)) &&
(height() + (event->lastScenePos().y() - event->scenePos().y()) > Consts::MINIMUM_ITEM_HEIGHT) (height() + (event->lastScenePos().y() - event->scenePos().y()) > Const::MINIMUM_ITEM_HEIGHT)
) { ) {
qreal posBottomConner = int(mapToScene(0, 0).y()) + int(height()); qreal posBottomConner = int(mapToScene(0, 0).y()) + int(height());
setItemPos(x(), div(mapToParent(event->pos()).y(), 2).quot * 2); setItemPos(x(), div(mapToParent(event->pos()).y(), 2).quot * 2);
@ -619,7 +634,7 @@ void BaseDesignIntf::drawRenderModeBorder(QPainter *painter, QRectF rect) const
void BaseDesignIntf::drawBorder(QPainter *painter, QRectF rect) const void BaseDesignIntf::drawBorder(QPainter *painter, QRectF rect) const
{ {
painter->save(); painter->save();
if (itemMode() & DesignMode) { if (itemMode() & DesignMode && drawDesignBorders()) {
drawDesignModeBorder(painter, rect); drawDesignModeBorder(painter, rect);
} }
else drawRenderModeBorder(painter, rect); else drawRenderModeBorder(painter, rect);
@ -692,7 +707,7 @@ QPen BaseDesignIntf::borderPen(BorderSide side/*, bool selected*/) const
QColor BaseDesignIntf::selectionColor() const QColor BaseDesignIntf::selectionColor() const
{ {
return Consts::SELECTION_COLOR; return Const::SELECTION_COLOR;
} }
void BaseDesignIntf::initFlags() void BaseDesignIntf::initFlags()
@ -879,8 +894,8 @@ void BaseDesignIntf::drawResizeZone(QPainter *painter)
if (m_resizeAreas.count() > 0) { if (m_resizeAreas.count() > 0) {
painter->save(); painter->save();
painter->setPen(QPen(Consts::RESIZE_ZONE_COLOR)); painter->setPen(QPen(Const::RESIZE_ZONE_COLOR));
(isSelected()) ? painter->setOpacity(Consts::SELECTED_RESIZE_ZONE_OPACITY) : painter->setOpacity(Consts::RESIZE_ZONE_OPACITY); (isSelected()) ? painter->setOpacity(Const::SELECTED_RESIZE_ZONE_OPACITY) : painter->setOpacity(Const::RESIZE_ZONE_OPACITY);
painter->setBrush(QBrush(Qt::green, Qt::SolidPattern)); painter->setBrush(QBrush(Qt::green, Qt::SolidPattern));
foreach(QRectF * resizeArea, m_resizeAreas) painter->drawRect(*resizeArea); foreach(QRectF * resizeArea, m_resizeAreas) painter->drawRect(*resizeArea);
painter->restore(); painter->restore();
@ -1093,7 +1108,7 @@ void SelectionMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
pen.setWidth(2); pen.setWidth(2);
pen.setStyle(Qt::DashLine); pen.setStyle(Qt::DashLine);
painter->setPen(pen); painter->setPen(pen);
painter->setOpacity(Consts::SELECTION_COLOR_OPACITY); painter->setOpacity(Const::SELECTION_COLOR_OPACITY);
painter->drawRect(boundingRect()); painter->drawRect(boundingRect());
} }

View File

@ -44,18 +44,6 @@ namespace LimeReport {
enum ItemModes{ DesignMode=1, PreviewMode=2, PrintMode=4, EditMode=8, LayoutEditMode=16 }; enum ItemModes{ DesignMode=1, PreviewMode=2, PrintMode=4, EditMode=8, LayoutEditMode=16 };
namespace Consts {
int const RESIZE_HANDLE_SIZE = 10;
int const SELECTION_PEN_SIZE = 4;
int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE;
int const MINIMUM_ITEM_HEIGHT = 2*RESIZE_HANDLE_SIZE;
double const RESIZE_ZONE_OPACITY = 0.5;
double const SELECTED_RESIZE_ZONE_OPACITY = 0.6;
QColor const RESIZE_ZONE_COLOR = Qt::green;
QColor const SELECTION_COLOR = Qt::red;
double const SELECTION_COLOR_OPACITY = 0.9;
}
class ReportEnginePrivate; class ReportEnginePrivate;
class PageDesignIntf; class PageDesignIntf;
class BaseDesignIntf; class BaseDesignIntf;
@ -268,6 +256,7 @@ protected:
RenderPass currentRenderPass(){return m_currentPass;} RenderPass currentRenderPass(){return m_currentPass;}
virtual bool drawDesignBorders() const {return true;}
private: private:
void updateSelectionMarker(); void updateSelectionMarker();
int resizeDirectionFlags(QPointF position); int resizeDirectionFlags(QPointF position);

View File

@ -112,6 +112,11 @@ void QueryHolder::setConnectionName(QString connectionName)
m_connectionName=connectionName; m_connectionName=connectionName;
} }
void QueryHolder::update()
{
runQuery(m_mode);
}
void QueryHolder::setDatasource(IDataSource::Ptr value){ void QueryHolder::setDatasource(IDataSource::Ptr value){
m_dataSource.clear(); m_dataSource.clear();
m_dataSource=value; m_dataSource=value;
@ -120,13 +125,13 @@ void QueryHolder::setDatasource(IDataSource::Ptr value){
void QueryHolder::fillParams(QSqlQuery *query) void QueryHolder::fillParams(QSqlQuery *query)
{ {
DataSourceManager* dm=DataSourceManager::instance(); DataSourceManager* dm=DataSourceManager::instance();
foreach(QString param,m_params){ foreach(QString param,m_aliasesToParam.keys()){
QVariant value; QVariant value;
if (param.contains(".")){ if (param.contains(".")){
value = dm->fieldData(param); value = dm->fieldData(m_aliasesToParam.value(param));
param=param.right(param.length()-param.indexOf('.')-1); param=param.right(param.length()-param.indexOf('.')-1);
} else { } else {
value = dm->variable(param); value = dm->variable(m_aliasesToParam.value(param));
} }
if (value.isValid() || m_mode == IDataSource::DESIGN_MODE) if (value.isValid() || m_mode == IDataSource::DESIGN_MODE)
query->bindValue(':'+param,value); query->bindValue(':'+param,value);
@ -135,19 +140,31 @@ void QueryHolder::fillParams(QSqlQuery *query)
void QueryHolder::extractParams() void QueryHolder::extractParams()
{ {
m_preparedSQL = replaceVriables(m_queryText); m_preparedSQL = replaceVariables(m_queryText);
} }
QString QueryHolder::replaceVriables(QString query) QString QueryHolder::replaceVariables(QString query)
{ {
QRegExp rx(VARIABLE_RX); QRegExp rx(Const::VARIABLE_RX);
int curentAliasIndex = 0;
if (query.contains(rx)){ if (query.contains(rx)){
while ((rx.indexIn(query))!=-1){ int pos = -1;
while ((pos=rx.indexIn(query))!=-1){
QString variable=rx.cap(0); QString variable=rx.cap(0);
variable.remove("$V{"); variable.remove("$V{");
variable.remove("}"); variable.remove("}");
m_params.append(variable);
query.replace(rx.cap(0),":"+variable); if (m_aliasesToParam.contains(variable)){
curentAliasIndex++;
m_aliasesToParam.insert(variable+"_alias"+QString::number(curentAliasIndex),variable);
variable += "_alias"+QString::number(curentAliasIndex);
} else {
m_aliasesToParam.insert(variable,variable);
}
query.replace(pos,rx.cap(0).length(),":"+variable);
} }
} }
return query; return query;
@ -344,7 +361,7 @@ void SubQueryHolder::setMasterDatasource(const QString &value)
void SubQueryHolder::extractParams() void SubQueryHolder::extractParams()
{ {
m_preparedSQL = replaceFields(replaceVriables(queryText())); m_preparedSQL = replaceFields(replaceVariables(queryText()));
} }
QString SubQueryHolder::extractField(QString source) QString SubQueryHolder::extractField(QString source)
@ -357,17 +374,29 @@ QString SubQueryHolder::extractField(QString source)
QString SubQueryHolder::replaceFields(QString query) QString SubQueryHolder::replaceFields(QString query)
{ {
QRegExp rx(FIELD_RX); QRegExp rx(Const::FIELD_RX);
int curentAliasIndex=0;
if (query.contains(rx)){ if (query.contains(rx)){
while ((rx.indexIn(query))!=-1){ int pos;
while ((pos=rx.indexIn(query))!=-1){
QString field=rx.cap(0); QString field=rx.cap(0);
field.remove("$D{"); field.remove("$D{");
field.remove("}"); field.remove("}");
if (!m_aliasesToParam.contains(field)){
if (field.contains(".")) if (field.contains("."))
m_params.append(field); m_aliasesToParam.insert(field,field);
else else
m_params.append(m_masterDatasource+"."+field); m_aliasesToParam.insert(field,m_masterDatasource+"."+field);
query.replace(rx.cap(0),":"+extractField(field)); } else {
curentAliasIndex++;
if (field.contains("."))
m_aliasesToParam.insert(field+"_alias"+QString::number(curentAliasIndex),field);
else
m_aliasesToParam.insert(field+"_alias"+QString::number(curentAliasIndex),m_masterDatasource+"."+field);
field+="_alias"+QString::number(curentAliasIndex);
}
query.replace(pos,rx.cap(0).length(),":"+extractField(field));
} }
} }
return query; return query;

View File

@ -73,6 +73,7 @@ public:
virtual bool isEditable() const = 0; virtual bool isEditable() const = 0;
virtual bool isRemovable() const = 0; virtual bool isRemovable() const = 0;
virtual void invalidate() = 0; virtual void invalidate() = 0;
virtual void update() = 0;
virtual ~IDataSourceHolder(){} virtual ~IDataSourceHolder(){}
}; };
@ -88,6 +89,7 @@ public:
bool isEditable() const { return false; } bool isEditable() const { return false; }
bool isRemovable() const { return false; } bool isRemovable() const { return false; }
void invalidate(){} void invalidate(){}
void update(){}
signals: signals:
void modelStateChanged(); void modelStateChanged();
private: private:
@ -178,12 +180,13 @@ public:
QString lastError() const { return m_lastError; } QString lastError() const { return m_lastError; }
void setLastError(QString value){m_lastError=value; if (m_query) {delete m_query; m_query=0;}} void setLastError(QString value){m_lastError=value; if (m_query) {delete m_query; m_query=0;}}
void invalidate(){} void invalidate(){}
void update();
protected: protected:
void setDatasource(IDataSource::Ptr value); void setDatasource(IDataSource::Ptr value);
virtual void fillParams(QSqlQuery* query); virtual void fillParams(QSqlQuery* query);
virtual void extractParams(); virtual void extractParams();
QString replaceVriables(QString query); QString replaceVariables(QString query);
QList<QString> m_params; QMap<QString,QString> m_aliasesToParam;
QSqlQuery* m_query; QSqlQuery* m_query;
QString m_preparedSQL; QString m_preparedSQL;
private: private:
@ -299,6 +302,7 @@ public:
bool isRemovable() const { return true; } bool isRemovable() const { return true; }
QString lastError() const { return m_lastError; } QString lastError() const { return m_lastError; }
void invalidate(){m_invalid = true; m_lastError = tr("Datasource has been invalidated");} void invalidate(){m_invalid = true; m_lastError = tr("Datasource has been invalidated");}
void update(){};
private slots: private slots:
void slotChildModelDestoroyed(){m_datasource.clear();} void slotChildModelDestoroyed(){m_datasource.clear();}
private: private:
@ -395,6 +399,7 @@ public:
bool isRemovable() const {return false;} bool isRemovable() const {return false;}
void invalidate(){} void invalidate(){}
~CallbackDatasourceHolder(){if (m_datasource) delete m_datasource;} ~CallbackDatasourceHolder(){if (m_datasource) delete m_datasource;}
void update(){}
private: private:
IDataSource* m_datasource; IDataSource* m_datasource;
bool m_owned; bool m_owned;

View File

@ -30,6 +30,7 @@
#include "lrdatasourcemanager.h" #include "lrdatasourcemanager.h"
#include "lrdatadesignintf.h" #include "lrdatadesignintf.h"
#include <QStringList> #include <QStringList>
#include <QSqlQuery>
#include <QRegExp> #include <QRegExp>
#include <QSqlError> #include <QSqlError>
#include <QSqlQueryModel> #include <QSqlQueryModel>
@ -284,12 +285,34 @@ void DataSourceManager::addCallbackDatasource(ICallbackDatasource *datasource, c
} }
} }
QSharedPointer<QAbstractItemModel>DataSourceManager::previewSQL(const QString &connectionName, const QString &sqlText) QSharedPointer<QAbstractItemModel>DataSourceManager::previewSQL(const QString &connectionName, const QString &sqlText, QString masterDatasource)
{ {
QSqlDatabase db = QSqlDatabase::database(connectionName); QSqlDatabase db = QSqlDatabase::database(connectionName);
if (db.isValid() && db.isOpen()){ if (db.isValid() && db.isOpen()){
QSqlQueryModel* model = new QSqlQueryModel(); QSqlQueryModel* model = new QSqlQueryModel();
model->setQuery(sqlText,db); QMap<QString,QString> aliasesToParam;
QString queryText = replaceVariables(sqlText,aliasesToParam);
queryText = replaceFields(queryText,aliasesToParam,masterDatasource);
QSqlQuery query(db);
query.prepare(queryText);
foreach(QString param,aliasesToParam.keys()){
QVariant value;
if (param.contains(".")){
value = fieldData(aliasesToParam.value(param));
param=param.right(param.length()-param.indexOf('.')-1);
} else {
value = variable(aliasesToParam.value(param));
}
if (value.isValid() || m_designTime)
query.bindValue(':'+param,value);
}
query.exec();
model->setQuery(query);
m_lastError = model->lastError().text(); m_lastError = model->lastError().text();
if (model->query().isActive()) if (model->query().isActive())
return QSharedPointer<QAbstractItemModel>(model); return QSharedPointer<QAbstractItemModel>(model);
@ -301,6 +324,86 @@ QSharedPointer<QAbstractItemModel>DataSourceManager::previewSQL(const QString &c
return QSharedPointer<QAbstractItemModel>(0); return QSharedPointer<QAbstractItemModel>(0);
} }
QString DataSourceManager::extractField(QString source)
{
if (source.contains('.')) {
return source.right(source.length()-(source.indexOf('.')+1));
}
return source;
}
QString DataSourceManager::replaceVariables(QString query, QMap<QString,QString> &aliasesToParam)
{
QRegExp rx(Const::VARIABLE_RX);
int curentAliasIndex = 0;
if (query.contains(rx)){
int pos = -1;
while ((pos=rx.indexIn(query))!=-1){
QString var=rx.cap(0);
var.remove("$V{");
var.remove("}");
if (aliasesToParam.contains(var)){
curentAliasIndex++;
aliasesToParam.insert(var+"_v_alias"+QString::number(curentAliasIndex),var);
var += "_v_alias"+QString::number(curentAliasIndex);
} else {
aliasesToParam.insert(var,var);
}
query.replace(pos,rx.cap(0).length(),":"+var);
}
}
return query;
}
QString DataSourceManager::replaceFields(QString query, QMap<QString,QString> &aliasesToParam, QString masterDatasource)
{
QRegExp rx(Const::FIELD_RX);
int curentAliasIndex=0;
if (query.contains(rx)){
int pos;
while ((pos=rx.indexIn(query))!=-1){
QString field=rx.cap(0);
field.remove("$D{");
field.remove("}");
if (!aliasesToParam.contains(field)){
if (field.contains("."))
aliasesToParam.insert(field,field);
else
aliasesToParam.insert(field,masterDatasource+"."+field);
} else {
curentAliasIndex++;
if (field.contains("."))
aliasesToParam.insert(field+"_f_alias"+QString::number(curentAliasIndex),field);
else
aliasesToParam.insert(field+"_f_alias"+QString::number(curentAliasIndex),masterDatasource+"."+field);
field+="_f_alias"+QString::number(curentAliasIndex);
}
query.replace(pos,rx.cap(0).length(),":"+extractField(field));
}
}
return query;
// QRegExp rx(Const::FIELD_RX);
// if (query.contains(rx)){
// while ((rx.indexIn(query))!=-1){
// QString field=rx.cap(0);
// field.remove("$D{");
// field.remove("}");
// if (field.contains("."))
// aliasesToParam.append(field);
// else
// aliasesToParam.append(masterDatasource+"."+field);
// query.replace(rx.cap(0),":"+extractField(field));
// }
// }
// return query;
}
void DataSourceManager::setReportVariable(const QString &name, const QVariant &value) void DataSourceManager::setReportVariable(const QString &name, const QVariant &value)
{ {
if (!containsVariable(name)){ if (!containsVariable(name)){
@ -525,10 +628,11 @@ void DataSourceManager::putProxyDesc(ProxyDesc *proxyDesc)
bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc) bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc)
{ {
if (QSqlDatabase::contains(connectionDesc->name())) return QSqlDatabase::database(connectionDesc->name()).isOpen();
bool connected = false; bool connected = false;
clearErrorsList();
QString lastError =""; QString lastError ="";
if (!QSqlDatabase::contains(connectionDesc->name())){
{ {
QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name()); QSqlDatabase db = QSqlDatabase::addDatabase(connectionDesc->driver(),connectionDesc->name());
db.setHostName(connectionDesc->host()); db.setHostName(connectionDesc->host());
@ -538,6 +642,9 @@ bool DataSourceManager::connectConnection(ConnectionDesc *connectionDesc)
connected=db.open(); connected=db.open();
if (!connected) lastError=db.lastError().text(); if (!connected) lastError=db.lastError().text();
} }
} else {
connected = QSqlDatabase::database(connectionDesc->name()).isOpen();
}
if (!connected) { if (!connected) {
QSqlDatabase::removeDatabase(connectionDesc->name()); QSqlDatabase::removeDatabase(connectionDesc->name());
setLastError(lastError); setLastError(lastError);
@ -865,14 +972,6 @@ void DataSourceManager::slotConnectionRenamed(const QString &oldName, const QStr
void DataSourceManager::clear(ClearMethod method) void DataSourceManager::clear(ClearMethod method)
{ {
QList<ConnectionDesc*>::iterator cit = m_connections.begin();
while( cit != m_connections.end() ){
QSqlDatabase::removeDatabase( (*cit)->name() );
delete (*cit);
cit = m_connections.erase(cit);
}
DataSourcesMap::iterator dit; DataSourcesMap::iterator dit;
for( dit = m_datasources.begin(); dit != m_datasources.end(); ){ for( dit = m_datasources.begin(); dit != m_datasources.end(); ){
bool owned = (*dit)->isOwned() && (*dit)->isRemovable(); bool owned = (*dit)->isOwned() && (*dit)->isRemovable();
@ -894,6 +993,13 @@ void DataSourceManager::clear(ClearMethod method)
} }
QList<ConnectionDesc*>::iterator cit = m_connections.begin();
while( cit != m_connections.end() ){
QSqlDatabase::removeDatabase( (*cit)->name() );
delete (*cit);
cit = m_connections.erase(cit);
}
//TODO: add smart pointes to collections //TODO: add smart pointes to collections
foreach(QueryDesc *desc, m_queries) delete desc; foreach(QueryDesc *desc, m_queries) delete desc;
foreach(SubQueryDesc* desc, m_subqueries) delete desc; foreach(SubQueryDesc* desc, m_subqueries) delete desc;

View File

@ -177,7 +177,11 @@ public:
QStringList errorsList(){ return m_errorsList;} QStringList errorsList(){ return m_errorsList;}
bool designTime() const; bool designTime() const;
void setDesignTime(bool designTime); void setDesignTime(bool designTime);
QSharedPointer<QAbstractItemModel> previewSQL(const QString& connectionName, const QString& sqlText);
QString extractField(QString source);
QString replaceVariables(QString query, QMap<QString, QString> &aliasesToParam);
QString replaceFields(QString query, QMap<QString, QString> &aliasesToParam, QString masterDatasource = "");
QSharedPointer<QAbstractItemModel> previewSQL(const QString& connectionName, const QString& sqlText, QString masterDatasource="");
signals: signals:
void loadCollectionFinished(const QString& collectionName); void loadCollectionFinished(const QString& collectionName);

View File

@ -42,19 +42,29 @@
#endif #endif
namespace LimeReport { namespace LimeReport {
namespace Const{
int const RESIZE_HANDLE_SIZE = 10;
int const SELECTION_PEN_SIZE = 4;
int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE;
int const MINIMUM_ITEM_HEIGHT = 2*RESIZE_HANDLE_SIZE;
double const RESIZE_ZONE_OPACITY = 0.5;
double const SELECTED_RESIZE_ZONE_OPACITY = 0.6;
Qt::GlobalColor const RESIZE_ZONE_COLOR = Qt::green;
Qt::GlobalColor const SELECTION_COLOR = Qt::red;
double const SELECTION_COLOR_OPACITY = 0.9;
const qreal fontFACTOR = 3.5; const qreal fontFACTOR = 3.5;
const int mmFACTOR = 10; const int mmFACTOR = 10;
const int itemPaleteIconSize = 24; const int itemPaleteIconSize = 24;
const qreal minSpaceBorder = 10; const qreal minSpaceBorder = 10;
QString extractClassName(QString className);
const QString bandTAG = "band"; const QString bandTAG = "band";
const Qt::GlobalColor BAND_NAME_LABEL_COLOR = Qt::yellow;
const Qt::GlobalColor BAND_NAME_BORDER_COLOR = Qt::darkYellow;
const qreal BAND_MARKER_OPACITY = 1; const qreal BAND_MARKER_OPACITY = 1;
const qreal LAYOUT_MARKER_OPACITY = 0.3; const qreal LAYOUT_MARKER_OPACITY = 0.3;
const qreal BAND_NAME_AREA_OPACITY = 0.3; const qreal BAND_NAME_AREA_OPACITY = 0.3;
const qreal BAND_NAME_TEXT_OPACITY = 0.6; const qreal BAND_NAME_TEXT_OPACITY = 0.6;
const qreal SELECTION_OPACITY = 0.3; const qreal SELECTION_OPACITY = 0.3;
enum RenderPass {FirstPass, SecondPass};
enum ArrangeType {AsNeeded, Force};
const QString FIELD_RX = "\\$D\\s*\\{\\s*([^\\s{}]*)\\s*\\}"; const QString FIELD_RX = "\\$D\\s*\\{\\s*([^\\s{}]*)\\s*\\}";
const QString VARIABLE_RX = "\\$V\\s*\\{\\s*([^\\s{}]*)\\s*\\}"; const QString VARIABLE_RX = "\\$V\\s*\\{\\s*([^\\s{}]*)\\s*\\}";
const QString SCRIPT_RX = "\\$S\\s*\\{(.*)\\}"; const QString SCRIPT_RX = "\\$S\\s*\\{(.*)\\}";
@ -64,6 +74,10 @@ namespace LimeReport {
const QString GROUP_FUNCTION_RX = "(%1\\s*"+GROUP_FUNCTION_PARAM_RX+")"; const QString GROUP_FUNCTION_RX = "(%1\\s*"+GROUP_FUNCTION_PARAM_RX+")";
const QString GROUP_FUNCTION_NAME_RX = "%1\\s*\\((.*[^\\)])\\)"; const QString GROUP_FUNCTION_NAME_RX = "%1\\s*\\((.*[^\\)])\\)";
const int SCENE_MARGIN = 50; const int SCENE_MARGIN = 50;
}
QString extractClassName(QString className);
enum RenderPass {FirstPass, SecondPass};
enum ArrangeType {AsNeeded, Force};
class ReportError : public std::runtime_error{ class ReportError : public std::runtime_error{
public: public:
ReportError(const QString& message):std::runtime_error(message.toStdString()){} ReportError(const QString& message):std::runtime_error(message.toStdString()){}

View File

@ -88,14 +88,14 @@ QVariant GroupFunction::multiplication(QVariant value1, QVariant value2)
GroupFunction::GroupFunction(const QString &expression, const QString &dataBandName, DataSourceManager* dataManager) GroupFunction::GroupFunction(const QString &expression, const QString &dataBandName, DataSourceManager* dataManager)
:m_dataBandName(dataBandName), m_dataManager(dataManager),m_isValid(true), m_errorMessage("") :m_dataBandName(dataBandName), m_dataManager(dataManager),m_isValid(true), m_errorMessage("")
{ {
QRegExp rxField(FIELD_RX,Qt::CaseInsensitive); QRegExp rxField(Const::FIELD_RX,Qt::CaseInsensitive);
if (rxField.indexIn(expression)>=0){ if (rxField.indexIn(expression)>=0){
m_dataType=Field; m_dataType=Field;
m_data = rxField.cap(1); m_data = rxField.cap(1);
return; return;
} }
QRegExp rxVariable(VARIABLE_RX,Qt::CaseInsensitive); QRegExp rxVariable(Const::VARIABLE_RX,Qt::CaseInsensitive);
if (rxVariable.indexIn(expression)>=0){ if (rxVariable.indexIn(expression)>=0){
m_dataType=Variable; m_dataType=Variable;
m_data = rxVariable.cap(1); m_data = rxVariable.cap(1);

View File

@ -116,7 +116,7 @@ void ItemDesignIntf::initFlags()
QString ContentItemDesignIntf::expandDataFields(QString context, ExpandType expandType) QString ContentItemDesignIntf::expandDataFields(QString context, ExpandType expandType)
{ {
DataSourceManager* dm = DataSourceManager::instance(); DataSourceManager* dm = DataSourceManager::instance();
QRegExp rx(FIELD_RX); QRegExp rx(Const::FIELD_RX);
if (context.contains(rx)){ if (context.contains(rx)){
while ((rx.indexIn(context))!=-1){ while ((rx.indexIn(context))!=-1){
@ -166,8 +166,7 @@ QString ContentItemDesignIntf::expandDataFields(QString context, ExpandType expa
QString ContentItemDesignIntf::expandUserVariables(QString context, RenderPass pass, ExpandType expandType) QString ContentItemDesignIntf::expandUserVariables(QString context, RenderPass pass, ExpandType expandType)
{ {
DataSourceManager* dm=DataSourceManager::instance(); DataSourceManager* dm=DataSourceManager::instance();
//QRegExp rx("\\$V\\{([^{}]*)\\}"); QRegExp rx(Const::VARIABLE_RX);
QRegExp rx(VARIABLE_RX);
if (context.contains(rx)){ if (context.contains(rx)){
int pos = 0; int pos = 0;
while ((pos = rx.indexIn(context,pos))!=-1){ while ((pos = rx.indexIn(context,pos))!=-1){
@ -192,7 +191,7 @@ QString ContentItemDesignIntf::expandUserVariables(QString context, RenderPass p
QString ContentItemDesignIntf::expandScripts(QString context) QString ContentItemDesignIntf::expandScripts(QString context)
{ {
QRegExp rx(SCRIPT_RX); QRegExp rx(Const::SCRIPT_RX);
if (context.contains(rx)){ if (context.contains(rx)){
QScriptEngine* se = ScriptEngineManager::instance().scriptEngine(); QScriptEngine* se = ScriptEngineManager::instance().scriptEngine();

View File

@ -46,7 +46,6 @@
#include "lrglobal.h" #include "lrglobal.h"
#include <QPrinter> #include <QPrinter>
#include <QDebug> #include <QDebug>
#include <QGraphicsItem> #include <QGraphicsItem>
@ -117,9 +116,9 @@ void PageDesignIntf::updatePageRect()
connect(m_pageItem.data(), SIGNAL(geometryChanged(QObject *, QRectF, QRectF)), this, SLOT(slotPageGeomertyChanged(QObject *, QRectF, QRectF))); connect(m_pageItem.data(), SIGNAL(geometryChanged(QObject *, QRectF, QRectF)), this, SLOT(slotPageGeomertyChanged(QObject *, QRectF, QRectF)));
connect(m_pageItem.data(), SIGNAL(objectLoaded(QObject *)), this, SLOT(slotPageItemLoaded(QObject *))); connect(m_pageItem.data(), SIGNAL(objectLoaded(QObject *)), this, SLOT(slotPageItemLoaded(QObject *)));
} }
this->setSceneRect(-SCENE_MARGIN, -SCENE_MARGIN, this->setSceneRect(-Const::SCENE_MARGIN, -Const::SCENE_MARGIN,
pageItem()->geometry().width() + SCENE_MARGIN*2, pageItem()->geometry().width() + Const::SCENE_MARGIN*2,
pageItem()->geometry().height() + SCENE_MARGIN*2); pageItem()->geometry().height() + Const::SCENE_MARGIN*2);
emit sceneRectChanged(sceneRect()); emit sceneRectChanged(sceneRect());
} }
@ -256,7 +255,7 @@ void PageDesignIntf::setPageItem(PageItemDesignIntf::Ptr pageItem)
} }
m_pageItem = pageItem; m_pageItem = pageItem;
m_pageItem->setItemMode(itemMode()); m_pageItem->setItemMode(itemMode());
setSceneRect(pageItem->rect().adjusted(-10*mmFACTOR,-10*mmFACTOR,10*mmFACTOR,10*mmFACTOR)); setSceneRect(pageItem->rect().adjusted(-10*Const::mmFACTOR,-10*Const::mmFACTOR,10*Const::mmFACTOR,10*Const::mmFACTOR));
addItem(m_pageItem.data()); addItem(m_pageItem.data());
registerItem(m_pageItem.data()); registerItem(m_pageItem.data());
} }
@ -278,7 +277,7 @@ void PageDesignIntf::setPageItems(QList<PageItemDesignIntf::Ptr> pages)
curHeight+=pageItem->height()+20; curHeight+=pageItem->height()+20;
if (curWidth<pageItem->width()) curWidth=pageItem->width(); if (curWidth<pageItem->width()) curWidth=pageItem->width();
} }
setSceneRect(QRectF(0,0,curWidth,curHeight).adjusted(-10*mmFACTOR,-10*mmFACTOR,10*mmFACTOR,10*mmFACTOR)); setSceneRect(QRectF(0,0,curWidth,curHeight).adjusted(-10*Const::mmFACTOR,-10*Const::mmFACTOR,10*Const::mmFACTOR,10*Const::mmFACTOR));
} }
@ -290,6 +289,10 @@ void PageDesignIntf::mousePressEvent(QGraphicsSceneMouseEvent *event)
saveCommand(command); saveCommand(command);
emit itemInserted(this, event->scenePos(), m_insertItemType); emit itemInserted(this, event->scenePos(), m_insertItemType);
} }
if (event->buttons() & Qt::LeftButton && !selectedItems().isEmpty()){
m_startMovePoint = event->scenePos();
}
if (event->buttons() & Qt::LeftButton && event->modifiers()==Qt::ShiftModifier){ if (event->buttons() & Qt::LeftButton && event->modifiers()==Qt::ShiftModifier){
m_startSelectionPoint = event->scenePos(); m_startSelectionPoint = event->scenePos();
} else { } else {
@ -308,6 +311,10 @@ void PageDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
} }
} }
if (event->button() & Qt::LeftButton && event->modifiers()==0){
}
if (event->buttons() & Qt::LeftButton && event->modifiers()==Qt::ShiftModifier){ if (event->buttons() & Qt::LeftButton && event->modifiers()==Qt::ShiftModifier){
if (!m_selectionRect){ if (!m_selectionRect){
m_selectionRect = new QGraphicsRectItem(); m_selectionRect = new QGraphicsRectItem();
@ -647,22 +654,15 @@ void PageDesignIntf::dragMoveEvent(QGraphicsSceneDragDropEvent* /**event*/)
void PageDesignIntf::dropEvent(QGraphicsSceneDragDropEvent* event) void PageDesignIntf::dropEvent(QGraphicsSceneDragDropEvent* event)
{ {
if (event->mimeData()->hasText() &&
// if (m_itemInsertRect) { ((event->mimeData()->text().indexOf("field:")==0) ||
// removeItem(m_itemInsertRect); (event->mimeData()->text().indexOf("variable:")==0))
// delete m_itemInsertRect; ){
// m_itemInsertRect = 0;
// }
// if (event->mimeData()->text() == "Text Item") {
// addReportItem(event->mimeData()->text(), event->scenePos(), QSizeF(200, 50));
// }
// else addBand(event->mimeData()->text());
BaseDesignIntf* item = addReportItem("TextItem",event->scenePos(),QSize(250, 50)); BaseDesignIntf* item = addReportItem("TextItem",event->scenePos(),QSize(250, 50));
TextItem* ti = dynamic_cast<TextItem*>(item); TextItem* ti = dynamic_cast<TextItem*>(item);
ti->setContent(event->mimeData()->text()); QString data = event->mimeData()->text().remove(0,event->mimeData()->text().indexOf(":")+1);
ti->setContent(data);
}
} }
void PageDesignIntf::dragLeaveEvent(QGraphicsSceneDragDropEvent *) void PageDesignIntf::dragLeaveEvent(QGraphicsSceneDragDropEvent *)
@ -1250,9 +1250,10 @@ HorizontalLayout* PageDesignIntf::internalAddHLayout()
if (si.count() > 1) { if (si.count() > 1) {
it = si.begin(); it = si.begin();
BaseDesignIntf *firstElement = dynamic_cast<BaseDesignIntf *>(*it); ItemDesignIntf *firstElement = dynamic_cast<ItemDesignIntf *>(*it);
HorizontalLayout *layout = new HorizontalLayout(firstElement->parent(), firstElement->parentItem()); HorizontalLayout *layout = new HorizontalLayout(firstElement->parent(), firstElement->parentItem());
layout->setItemLocation(firstElement->itemLocation());
layout->setPos(firstElement->pos()); layout->setPos(firstElement->pos());
layout->setWidth(0); layout->setWidth(0);
layout->setHeight(firstElement->height()); layout->setHeight(firstElement->height());
@ -1266,9 +1267,9 @@ HorizontalLayout* PageDesignIntf::internalAddHLayout()
item->setSelected(false); item->setSelected(false);
} }
layout->setSelected(true);
layout->setObjectName(genObjectName(*layout)); layout->setObjectName(genObjectName(*layout));
layout->setItemTypeName("HorizontalLayout"); layout->setItemTypeName("HorizontalLayout");
layout->setSelected(true);
registerItem(layout); registerItem(layout);
return layout; return layout;
} }

View File

@ -244,6 +244,7 @@ namespace LimeReport {
QList<QObject*> m_animationList; QList<QObject*> m_animationList;
QPointF m_startSelectionPoint; QPointF m_startSelectionPoint;
QGraphicsRectItem* m_selectionRect; QGraphicsRectItem* m_selectionRect;
QPointF m_startMovePoint;
}; };
class AbstractPageCommand : public CommandIf{ class AbstractPageCommand : public CommandIf{

View File

@ -385,6 +385,26 @@ void PreviewReportWindow::slotLastPage()
m_changingPage=false; m_changingPage=false;
} }
void PreviewReportWindow::slotPrintToPDF()
{
QString fileName = QFileDialog::getSaveFileName(this,tr("PDF file name"),"","PDF(*.pdf)" );
qDebug()<<fileName;
if (!fileName.isEmpty()){
QPrinter printer;
printer.setOutputFileName(fileName);
printer.setOutputFormat(QPrinter::PdfFormat);
if (!m_reportPages.isEmpty()){
ReportEnginePrivate::printReport(m_reportPages,printer,PrintRange());
} else {
ReportEnginePrivate::printReport(m_reader,printer);
}
foreach(PageItemDesignIntf::Ptr pageItem, m_reportPages){
m_previewPage->reactivatePageItem(pageItem);
}
}
}
void PreviewReportWindow::slotSliderMoved(int value) void PreviewReportWindow::slotSliderMoved(int value)
{ {
if (ui->graphicsView->verticalScrollBar()->minimum()==value){ if (ui->graphicsView->verticalScrollBar()->minimum()==value){

View File

@ -73,6 +73,7 @@ public slots:
void on_actionSaveToFile_triggered(); void on_actionSaveToFile_triggered();
void slotFirstPage(); void slotFirstPage();
void slotLastPage(); void slotLastPage();
void slotPrintToPDF();
private slots: private slots:
void slotSliderMoved(int value); void slotSliderMoved(int value);
private: private:

View File

@ -41,7 +41,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>800</width>
<height>20</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuView"> <widget class="QMenu" name="menuView">
@ -56,6 +56,7 @@
<string>Report</string> <string>Report</string>
</property> </property>
<addaction name="actionPrint"/> <addaction name="actionPrint"/>
<addaction name="actionPrint_To_PDF"/>
</widget> </widget>
<addaction name="menuReport"/> <addaction name="menuReport"/>
<addaction name="menuView"/> <addaction name="menuView"/>
@ -78,7 +79,7 @@
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="actionPrint"/> <addaction name="actionPrint"/>
<addaction name="actionSaveToFile"/> <addaction name="actionPrint_To_PDF"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionZoomIn"/> <addaction name="actionZoomIn"/>
<addaction name="actionZoomOut"/> <addaction name="actionZoomOut"/>
@ -220,10 +221,19 @@
<string>Last Page</string> <string>Last Page</string>
</property> </property>
</action> </action>
<action name="actionPrint_To_PDF">
<property name="icon">
<iconset resource="report.qrc">
<normaloff>:/report/images/pdf</normaloff>:/report/images/pdf</iconset>
</property>
<property name="text">
<string>Print To PDF</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="databrowser/lrdatabrowser.qrc"/>
<include location="report.qrc"/> <include location="report.qrc"/>
<include location="databrowser/lrdatabrowser.qrc"/>
</resources> </resources>
<connections> <connections>
<connection> <connection>
@ -354,6 +364,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>actionPrint_To_PDF</sender>
<signal>triggered()</signal>
<receiver>PreviewReportWindow</receiver>
<slot>slotPrintToPDF()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>slotNextPage()</slot> <slot>slotNextPage()</slot>
@ -363,5 +389,6 @@
<slot>slotPrint()</slot> <slot>slotPrint()</slot>
<slot>slotFirstPage()</slot> <slot>slotFirstPage()</slot>
<slot>slotLastPage()</slot> <slot>slotLastPage()</slot>
<slot>slotPrintToPDF()</slot>
</slots> </slots>
</ui> </ui>

View File

@ -39,10 +39,62 @@
#include <QtXml> #include <QtXml>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QFileDialog> #include <QFileDialog>
#include <QApplication>
namespace LimeReport { namespace LimeReport {
//GraphicsViewZoom
GraphicsViewZoom::GraphicsViewZoom(QGraphicsView* view)
: QObject(view), m_view(view)
{
m_view->viewport()->installEventFilter(this);
m_view->setMouseTracking(true);
m_modifiers = Qt::ControlModifier;
m_zoomFactorBase = 1.0015;
}
void GraphicsViewZoom::gentleZoom(double factor) {
m_view->scale(factor, factor);
m_view->centerOn(m_targetScenePos);
QPointF delta_viewport_pos = m_targetViewportPos - QPointF(m_view->viewport()->width() / 2.0,
m_view->viewport()->height() / 2.0);
QPointF viewport_center = m_view->mapFromScene(m_targetScenePos) - delta_viewport_pos;
m_view->centerOn(m_view->mapToScene(viewport_center.toPoint()));
emit zoomed();
}
void GraphicsViewZoom::setModifiers(Qt::KeyboardModifiers modifiers) {
m_modifiers = modifiers;
}
void GraphicsViewZoom::setZoomFactorBase(double value) {
m_zoomFactorBase = value;
}
bool GraphicsViewZoom::eventFilter(QObject *object, QEvent *event) {
if (event->type() == QEvent::MouseMove) {
QMouseEvent* mouse_event = static_cast<QMouseEvent*>(event);
QPointF delta = m_targetViewportPos - mouse_event->pos();
if (qAbs(delta.x()) > 5 || qAbs(delta.y()) > 5) {
m_targetViewportPos = mouse_event->pos();
m_targetScenePos = m_view->mapToScene(mouse_event->pos());
}
} else if (event->type() == QEvent::Wheel) {
QWheelEvent* wheel_event = static_cast<QWheelEvent*>(event);
if (QApplication::keyboardModifiers() == m_modifiers) {
if (wheel_event->orientation() == Qt::Vertical) {
double angle = wheel_event->angleDelta().y();
double factor = qPow(m_zoomFactorBase, angle);
gentleZoom(factor);
return true;
}
}
}
Q_UNUSED(object)
return false;
}
// ReportDesignIntf // ReportDesignIntf
ReportDesignWidget* ReportDesignWidget::m_instance=0; ReportDesignWidget* ReportDesignWidget::m_instance=0;
@ -74,6 +126,8 @@ ReportDesignWidget::ReportDesignWidget(ReportEnginePrivate *report, QMainWindow
connect(m_report,SIGNAL(cleared()),this,SIGNAL(cleared())); connect(m_report,SIGNAL(cleared()),this,SIGNAL(cleared()));
m_view->scale(0.5,0.5); m_view->scale(0.5,0.5);
m_instance=this; m_instance=this;
//m_view->viewport()->installEventFilter(this);
m_zoomer = new GraphicsViewZoom(m_view);
} }
ReportDesignWidget::~ReportDesignWidget() ReportDesignWidget::~ReportDesignWidget()
@ -350,6 +404,18 @@ void ReportDesignWidget::slotSceneRectChanged(QRectF)
m_view->centerOn(0,0); m_view->centerOn(0,0);
} }
bool ReportDesignWidget::eventFilter(QObject *target, QEvent *event)
{
if (event->type() == QEvent::Wheel){
QWheelEvent* we = dynamic_cast<QWheelEvent*>(event);
if (QApplication::keyboardModifiers()==Qt::ControlModifier){
if(we->delta()<0) scale(1.2,1.2);
else scale(1/1.2,1/1.2);
}
}
return QWidget::eventFilter(target,event);
}
void ReportDesignWidget::clear() void ReportDesignWidget::clear()
{ {
m_report->clearReport(); m_report->clearReport();

View File

@ -47,6 +47,24 @@ class ReportEnginePrivate;
class DataBrowser; class DataBrowser;
class ReportDesignWindow; class ReportDesignWindow;
class GraphicsViewZoom : public QObject {
Q_OBJECT
public:
GraphicsViewZoom(QGraphicsView* view);
void gentleZoom(double factor);
void setModifiers(Qt::KeyboardModifiers modifiers);
void setZoomFactorBase(double value);
private:
QGraphicsView* m_view;
Qt::KeyboardModifiers m_modifiers;
double m_zoomFactorBase;
QPointF m_targetScenePos, m_targetViewportPos;
bool eventFilter(QObject* object, QEvent* event);
signals:
void zoomed();
};
class ReportDesignWidget : public QWidget class ReportDesignWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -123,11 +141,13 @@ signals:
void itemAdded(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*); void itemAdded(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*);
void itemDeleted(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*); void itemDeleted(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*);
private: private:
bool eventFilter(QObject *target, QEvent *event);
ReportDesignWidget(ReportEnginePrivate* report,QMainWindow *mainWindow,QWidget *parent = 0); ReportDesignWidget(ReportEnginePrivate* report,QMainWindow *mainWindow,QWidget *parent = 0);
private: private:
ReportEnginePrivate* m_report; ReportEnginePrivate* m_report;
QGraphicsView *m_view; QGraphicsView *m_view;
QMainWindow *m_mainWindow; QMainWindow *m_mainWindow;
GraphicsViewZoom* m_zoomer;
static ReportDesignWidget* m_instance; static ReportDesignWidget* m_instance;
}; };

View File

@ -49,7 +49,6 @@
#include "lrbasedesignintf.h" #include "lrbasedesignintf.h"
#include "lrpagedesignintf.h" #include "lrpagedesignintf.h"
#include "waitform.h"
#include "lrpreviewreportwindow.h" #include "lrpreviewreportwindow.h"
#include "serializators/lrstorageintf.h" #include "serializators/lrstorageintf.h"
#include "serializators/lrxmlreader.h" #include "serializators/lrxmlreader.h"
@ -78,6 +77,8 @@ ReportDesignWindow::ReportDesignWindow(ReportEnginePrivate *report, QWidget *par
setStatusBar(m_statusBar); setStatusBar(m_statusBar);
setWindowTitle("Lime Report Designer"); setWindowTitle("Lime Report Designer");
restoreSetting(); restoreSetting();
m_hideLeftPanel->setChecked(isDockAreaVisible(Qt::LeftDockWidgetArea));
m_hideRightPanel->setChecked(isDockAreaVisible(Qt::RightDockWidgetArea));
} }
ReportDesignWindow::~ReportDesignWindow() ReportDesignWindow::~ReportDesignWindow()
@ -187,6 +188,17 @@ void ReportDesignWindow::createActions()
m_aboutAction->setIcon(QIcon(":/report/images/copyright")); m_aboutAction->setIcon(QIcon(":/report/images/copyright"));
connect(m_aboutAction,SIGNAL(triggered()),this,SLOT(slotShowAbout())); connect(m_aboutAction,SIGNAL(triggered()),this,SLOT(slotShowAbout()));
m_hideLeftPanel = new QAction(tr("Hide left panel"),this);
m_hideLeftPanel->setCheckable(true);
m_hideLeftPanel->setChecked(true);
m_hideLeftPanel->setIcon(QIcon(":/report/images/hideLeftPanel"));
connect(m_hideLeftPanel,SIGNAL(toggled(bool)), this, SLOT(slotHideLeftPanel(bool)));
m_hideRightPanel = new QAction(tr("Hide left panel"),this);
m_hideRightPanel->setCheckable(true);
m_hideRightPanel->setChecked(true);
m_hideRightPanel->setIcon(QIcon(":/report/images/hideRightPanel"));
connect(m_hideRightPanel,SIGNAL(toggled(bool)), this, SLOT(slotHideRightPanel(bool)));
} }
void ReportDesignWindow::createReportToolBar() void ReportDesignWindow::createReportToolBar()
@ -203,7 +215,15 @@ void ReportDesignWindow::createReportToolBar()
m_reportToolBar->addAction(m_addHLayout); m_reportToolBar->addAction(m_addHLayout);
m_reportToolBar->addSeparator(); m_reportToolBar->addSeparator();
m_reportToolBar->addAction(m_deleteItemAction); m_reportToolBar->addAction(m_deleteItemAction);
QWidget* empty = new QWidget();
empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
m_reportToolBar->addWidget(empty);
m_reportToolBar->addAction(m_hideLeftPanel);
m_reportToolBar->addAction(m_hideRightPanel);
addToolBar(Qt::LeftToolBarArea,m_reportToolBar); addToolBar(Qt::LeftToolBarArea,m_reportToolBar);
} }
void ReportDesignWindow::createToolBars() void ReportDesignWindow::createToolBars()
@ -880,6 +900,34 @@ void ReportDesignWindow::slotShowAbout()
about->exec(); about->exec();
} }
void ReportDesignWindow::hideDockWidgets(Qt::DockWidgetArea area, bool value){
QList<QDockWidget *> dockWidgets = findChildren<QDockWidget *>();
foreach (QDockWidget* dw, dockWidgets) {
if (dockWidgetArea(dw) == area)
value ? dw->show(): dw->hide();
}
}
bool ReportDesignWindow::isDockAreaVisible(Qt::DockWidgetArea area)
{
QList<QDockWidget *> dockWidgets = findChildren<QDockWidget *>();
foreach (QDockWidget* dw, dockWidgets){
if ((dockWidgetArea(dw) == area) && !dw->isHidden())
return true;
}
return false;
}
void ReportDesignWindow::slotHideLeftPanel(bool value)
{
hideDockWidgets(Qt::LeftDockWidgetArea,value);
}
void ReportDesignWindow::slotHideRightPanel(bool value)
{
hideDockWidgets(Qt::RightDockWidgetArea,value);
}
void ReportDesignWindow::closeEvent(QCloseEvent * event) void ReportDesignWindow::closeEvent(QCloseEvent * event)
{ {
if (checkNeedToSave()){ if (checkNeedToSave()){

View File

@ -107,10 +107,14 @@ private slots:
void renderPageFinished(int renderedPageCount); void renderPageFinished(int renderedPageCount);
void renderFinished(); void renderFinished();
void slotShowAbout(); void slotShowAbout();
void slotHideLeftPanel(bool value);
void slotHideRightPanel(bool value);
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
void resizeEvent(QResizeEvent *); void resizeEvent(QResizeEvent *);
void moveEvent(QMoveEvent *); void moveEvent(QMoveEvent *);
void hideDockWidgets(Qt::DockWidgetArea area, bool value);
bool isDockAreaVisible(Qt::DockWidgetArea area);
private: private:
void createActions(); void createActions();
void createBandsButton(); void createBandsButton();
@ -177,6 +181,8 @@ private:
QAction* m_aboutAction; QAction* m_aboutAction;
QAction* m_editLayoutMode; QAction* m_editLayoutMode;
QAction* m_addHLayout; QAction* m_addHLayout;
QAction* m_hideLeftPanel;
QAction* m_hideRightPanel;
QSignalMapper* m_bandsAddSignalsMap; QSignalMapper* m_bandsAddSignalsMap;

View File

@ -58,8 +58,6 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) :
{ {
m_datasources= new DataSourceManager(this); m_datasources= new DataSourceManager(this);
m_datasources->setObjectName("datasources"); m_datasources->setObjectName("datasources");
//m_reportRender=ReportRender::Ptr(new ReportRender());
//m_reportRender->setDatasources(m_datasources);
connect(m_datasources,SIGNAL(loadCollectionFinished(QString)),this,SLOT(slotDataSourceCollectionLoaded(QString))); connect(m_datasources,SIGNAL(loadCollectionFinished(QString)),this,SLOT(slotDataSourceCollectionLoaded(QString)));
} }
@ -85,7 +83,6 @@ PageDesignIntf *ReportEnginePrivate::createPage(const QString &pageName)
PageDesignIntf* page =new PageDesignIntf(this); PageDesignIntf* page =new PageDesignIntf(this);
page->setObjectName(pageName); page->setObjectName(pageName);
page->setReportEditor(this); page->setReportEditor(this);
//m_pages.append(page);
return page; return page;
} }
@ -110,9 +107,9 @@ void ReportEnginePrivate::collectionLoadFinished(const QString &)
{ {
foreach (PageDesignIntf* page, m_pages) { foreach (PageDesignIntf* page, m_pages) {
page->setReportEditor(this); page->setReportEditor(this);
page->setSceneRect(-SCENE_MARGIN,-SCENE_MARGIN, page->setSceneRect(-Const::SCENE_MARGIN,-Const::SCENE_MARGIN,
page->pageItem()->width()+SCENE_MARGIN*2, page->pageItem()->width()+Const::SCENE_MARGIN*2,
page->pageItem()->height()+SCENE_MARGIN*2); page->pageItem()->height()+Const::SCENE_MARGIN*2);
} }
emit pagesLoadFinished(); emit pagesLoadFinished();
} }
@ -228,7 +225,6 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer, cons
bool ReportEnginePrivate::printReport(QPrinter* printer) bool ReportEnginePrivate::printReport(QPrinter* printer)
{ {
//QScopedPointer<QPrinter>l_printer(new QPrinter(QPrinter::HighResolution));
if (!printer&&!m_printerSelected){ if (!printer&&!m_printerSelected){
QPrintDialog dialog(m_printer.data(),QApplication::activeWindow()); QPrintDialog dialog(m_printer.data(),QApplication::activeWindow());
m_printerSelected = dialog.exec()!=QDialog::Rejected; m_printerSelected = dialog.exec()!=QDialog::Rejected;
@ -266,6 +262,17 @@ void ReportEnginePrivate::printToFile(const QString &fileName)
} }
} }
bool ReportEnginePrivate::printToPDF(const QString &fileName)
{
if (!fileName.isEmpty()){
QPrinter printer;
printer.setOutputFileName(fileName);
printer.setOutputFormat(QPrinter::PdfFormat);
return printReport(&printer);
}
return false;
}
void ReportEnginePrivate::previewReport() void ReportEnginePrivate::previewReport()
{ {
QTime start = QTime::currentTime(); QTime start = QTime::currentTime();
@ -312,11 +319,6 @@ void ReportEnginePrivate::cancelRender()
m_reportRender->cancelRender(); m_reportRender->cancelRender();
} }
//PageDesignIntf* ReportEngine::createPreviewScene(QObject* parent){
// Q_D(ReportEngine);
// return d->createPreviewScene(parent);
//}
void ReportEnginePrivate::designReport() void ReportEnginePrivate::designReport()
{ {
LimeReport::ReportDesignWindow* w = new LimeReport::ReportDesignWindow(this,QApplication::activeWindow(),settings()); LimeReport::ReportDesignWindow* w = new LimeReport::ReportDesignWindow(this,QApplication::activeWindow(),settings());
@ -364,7 +366,6 @@ QSettings*ReportEnginePrivate::settings()
bool ReportEnginePrivate::loadFromFile(const QString &fileName) bool ReportEnginePrivate::loadFromFile(const QString &fileName)
{ {
clearReport(); clearReport();
//QScopedPointer< ItemsReaderIntf > reader(new FileXMLReader(fileName));
ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName); ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName);
if (reader->first()){ if (reader->first()){
if (reader->readItem(this)){ if (reader->readItem(this)){
@ -434,8 +435,6 @@ QString ReportEnginePrivate::renderToString()
ReportPages ReportEnginePrivate::renderToPages() ReportPages ReportEnginePrivate::renderToPages()
{ {
//ReportRender render;
m_reportRender = ReportRender::Ptr(new ReportRender); m_reportRender = ReportRender::Ptr(new ReportRender);
dataManager()->clearErrorsList(); dataManager()->clearErrorsList();
dataManager()->connectAllDatabases(); dataManager()->connectAllDatabases();
@ -479,17 +478,18 @@ bool ReportEngine::printReport(QPrinter *printer)
return d->printReport(printer); return d->printReport(printer);
} }
//void ReportEngine::printReport(ReportPages pages, QPrinter &printer){
// Q_D(ReportEngine);
// d->printReport(pages,printer,PrintRange());
//}
void ReportEngine::printToFile(const QString &fileName) void ReportEngine::printToFile(const QString &fileName)
{ {
Q_D(ReportEngine); Q_D(ReportEngine);
d->printToFile(fileName); d->printToFile(fileName);
} }
bool ReportEngine::printToPDF(const QString &fileName)
{
Q_D(ReportEngine);
return d->printToPDF(fileName);
}
void ReportEngine::previewReport() void ReportEngine::previewReport()
{ {
Q_D(ReportEngine); Q_D(ReportEngine);
@ -541,12 +541,6 @@ QString ReportEngine::reportFileName()
return d->reportFileName(); return d->reportFileName();
} }
//void ReportDesignIntf::setPrinter(QPrinter *printer)
//{
// Q_D(ReportDesignIntf);
// d->setPrinter(printer);
//}
bool ReportEngine::saveToFile() bool ReportEngine::saveToFile()
{ {
Q_D(ReportEngine); Q_D(ReportEngine);

View File

@ -37,13 +37,11 @@
#include "lrglobal.h" #include "lrglobal.h"
#include "lrdatasourcemanagerintf.h" #include "lrdatasourcemanagerintf.h"
#include "lrscriptenginemanagerintf.h" #include "lrscriptenginemanagerintf.h"
//#include "lrreportrender.h"
class QPrinter; class QPrinter;
namespace LimeReport { namespace LimeReport {
class PrintRange{ class PrintRange{
public: public:
int fromPage() const { return m_fromPage;} int fromPage() const { return m_fromPage;}
@ -61,7 +59,6 @@ private:
class DataSourceManager; class DataSourceManager;
class ReportEnginePrivate; class ReportEnginePrivate;
//class PageDesignIntf;
class LIMEREPORT_EXPORT ReportEngine : public QObject{ class LIMEREPORT_EXPORT ReportEngine : public QObject{
Q_OBJECT Q_OBJECT
@ -71,9 +68,8 @@ public:
explicit ReportEngine(QObject *parent = 0); explicit ReportEngine(QObject *parent = 0);
~ReportEngine(); ~ReportEngine();
bool printReport(QPrinter *printer=0); bool printReport(QPrinter *printer=0);
//void printReport(ReportPages pages, QPrinter &printer);
void printToFile(const QString& fileName); void printToFile(const QString& fileName);
//PageDesignIntf *createPreviewScene(QObject *parent = 0); bool printToPDF(const QString& fileName);
void previewReport(); void previewReport();
void designReport(); void designReport();
void setShowProgressDialog(bool value); void setShowProgressDialog(bool value);

View File

@ -71,6 +71,7 @@ public:
void clearReport(); void clearReport();
bool printReport(QPrinter *printer=0); bool printReport(QPrinter *printer=0);
void printToFile(const QString& fileName); void printToFile(const QString& fileName);
bool printToPDF(const QString& fileName);
void previewReport(); void previewReport();
void designReport(); void designReport();
void setSettings(QSettings* value); void setSettings(QSettings* value);

View File

@ -124,6 +124,7 @@ void ReportRender::initRenderPage()
if (!m_renderPageItem) { if (!m_renderPageItem) {
m_renderPageItem = new PageItemDesignIntf(m_patternPageItem->pageSize(), m_patternPageItem->pageRect()); m_renderPageItem = new PageItemDesignIntf(m_patternPageItem->pageSize(), m_patternPageItem->pageRect());
m_renderPageItem->initFromItem(m_patternPageItem); m_renderPageItem->initFromItem(m_patternPageItem);
m_renderPageItem->setItemMode(PreviewMode);
} }
} }
@ -144,18 +145,18 @@ void ReportRender::extractGroupsFunction(BandDesignIntf *band)
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item); ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item);
if (contentItem&&(contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}")))){ if (contentItem&&(contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}")))){
foreach(QString functionName, DataSourceManager::instance()->groupFunctionNames()){ foreach(QString functionName, DataSourceManager::instance()->groupFunctionNames()){
QRegExp rx(QString(GROUP_FUNCTION_RX).arg(functionName)); QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
QRegExp rxName(QString(GROUP_FUNCTION_NAME_RX).arg(functionName)); QRegExp rxName(QString(Const::GROUP_FUNCTION_NAME_RX).arg(functionName));
if (rx.indexIn(contentItem->content())>=0){ if (rx.indexIn(contentItem->content())>=0){
BandDesignIntf* dataBand = m_patternPageItem->bandByName(rx.cap(DATASOURCE_INDEX)); BandDesignIntf* dataBand = m_patternPageItem->bandByName(rx.cap(Const::DATASOURCE_INDEX));
if (dataBand){ if (dataBand){
GroupFunction* gf = datasources()->addGroupFunction(functionName,rx.cap(VALUE_INDEX),band->objectName(),dataBand->objectName()); GroupFunction* gf = datasources()->addGroupFunction(functionName,rx.cap(Const::VALUE_INDEX),band->objectName(),dataBand->objectName());
if (gf){ if (gf){
connect(dataBand,SIGNAL(bandRendered(BandDesignIntf*)),gf,SLOT(slotBandRendered(BandDesignIntf*))); connect(dataBand,SIGNAL(bandRendered(BandDesignIntf*)),gf,SLOT(slotBandRendered(BandDesignIntf*)));
} }
} else { } else {
GroupFunction* gf = datasources()->addGroupFunction(functionName,rx.cap(VALUE_INDEX),band->objectName(),rx.cap(DATASOURCE_INDEX)); GroupFunction* gf = datasources()->addGroupFunction(functionName,rx.cap(Const::VALUE_INDEX),band->objectName(),rx.cap(Const::DATASOURCE_INDEX));
gf->setInvalid(tr("Databand \"%1\" not found").arg(rx.cap(DATASOURCE_INDEX))); gf->setInvalid(tr("Databand \"%1\" not found").arg(rx.cap(Const::DATASOURCE_INDEX)));
} }
} else if (rxName.indexIn(contentItem->content())>=0){ } else if (rxName.indexIn(contentItem->content())>=0){
GroupFunction* gf = datasources()->addGroupFunction(functionName,rxName.cap(1),band->objectName(),""); GroupFunction* gf = datasources()->addGroupFunction(functionName,rxName.cap(1),band->objectName(),"");
@ -173,7 +174,7 @@ void ReportRender::replaceGroupsFunction(BandDesignIntf *band)
if (contentItem){ if (contentItem){
QString content = contentItem->content(); QString content = contentItem->content();
foreach(QString functionName, DataSourceManager::instance()->groupFunctionNames()){ foreach(QString functionName, DataSourceManager::instance()->groupFunctionNames()){
QRegExp rx(QString(GROUP_FUNCTION_RX).arg(functionName)); QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
if (rx.indexIn(content)>=0){ if (rx.indexIn(content)>=0){
content.replace(rx,QString("%1(%2,%3)").arg(functionName).arg('"'+rx.cap(4)+'"').arg('"'+band->objectName()+'"')); content.replace(rx,QString("%1(%2,%3)").arg(functionName).arg('"'+rx.cap(4)+'"').arg('"'+band->objectName()+'"'));
contentItem->setContent(content); contentItem->setContent(content);
@ -272,7 +273,7 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
renderGroupHeader(dataBand,bandDatasource); renderGroupHeader(dataBand,bandDatasource);
if (dataBand->tryToKeepTogether()) closeDataGroup(dataBand); if (dataBand->tryToKeepTogether()) closeDataGroup(dataBand);
} }
renderBand(dataBand->bandFooter()); renderBand(dataBand->bandFooter(),StartNewPage);
renderGroupFooter(dataBand); renderGroupFooter(dataBand);
//renderChildFooter(dataBand,PrintNotAlwaysPrintable); //renderChildFooter(dataBand,PrintNotAlwaysPrintable);
datasources()->deleteVariable(varName); datasources()->deleteVariable(varName);
@ -590,7 +591,7 @@ void ReportRender::startNewPage()
m_renderPageItem->setObjectName(QLatin1String("ReportPage")+QString::number(m_pageCount)); m_renderPageItem->setObjectName(QLatin1String("ReportPage")+QString::number(m_pageCount));
m_currentMaxHeight=m_renderPageItem->pageRect().height(); m_currentMaxHeight=m_renderPageItem->pageRect().height();
m_currentStartDataPos=m_patternPageItem->topMargin()*mmFACTOR; m_currentStartDataPos=m_patternPageItem->topMargin()*Const::mmFACTOR;
m_currentIndex=0; m_currentIndex=0;
renderPageHeader(m_patternPageItem); renderPageHeader(m_patternPageItem);

View File

@ -154,5 +154,9 @@
<file>images/logo.png</file> <file>images/logo.png</file>
<file alias="/images/copyright">images/cpyright_logo.png</file> <file alias="/images/copyright">images/cpyright_logo.png</file>
<file>images/logo_100.png</file> <file>images/logo_100.png</file>
<file alias="empty">images/empty.png</file>
<file alias="/images/hideLeftPanel">images/hideLeftPanel.png</file>
<file alias="/images/hideRightPanel">images/hideRightPanel.png</file>
<file alias="/images/pdf">images/PDF2.png</file>
</qresource> </qresource>
</RCC> </RCC>

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 Ui {
class ScriptBrowser;
}
namespace LimeReport{
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