0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00
This commit is contained in:
Arin Alexander 2017-04-20 21:10:31 +03:00
commit cbf205b728
29 changed files with 152 additions and 89 deletions

View File

@ -71,19 +71,19 @@ MainWindow::MainWindow(QWidget *parent) :
}; };
} }
LimeReport::ICallbackDatasource * callbackDatasource = report->dataManager()->createCallbackDatasouce("master"); LimeReport::ICallbackDatasource * callbackDatasource = report->dataManager()->createCallbackDatasource("master");
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)), connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
this, SLOT(slotGetCallbackData(LimeReport::CallbackInfo,QVariant&))); this, SLOT(slotGetCallbackData(LimeReport::CallbackInfo,QVariant&)));
connect(callbackDatasource, SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)), connect(callbackDatasource, SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)),
this, SLOT(slotChangePos(const LimeReport::CallbackInfo::ChangePosType&,bool&))); this, SLOT(slotChangePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)));
callbackDatasource = report->dataManager()->createCallbackDatasouce("detail"); callbackDatasource = report->dataManager()->createCallbackDatasource("detail");
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)), connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
this, SLOT(slotGetCallbackChildData(LimeReport::CallbackInfo,QVariant&))); this, SLOT(slotGetCallbackChildData(LimeReport::CallbackInfo,QVariant&)));
connect(callbackDatasource, SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)), connect(callbackDatasource, SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)),
this, SLOT(slotChangeChildPos(const LimeReport::CallbackInfo::ChangePosType&,bool&))); this, SLOT(slotChangeChildPos(const LimeReport::CallbackInfo::ChangePosType&,bool&)));
callbackDatasource = report->dataManager()->createCallbackDatasouce("oneSlotDS"); callbackDatasource = report->dataManager()->createCallbackDatasource("oneSlotDS");
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)), connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
this, SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&))); this, SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&)));

View File

@ -54,7 +54,7 @@ public:
virtual void removeModel(const QString& name) = 0; virtual void removeModel(const QString& name) = 0;
virtual bool containsDatasource(const QString& dataSourceName) = 0; virtual bool containsDatasource(const QString& dataSourceName) = 0;
virtual void clearUserVariables()=0; virtual void clearUserVariables()=0;
virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0; virtual ICallbackDatasource* createCallbackDatasource(const QString& name) = 0;
virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0; virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0;
//virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0; //virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0;
}; };

View File

@ -87,7 +87,7 @@ public:
void setShowProgressDialog(bool value); void setShowProgressDialog(bool value);
IDataSourceManager* dataManager(); IDataSourceManager* dataManager();
IScriptEngineManager* scriptManager(); IScriptEngineManager* scriptManager();
bool loadFromFile(const QString& fileName); bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange = false);
bool loadFromByteArray(QByteArray *data); bool loadFromByteArray(QByteArray *data);
bool loadFromString(const QString& data); bool loadFromString(const QString& data);
QString reportFileName(); QString reportFileName();

View File

@ -12,7 +12,7 @@ public:
virtual BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0); virtual BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0);
protected: protected:
QColor bandColor() const; QColor bandColor() const;
bool isUnique(){ return true;} virtual bool isUnique() const {return true;}
}; };
} // namespace LimeReport } // namespace LimeReport

View File

@ -43,7 +43,7 @@ class AlignmentPropItem : public ObjectPropItem
{ {
Q_OBJECT Q_OBJECT
public: public:
AlignmentPropItem():ObjectPropItem(){} AlignmentPropItem():ObjectPropItem(),m_horizEditor(NULL),m_vertEditor(NULL){}
AlignmentPropItem(QObject *object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly=true); AlignmentPropItem(QObject *object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value, ObjectPropItem* parent, bool readonly=true);
QString displayValue() const; QString displayValue() const;
void setPropertyValue(QVariant value); void setPropertyValue(QVariant value);

View File

@ -390,8 +390,8 @@ void HorizontalLayout::slotOnChildDestroy(QObject* child)
BaseDesignIntf* HorizontalLayout::findNext(BaseDesignIntf* item){ BaseDesignIntf* HorizontalLayout::findNext(BaseDesignIntf* item){
if (m_children.count()<childItems().size()-1){ if (m_children.count()<childItems().size()-1){
m_children.clear(); m_children.clear();
foreach (BaseDesignIntf* item, childBaseItems()) { foreach (BaseDesignIntf* childItem, childBaseItems()) {
m_children.append(item); m_children.append(childItem);
} }
} }
qSort(m_children.begin(),m_children.end(),lessThen); qSort(m_children.begin(),m_children.end(),lessThen);
@ -404,8 +404,8 @@ BaseDesignIntf* HorizontalLayout::findNext(BaseDesignIntf* item){
BaseDesignIntf* HorizontalLayout::findPrior(BaseDesignIntf* item){ BaseDesignIntf* HorizontalLayout::findPrior(BaseDesignIntf* item){
if (m_children.count()<childItems().size()-1){ if (m_children.count()<childItems().size()-1){
m_children.clear(); m_children.clear();
foreach (BaseDesignIntf* item, childBaseItems()) { foreach (BaseDesignIntf* childItem, childBaseItems()) {
m_children.append(item); m_children.append(childItem);
} }
} }
qSort(m_children.begin(),m_children.end(),lessThen); qSort(m_children.begin(),m_children.end(),lessThen);

View File

@ -63,7 +63,7 @@ QString HtmlContext::parseTag(QVector<Tag *> &storage, QString text, int &curPos
tagName.remove('>'); tagName.remove('>');
while (buff.contains(rx)){ while (buff.contains(rx)){
int pos=rx.indexIn(buff); pos=rx.indexIn(buff);
buff=buff.right(buff.length()-pos); buff=buff.right(buff.length()-pos);
curPos+=pos; curPos+=pos;
if (extractWord(rx.cap(0),1).compare(extractWord(tagName,1),Qt::CaseInsensitive)==0){ if (extractWord(rx.cap(0),1).compare(extractWord(tagName,1),Qt::CaseInsensitive)==0){

View File

@ -502,18 +502,20 @@ TextItem::TextPtr TextItem::textDocument() const
setTextFont(text,_font); setTextFont(text,_font);
} }
text->documentLayout(); //text->documentLayout();
if (m_lineSpacing != 1 || m_textIndent !=0 ){
for ( QTextBlock block = text->begin(); block.isValid(); block = block.next()) for ( QTextBlock block = text->begin(); block.isValid(); block = block.next())
{ {
QTextCursor tc = QTextCursor(block); QTextCursor tc = QTextCursor(block);
QTextBlockFormat fmt = block.blockFormat(); QTextBlockFormat fmt = block.blockFormat();
fmt.setTextIndent(m_textIndent); fmt.setTextIndent(m_textIndent);
if (fmt.lineHeight() != m_lineSpacing) {
if(fmt.lineHeight() != m_lineSpacing) { fmt.setLineHeight(m_lineSpacing,QTextBlockFormat::LineDistanceHeight);
fmt.setLineHeight(m_lineSpacing,QTextBlockFormat::LineDistanceHeight); }
tc.setBlockFormat( fmt ); tc.setBlockFormat( fmt );
} }
} }
return text; return text;

View File

@ -124,8 +124,8 @@ void TextItemEditor::initUI()
ui->twData->setModel(dm->datasourcesModel()); ui->twData->setModel(dm->datasourcesModel());
ui->twScriptEngine->setModel(se.model()); ui->twScriptEngine->setModel(se.model());
foreach(QString dsName,dm->dataSourceNames()){ foreach(const QString &dsName,dm->dataSourceNames()){
foreach(QString field, dm->fieldNames(dsName)){ foreach(const QString &field, dm->fieldNames(dsName)){
dataWords<<dsName+"."+field; dataWords<<dsName+"."+field;
} }
} }

View File

@ -1191,7 +1191,10 @@ void BaseDesignIntf::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QAction* a = menu.exec(event->screenPos()); QAction* a = menu.exec(event->screenPos());
if (a){ if (a){
if (a == cutAction) if (a == cutAction)
{
page->cut(); page->cut();
return;
}
if (a == copyAction) if (a == copyAction)
page->copy(); page->copy();
if (a == pasteAction) if (a == pasteAction)

View File

@ -51,7 +51,7 @@ class BaseDesignIntf;
class Marker : public QGraphicsItem{ class Marker : public QGraphicsItem{
public: public:
Marker(QGraphicsItem* parent=0):QGraphicsItem(parent){} Marker(QGraphicsItem* parent=0):QGraphicsItem(parent),m_object(NULL){}
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
void setRect(QRectF rect){prepareGeometryChange();m_rect=rect;} void setRect(QRectF rect){prepareGeometryChange();m_rect=rect;}
@ -266,7 +266,7 @@ public:
QColor borderColor() const; QColor borderColor() const;
void setBorderColor(const QColor &borderColor); void setBorderColor(const QColor &borderColor);
void setItemVisible(const bool& value); void setItemVisible(const bool& value);
virtual bool canContainChildren(){ return false;} virtual bool canContainChildren(){ return false;}
ReportSettings* reportSettings() const; ReportSettings* reportSettings() const;
void setReportSettings(ReportSettings *reportSettings); void setReportSettings(ReportSettings *reportSettings);
void setZValueProperty(qreal value); void setZValueProperty(qreal value);

View File

@ -299,7 +299,7 @@ int ModelToDataSource::columnCount()
QString ModelToDataSource::columnNameByIndex(int columnIndex) QString ModelToDataSource::columnNameByIndex(int columnIndex)
{ {
if (isInvalid()) return ""; if (isInvalid()) return "";
QString result = m_model->headerData(columnIndex,Qt::Horizontal, Qt::UserRole).isValid()? QString result = m_model->headerData(columnIndex,Qt::Horizontal, Qt::UserRole).isValid()?
m_model->headerData(columnIndex,Qt::Horizontal, Qt::UserRole).toString(): m_model->headerData(columnIndex,Qt::Horizontal, Qt::UserRole).toString():
m_model->headerData(columnIndex,Qt::Horizontal).toString(); m_model->headerData(columnIndex,Qt::Horizontal).toString();
@ -704,7 +704,6 @@ int CallbackDatasource::columnCount(){
int currIndex = 0; int currIndex = 0;
do { do {
QVariant columnName; QVariant columnName;
CallbackInfo info;
info.dataType = CallbackInfo::ColumnHeaderData; info.dataType = CallbackInfo::ColumnHeaderData;
info.index = currIndex; info.index = currIndex;
emit getCallbackData(info,columnName); emit getCallbackData(info,columnName);

View File

@ -318,7 +318,7 @@ void DataSourceManager::removeModel(const QString &name)
removeDatasource(name.toLower()); removeDatasource(name.toLower());
} }
ICallbackDatasource *DataSourceManager::createCallbackDatasouce(const QString& name) ICallbackDatasource *DataSourceManager::createCallbackDatasource(const QString& name)
{ {
ICallbackDatasource* ds = new CallbackDatasource(); ICallbackDatasource* ds = new CallbackDatasource();
IDataSourceHolder* holder = new CallbackDatasourceHolder(dynamic_cast<IDataSource*>(ds),true); IDataSourceHolder* holder = new CallbackDatasourceHolder(dynamic_cast<IDataSource*>(ds),true);

View File

@ -71,7 +71,7 @@ class DataSourceModel : public QAbstractItemModel{
Q_OBJECT Q_OBJECT
friend class DataSourceManager; friend class DataSourceManager;
public: public:
DataSourceModel():m_rootNode(new DataNode()){} DataSourceModel():m_dataManager(NULL),m_rootNode(new DataNode()){}
DataSourceModel(DataSourceManager* dataManager); DataSourceModel(DataSourceManager* dataManager);
~DataSourceModel(); ~DataSourceModel();
QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex index(int row, int column, const QModelIndex &parent) const;
@ -114,7 +114,7 @@ public:
void addProxy(const QString& name, QString master, QString detail, QList<FieldsCorrelation> fields); void addProxy(const QString& name, QString master, QString detail, QList<FieldsCorrelation> fields);
bool addModel(const QString& name, QAbstractItemModel *model, bool owned); bool addModel(const QString& name, QAbstractItemModel *model, bool owned);
void removeModel(const QString& name); void removeModel(const QString& name);
ICallbackDatasource* createCallbackDatasouce(const QString &name); ICallbackDatasource* createCallbackDatasource(const QString &name);
void registerDbCredentialsProvider(IDbCredentialsProvider *provider); void registerDbCredentialsProvider(IDbCredentialsProvider *provider);
void addCallbackDatasource(ICallbackDatasource *datasource, const QString &name); void addCallbackDatasource(ICallbackDatasource *datasource, const QString &name);
void setReportVariable(const QString& name, const QVariant& value); void setReportVariable(const QString& name, const QVariant& value);

View File

@ -54,7 +54,7 @@ public:
virtual void removeModel(const QString& name) = 0; virtual void removeModel(const QString& name) = 0;
virtual bool containsDatasource(const QString& dataSourceName) = 0; virtual bool containsDatasource(const QString& dataSourceName) = 0;
virtual void clearUserVariables()=0; virtual void clearUserVariables()=0;
virtual ICallbackDatasource* createCallbackDatasouce(const QString& name) = 0; virtual ICallbackDatasource* createCallbackDatasource(const QString& name) = 0;
virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0; virtual void registerDbCredentialsProvider(IDbCredentialsProvider* provider) = 0;
//virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0; //virtual void addCallbackDatasource(ICallbackDatasource* datasource, const QString& name) = 0;
}; };

View File

@ -1226,6 +1226,8 @@ void PageDesignIntf::copy()
if (shouldWrite) { if (shouldWrite) {
clipboard->setText(writer->saveToString()); clipboard->setText(writer->saveToString());
} }
delete writer;
} }
} }
@ -1304,7 +1306,7 @@ void PageDesignIntf::deleteSelected()
} }
void PageDesignIntf::cut() void PageDesignIntf::cut()
{ {
CommandIf::Ptr command = CutCommand::create(this); CommandIf::Ptr command = CutCommand::create(this);
saveCommand(command); saveCommand(command);
} }
@ -1727,8 +1729,8 @@ CommandIf::Ptr DeleteLayoutCommand::create(PageDesignIntf *page, LayoutDesignInt
DeleteLayoutCommand* command = new DeleteLayoutCommand(); DeleteLayoutCommand* command = new DeleteLayoutCommand();
command->setPage(page); command->setPage(page);
command->setItem(item); command->setItem(item);
foreach (BaseDesignIntf* item, item->childBaseItems()){ foreach (BaseDesignIntf* childItem, item->childBaseItems()){
command->m_childItems.append(item->objectName()); command->m_childItems.append(childItem->objectName());
} }
return CommandIf::Ptr(command); return CommandIf::Ptr(command);
} }
@ -1845,7 +1847,7 @@ CommandIf::Ptr CutCommand::create(PageDesignIntf *page)
foreach(QGraphicsItem * item, page->selectedItems()) { foreach(QGraphicsItem * item, page->selectedItems()) {
if (!dynamic_cast<PageItemDesignIntf*>(item)){ if (!dynamic_cast<PageItemDesignIntf*>(item)){
BaseDesignIntf *reportItem = dynamic_cast<BaseDesignIntf *>(item); BaseDesignIntf *reportItem = dynamic_cast<BaseDesignIntf *>(item);
if (reportItem) { if (reportItem) {
command->m_itemNames.push_back(reportItem->objectName()); command->m_itemNames.push_back(reportItem->objectName());
writer->putItem(reportItem); writer->putItem(reportItem);
@ -2169,7 +2171,7 @@ void PropertyItemAlignChangedCommand::undoIt()
if (reportItem && (reportItem->property(m_propertyName.toLatin1()) != m_oldValue)) { if (reportItem && (reportItem->property(m_propertyName.toLatin1()) != m_oldValue)) {
reportItem->setProperty(m_propertyName.toLatin1(), m_oldValue); reportItem->setProperty(m_propertyName.toLatin1(), m_oldValue);
} }
if (m_oldValue == BaseDesignIntf::DesignedItemAlign){ if (reportItem && (m_oldValue == BaseDesignIntf::DesignedItemAlign)){
reportItem->setPos(m_savedPos); reportItem->setPos(m_savedPos);
} }
} }

View File

@ -13,6 +13,7 @@ class PreviewReportWidgetPrivate
{ {
public: public:
PreviewReportWidgetPrivate(PreviewReportWidget* previewReportWidget): PreviewReportWidgetPrivate(PreviewReportWidget* previewReportWidget):
m_previewPage(NULL), m_report(NULL), m_zoomer(NULL),
m_currentPage(1), m_changingPage(false), m_priorScrolValue(0), m_scalePercent(50), m_currentPage(1), m_changingPage(false), m_priorScrolValue(0), m_scalePercent(50),
q_ptr(previewReportWidget) {} q_ptr(previewReportWidget) {}
bool pageIsVisible(); bool pageIsVisible();

View File

@ -138,6 +138,11 @@ void PreviewReportWindow::initPreview(int pagesCount)
m_pagesNavigator->setValue(1); m_pagesNavigator->setValue(1);
} }
void PreviewReportWindow::reloadPreview()
{
m_previewReportWidget->refreshPages();
}
void PreviewReportWindow::setSettings(QSettings* value) void PreviewReportWindow::setSettings(QSettings* value)
{ {
if (m_ownedSettings) if (m_ownedSettings)

View File

@ -63,6 +63,7 @@ public:
void setPages(ReportPages pages); void setPages(ReportPages pages);
void exec(); void exec();
void initPreview(int pagesCount); void initPreview(int pagesCount);
void reloadPreview();
void setSettings(QSettings* value); void setSettings(QSettings* value);
void setErrorMessages(const QStringList& value); void setErrorMessages(const QStringList& value);
void setToolBarVisible(bool value); void setToolBarVisible(bool value);

View File

@ -422,7 +422,7 @@ bool ReportDesignWidget::save()
bool ReportDesignWidget::loadFromFile(const QString &fileName) bool ReportDesignWidget::loadFromFile(const QString &fileName)
{ {
if (m_report->loadFromFile(fileName)){ if (m_report->loadFromFile(fileName,false)){
createTabs(); createTabs();
//connectPage(m_report->pageAt(0)); //connectPage(m_report->pageAt(0));
m_scriptEditor->setPlainText(m_report->scriptContext()->initScript()); m_scriptEditor->setPlainText(m_report->scriptContext()->initScript());

View File

@ -33,6 +33,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QApplication> #include <QApplication>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QFileSystemWatcher>
#include "time.h" #include "time.h"
@ -60,13 +61,15 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) :
m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false), m_printer(new QPrinter(QPrinter::HighResolution)), m_printerSelected(false),
m_showProgressDialog(true), m_reportName(""), m_activePreview(0), m_showProgressDialog(true), m_reportName(""), m_activePreview(0),
m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")), m_previewWindowIcon(":/report/images/logo32"), m_previewWindowTitle(tr("Preview")),
m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy") m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy"),
m_fileWatcher( new QFileSystemWatcher( this ) )
{ {
m_datasources = new DataSourceManager(this); m_datasources = new DataSourceManager(this);
m_datasources->setReportSettings(&m_reportSettings); m_datasources->setReportSettings(&m_reportSettings);
m_scriptEngineContext = new ScriptEngineContext(this); m_scriptEngineContext = new ScriptEngineContext(this);
m_datasources->setObjectName("datasources"); m_datasources->setObjectName("datasources");
connect(m_datasources,SIGNAL(loadCollectionFinished(QString)),this,SLOT(slotDataSourceCollectionLoaded(QString))); connect(m_datasources,SIGNAL(loadCollectionFinished(QString)),this,SLOT(slotDataSourceCollectionLoaded(QString)));
connect(m_fileWatcher,SIGNAL(fileChanged(const QString &)),this,SLOT(slotLoadFromFile(const QString &)));
} }
ReportEnginePrivate::~ReportEnginePrivate() ReportEnginePrivate::~ReportEnginePrivate()
@ -156,7 +159,7 @@ void ReportEnginePrivate::slotDataSourceCollectionLoaded(const QString &collecti
emit datasourceCollectionLoadFinished(collectionName); emit datasourceCollectionLoadFinished(collectionName);
} }
void ReportEnginePrivate::slotPreviewWindowDestroed(QObject* window) void ReportEnginePrivate::slotPreviewWindowDestroyed(QObject* window)
{ {
if (m_activePreview == window){ if (m_activePreview == window){
m_activePreview = 0; m_activePreview = 0;
@ -404,7 +407,7 @@ void ReportEnginePrivate::previewReport(PreviewHints hints)
w->setHideResultEditButton(resultIsEditable()); w->setHideResultEditButton(resultIsEditable());
m_activePreview = w; m_activePreview = w;
connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroed(QObject*))); connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*)));
qDebug()<<"render time ="<<start.msecsTo(QTime::currentTime()); qDebug()<<"render time ="<<start.msecsTo(QTime::currentTime());
w->exec(); w->exec();
} }
@ -475,6 +478,63 @@ void ReportEnginePrivate::setCurrentReportsDir(const QString &dirName)
m_reportsDir = dirName; m_reportsDir = dirName;
} }
bool ReportEnginePrivate::slotLoadFromFile(const QString &fileName)
{
PreviewReportWindow *currentPreview = qobject_cast<PreviewReportWindow *>(m_activePreview);
if (!QFile::exists(fileName))
{
if ( hasActivePreview() )
{
QMessageBox::information( NULL,
tr( "Report File Change" ),
tr( "The report file \"%1\" has changed names or been deleted.\n\nThis preview is no longer valid." ).arg( fileName )
);
clearReport();
currentPreview->close();
}
return false;
}
clearReport();
ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName);
reader->setPassPhrase(m_passPhrase);
if (reader->first()){
if (reader->readItem(this)){
m_fileName=fileName;
QFileInfo fi(fileName);
m_reportName = fi.fileName();
QString dbSettingFileName = fi.absolutePath()+"/"+fi.baseName()+".db";
if (QFile::exists(dbSettingFileName)){
QSettings dbcredentals(dbSettingFileName, QSettings::IniFormat);
foreach (ConnectionDesc* connection, dataManager()->conections()) {
if (!connection->keepDBCredentials()){
dbcredentals.beginGroup(connection->name());
connection->setUserName(dbcredentals.value("user").toString());
connection->setPassword(dbcredentals.value("password").toString());
dbcredentals.endGroup();
}
}
}
dataManager()->connectAutoConnections();
if ( hasActivePreview() )
{
currentPreview->reloadPreview();
}
return true;
};
}
m_lastError = reader->lastError();
return false;
}
void ReportEnginePrivate::cancelRender() void ReportEnginePrivate::cancelRender()
{ {
if (m_reportRender) if (m_reportRender)
@ -528,39 +588,20 @@ QSettings*ReportEnginePrivate::settings()
} }
} }
bool ReportEnginePrivate::loadFromFile(const QString &fileName) bool ReportEnginePrivate::loadFromFile(const QString &fileName, bool autoLoadPreviewOnChange)
{ {
if (!QFile::exists(fileName)) return false; // only watch one file at a time
if ( !m_fileWatcher->files().isEmpty() )
{
m_fileWatcher->removePaths( m_fileWatcher->files() );
}
clearReport(); if ( autoLoadPreviewOnChange )
{
m_fileWatcher->addPath( fileName );
}
ItemsReaderIntf::Ptr reader = FileXMLReader::create(fileName); return slotLoadFromFile( fileName );
reader->setPassPhrase(m_passPhrase);
if (reader->first()){
if (reader->readItem(this)){
m_fileName=fileName;
QFileInfo fi(fileName);
m_reportName = fi.fileName();
QString dbSettingFileName = fi.absolutePath()+"/"+fi.baseName()+".db";
if (QFile::exists(dbSettingFileName)){
QSettings dbcredentals(dbSettingFileName, QSettings::IniFormat);
foreach (ConnectionDesc* connection, dataManager()->conections()) {
if (!connection->keepDBCredentials()){
dbcredentals.beginGroup(connection->name());
connection->setUserName(dbcredentals.value("user").toString());
connection->setPassword(dbcredentals.value("password").toString());
dbcredentals.endGroup();
}
}
}
dataManager()->connectAutoConnections();
return true;
};
}
m_lastError = reader->lastError();
return false;
} }
bool ReportEnginePrivate::loadFromByteArray(QByteArray* data, const QString &name){ bool ReportEnginePrivate::loadFromByteArray(QByteArray* data, const QString &name){
@ -899,10 +940,10 @@ IScriptEngineManager *ReportEngine::scriptManager()
return d->scriptManagerIntf(); return d->scriptManagerIntf();
} }
bool ReportEngine::loadFromFile(const QString &fileName) bool ReportEngine::loadFromFile(const QString &fileName, bool autoLoadPreviewOnChange)
{ {
Q_D(ReportEngine); Q_D(ReportEngine);
return d->loadFromFile(fileName); return d->loadFromFile(fileName, autoLoadPreviewOnChange);
} }
bool ReportEngine::loadFromByteArray(QByteArray* data){ bool ReportEngine::loadFromByteArray(QByteArray* data){

View File

@ -87,7 +87,7 @@ public:
void setShowProgressDialog(bool value); void setShowProgressDialog(bool value);
IDataSourceManager* dataManager(); IDataSourceManager* dataManager();
IScriptEngineManager* scriptManager(); IScriptEngineManager* scriptManager();
bool loadFromFile(const QString& fileName); bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange = false);
bool loadFromByteArray(QByteArray *data); bool loadFromByteArray(QByteArray *data);
bool loadFromString(const QString& data); bool loadFromString(const QString& data);
QString reportFileName(); QString reportFileName();

View File

@ -42,6 +42,8 @@
#include "serializators/lrstorageintf.h" #include "serializators/lrstorageintf.h"
#include "lrscriptenginemanager.h" #include "lrscriptenginemanager.h"
class QFileSystemWatcher;
namespace LimeReport{ namespace LimeReport{
class PageDesignIntf; class PageDesignIntf;
@ -91,7 +93,7 @@ public:
void setSettings(QSettings* value); void setSettings(QSettings* value);
void setShowProgressDialog(bool value){m_showProgressDialog = value;} void setShowProgressDialog(bool value){m_showProgressDialog = value;}
QSettings* settings(); QSettings* settings();
bool loadFromFile(const QString& fileName); bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange);
bool loadFromByteArray(QByteArray *data, const QString& name = ""); bool loadFromByteArray(QByteArray *data, const QString& name = "");
bool loadFromString(const QString& report, const QString& name = ""); bool loadFromString(const QString& report, const QString& name = "");
QString reportFileName(){return m_fileName;} QString reportFileName(){return m_fileName;}
@ -138,13 +140,14 @@ signals:
void onSave(); void onSave();
void saveFinished(); void saveFinished();
public slots: public slots:
bool slotLoadFromFile(const QString& fileName);
void cancelRender(); void cancelRender();
protected: protected:
PageDesignIntf* createPage(const QString& pageName=""); PageDesignIntf* createPage(const QString& pageName="");
protected slots: protected slots:
void slotDataSourceCollectionLoaded(const QString& collectionName); void slotDataSourceCollectionLoaded(const QString& collectionName);
private slots: private slots:
void slotPreviewWindowDestroed(QObject *window); void slotPreviewWindowDestroyed(QObject *window);
private: private:
//ICollectionContainer //ICollectionContainer
virtual QObject* createElement(const QString&,const QString&); virtual QObject* createElement(const QString&,const QString&);
@ -178,6 +181,8 @@ private:
bool m_reportRendering; bool m_reportRendering;
bool m_resultIsEditable; bool m_resultIsEditable;
QString m_passPhrase; QString m_passPhrase;
QFileSystemWatcher *m_fileWatcher;
}; };
} }

View File

@ -264,7 +264,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
BandDesignIntf* lastRenderedBand = 0; BandDesignIntf* lastRenderedBand = 0;
for (int i=0;i<m_patternPageItem->dataBandCount() && !m_renderCanceled;i++){ for (int i=0;i<m_patternPageItem->dataBandCount() && !m_renderCanceled;i++){
lastRenderedBand = m_patternPageItem->dataBandAt(i); lastRenderedBand = m_patternPageItem->dataBandAt(i);
initDatasource(lastRenderedBand->datasourceName()); initDatasource(lastRenderedBand->datasourceName());
renderDataBand(lastRenderedBand); renderDataBand(lastRenderedBand);
if (i<m_patternPageItem->dataBandCount()-1) closeFooterGroup(lastRenderedBand); if (i<m_patternPageItem->dataBandCount()-1) closeFooterGroup(lastRenderedBand);
} }
@ -273,7 +273,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
renderBand(reportFooter, 0, StartNewPageAsNeeded); renderBand(reportFooter, 0, StartNewPageAsNeeded);
if (lastRenderedBand && lastRenderedBand->keepFooterTogether()) if (lastRenderedBand && lastRenderedBand->keepFooterTogether())
closeFooterGroup(lastRenderedBand); closeFooterGroup(lastRenderedBand);
BandDesignIntf* tearOffBand = m_patternPageItem->bandByType(BandDesignIntf::TearOffBand); BandDesignIntf* tearOffBand = m_patternPageItem->bandByType(BandDesignIntf::TearOffBand);
if (tearOffBand) if (tearOffBand)
renderBand(tearOffBand, 0, StartNewPageAsNeeded); renderBand(tearOffBand, 0, StartNewPageAsNeeded);
@ -360,7 +360,7 @@ void ReportRender::extractGroupsFunction(BandDesignIntf *band)
foreach(BaseDesignIntf* item,band->childBaseItems()){ foreach(BaseDesignIntf* item,band->childBaseItems()){
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, m_datasources->groupFunctionNames()){ foreach(const QString &functionName, m_datasources->groupFunctionNames()){
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
QRegExp rxName(QString(Const::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){
@ -413,7 +413,7 @@ void ReportRender::replaceGroupsFunction(BandDesignIntf *band)
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item); ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item);
if (contentItem){ if (contentItem){
QString content = contentItem->content(); QString content = contentItem->content();
foreach(QString functionName, m_datasources->groupFunctionNames()){ foreach(const QString &functionName, m_datasources->groupFunctionNames()){
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
if (rx.indexIn(content)>=0){ if (rx.indexIn(content)>=0){
int pos = 0; int pos = 0;
@ -483,6 +483,7 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
BandDesignIntf* upperPart = dynamic_cast<BandDesignIntf*>(bandClone->cloneUpperPart(m_maxHeightByColumn[m_currentColumn])); BandDesignIntf* upperPart = dynamic_cast<BandDesignIntf*>(bandClone->cloneUpperPart(m_maxHeightByColumn[m_currentColumn]));
registerBand(upperPart); registerBand(upperPart);
delete bandClone; delete bandClone;
bandClone = NULL;
} }
} else { } else {
@ -500,6 +501,7 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
BandDesignIntf* upperPart = dynamic_cast<BandDesignIntf*>(bandClone->cloneUpperPart(m_maxHeightByColumn[m_currentColumn])); BandDesignIntf* upperPart = dynamic_cast<BandDesignIntf*>(bandClone->cloneUpperPart(m_maxHeightByColumn[m_currentColumn]));
registerBand(upperPart); registerBand(upperPart);
delete bandClone; delete bandClone;
bandClone = NULL;
}; };
} else { } else {
bandClone->setHeight(m_maxHeightByColumn[m_currentColumn]); bandClone->setHeight(m_maxHeightByColumn[m_currentColumn]);
@ -522,9 +524,12 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
void ReportRender::renderDataBand(BandDesignIntf *dataBand) void ReportRender::renderDataBand(BandDesignIntf *dataBand)
{ {
if (dataBand == NULL )
return;
IDataSource* bandDatasource = 0; IDataSource* bandDatasource = 0;
m_lastRenderedFooter = 0; m_lastRenderedFooter = 0;
if (dataBand && !dataBand->datasourceName().isEmpty()) if (!dataBand->datasourceName().isEmpty())
bandDatasource = datasources()->dataSource(dataBand->datasourceName()); bandDatasource = datasources()->dataSource(dataBand->datasourceName());
BandDesignIntf* header = dataBand->bandHeader(); BandDesignIntf* header = dataBand->bandHeader();
@ -775,7 +780,7 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
closeDataGroup(band); closeDataGroup(band);
} }
if (!gb->isStarted()){ if (gb && !gb->isStarted()){
if (band->reprintOnEachPage()) if (band->reprintOnEachPage())
m_reprintableBands.append(band); m_reprintableBands.append(band);
gb->startGroup(m_datasources); gb->startGroup(m_datasources);
@ -1325,7 +1330,7 @@ void ReportRender::savePage(bool isLast)
m_renderedPages.append(PageItemDesignIntf::Ptr(m_renderPageItem)); m_renderedPages.append(PageItemDesignIntf::Ptr(m_renderPageItem));
m_pageCount++; m_pageCount++;
emit pageRendered(m_pageCount); emit pageRendered(m_pageCount);
if (isLast){ if (isLast){
BandDesignIntf* ph = m_renderPageItem->bandByType(BandDesignIntf::PageHeader); BandDesignIntf* ph = m_renderPageItem->bandByType(BandDesignIntf::PageHeader);
if (ph && !ph->property("printOnLastPage").toBool()){ if (ph && !ph->property("printOnLastPage").toBool()){

View File

@ -36,7 +36,7 @@
#include "lrglobal.h" #include "lrglobal.h"
LimeReport::PropertyDelegate::PropertyDelegate(QObject *parent) LimeReport::PropertyDelegate::PropertyDelegate(QObject *parent)
:QItemDelegate(parent), m_editingItem(0), m_isEditing(false) :QItemDelegate(parent), m_objectInspector(NULL), m_editingItem(0), m_isEditing(false)
{} {}
void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const void LimeReport::PropertyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const

View File

@ -37,7 +37,7 @@ class EnumPropItem : public ObjectPropItem
{ {
Q_OBJECT Q_OBJECT
public: public:
EnumPropItem():ObjectPropItem(){} EnumPropItem():ObjectPropItem(), m_settingValue(false){}
EnumPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly) EnumPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly)
:ObjectPropItem(object, objects, name, displayName, value, parent, readonly),m_settingValue(false){} :ObjectPropItem(object, objects, name, displayName, value, parent, readonly),m_settingValue(false){}
EnumPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly, QVector<int> acceptableValues) EnumPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly, QVector<int> acceptableValues)

View File

@ -87,7 +87,7 @@ class FontPropItem : public ObjectPropItem
{ {
Q_OBJECT Q_OBJECT
public: public:
FontPropItem():ObjectPropItem(){} FontPropItem():ObjectPropItem(), m_pointSize(NULL), m_bold(NULL), m_italic(NULL), m_underline(NULL), m_family(NULL) {}
FontPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly); FontPropItem(QObject* object, ObjectsList* objects, const QString& name, const QString& displayName, const QVariant& value,ObjectPropItem* parent, bool readonly);
QWidget* createProperyEditor(QWidget *parent) const; QWidget* createProperyEditor(QWidget *parent) const;
QString displayValue() const; QString displayValue() const;

View File

@ -35,7 +35,7 @@
namespace LimeReport{ namespace LimeReport{
ObjectBrowser::ObjectBrowser(QWidget *parent) ObjectBrowser::ObjectBrowser(QWidget *parent)
:QWidget(parent), m_changingItemSelection(false) :QWidget(parent), m_report(NULL), m_mainWindow(NULL), m_changingItemSelection(false)
{ {
QVBoxLayout *layout = new QVBoxLayout(this); QVBoxLayout *layout = new QVBoxLayout(this);
setLayout(layout); setLayout(layout);

View File

@ -106,7 +106,6 @@ bool XMLReader::readItem(QObject *item)
void XMLReader::readItemFromNode(QObject* item,QDomElement *node) void XMLReader::readItemFromNode(QObject* item,QDomElement *node)
{ {
ObjectLoadingStateIntf* lf = dynamic_cast<ObjectLoadingStateIntf*>(item); ObjectLoadingStateIntf* lf = dynamic_cast<ObjectLoadingStateIntf*>(item);
if(lf) lf->objectLoadStarted(); if(lf) lf->objectLoadStarted();
for (int i=0;i<node->childNodes().count();i++){ for (int i=0;i<node->childNodes().count();i++){
@ -123,8 +122,8 @@ void XMLReader::readItemFromNode(QObject* item,QDomElement *node)
BaseDesignIntf* baseObj = dynamic_cast<BaseDesignIntf*>(item); BaseDesignIntf* baseObj = dynamic_cast<BaseDesignIntf*>(item);
if(baseObj) { if(baseObj) {
foreach(QGraphicsItem* item,baseObj->childItems()){ foreach(QGraphicsItem* childItem,baseObj->childItems()){
BaseDesignIntf* baseItem = dynamic_cast<BaseDesignIntf*>(item); BaseDesignIntf* baseItem = dynamic_cast<BaseDesignIntf*>(childItem);
if (baseItem) baseItem->parentObjectLoadFinished(); if (baseItem) baseItem->parentObjectLoadFinished();
} }
} }