0
0
mirror of https://github.com/fralx/LimeReport.git synced 2025-12-14 00:41:02 +03:00

added border for page and lrgroupbands has a sorting property

This commit is contained in:
yanis60
2024-05-25 21:10:14 +01:00
parent 9d10ad6227
commit 7b7d4add4e
78 changed files with 31670 additions and 1093 deletions

View File

@@ -62,7 +62,7 @@ namespace LimeReport{
GroupBandHeader::GroupBandHeader(QObject *owner, QGraphicsItem *parent)
: BandDesignIntf(BandDesignIntf::GroupHeader, xmlTagHeader, owner,parent),
m_groupFiledName(""), m_groupStarted(false), m_resetPageNumber(false)
m_groupFiledName(""), m_groupStarted(false), m_resetPageNumber(false),m_sortFieldNameBy(Qt::AscendingOrder)
{
setBandTypeText(tr("GroupHeader"));
setFixedPos(false);
@@ -95,7 +95,10 @@ void GroupBandHeader::startGroup(DataSourceManager* dataManager)
if (dataManager->containsDatasource(datasourceName)){
IDataSource* ds = dataManager->dataSource(datasourceName);
if (ds && ds->columnIndexByName(m_groupFiledName)!=-1)
{
m_groupFieldValue=ds->data(m_groupFiledName);
}
}
if (!m_condition.isEmpty()) m_conditionValue = calcCondition(dataManager);
@@ -149,6 +152,7 @@ bool GroupBandHeader::isNeedToClose(DataSourceManager* dataManager)
QString datasourceName = findDataSourceName(parentBand());
if (dataManager->containsDatasource(datasourceName)){
IDataSource* ds = dataManager->dataSource(datasourceName);
if (ds){
if (ds->data(m_groupFiledName).isNull() && m_groupFieldValue.isNull()) return false;
if (!ds->data(m_groupFiledName).isValid()) return false;

View File

@@ -32,12 +32,14 @@
#include "lrbanddesignintf.h"
#include "lrdesignelementsfactory.h"
#include "qnamespace.h"
namespace LimeReport{
class GroupBandHeader : public BandDesignIntf, public IGroupBand{
Q_OBJECT
Q_PROPERTY(QString groupFieldName READ groupFieldName WRITE setGroupFieldName)
Q_PROPERTY(Qt::SortOrder SortFieldNameBy READ SortFieldNameBy WRITE setSortFieldNameBy)
Q_PROPERTY(bool splittable READ isSplittable WRITE setSplittable )
Q_PROPERTY(bool keepGroupTogether READ tryToKeepTogether WRITE setTryToKeepTogether)
Q_PROPERTY(bool startNewPage READ startNewPage WRITE setStartNewPage)
@@ -60,6 +62,8 @@ public:
bool isGroupHeader() const {return true;}
QString condition() const;
void setCondition(const QString &condition);
Qt::SortOrder SortFieldNameBy(){return m_sortFieldNameBy;};
void setSortFieldNameBy(Qt::SortOrder sortOrder){m_sortFieldNameBy = sortOrder;}
private:
virtual BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0);
void startGroup(DataSourceManager* dataManager);
@@ -77,6 +81,7 @@ private:
bool m_resetPageNumber;
QString m_condition;
QString m_conditionValue;
Qt::SortOrder m_sortFieldNameBy;
};
class GroupBandFooter : public BandDesignIntf{

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@@ -15,12 +15,13 @@ BorderEditor::BorderEditor(QWidget *parent) :
connect(
ui->borderFrame, SIGNAL(borderSideClicked(LimeReport::BaseDesignIntf::BorderSide, bool)),
this, SLOT(checkToolButtons(LimeReport::BaseDesignIntf::BorderSide, bool))
);
);
}
void BorderEditor::loadItem(LimeReport::BaseDesignIntf *item)
{
m_item = item;
qDebug()<<item->metaObject()->className();
emit ui->borderFrame->borderSideClicked(LimeReport::BaseDesignIntf::BorderSide::TopLine,
item->borderLines() & LimeReport::BaseDesignIntf::TopLine);
emit ui->borderFrame->borderSideClicked(LimeReport::BaseDesignIntf::BorderSide::LeftLine,
@@ -68,6 +69,11 @@ double BorderEditor::borderWidth()
return m_borderWidth;
}
bool BorderEditor::isPage()
{
return QString(m_item->metaObject()->className()) == "LimeReport::PageItemDesignIntf";
}
BorderEditor::~BorderEditor()
{
delete ui;
@@ -93,18 +99,18 @@ void BorderEditor::checkToolButtons(LimeReport::BaseDesignIntf::BorderSide side,
{
switch(side)
{
case BaseDesignIntf::BorderSide::TopLine:
ui->topLine->setChecked(check);
break;
case BaseDesignIntf::BorderSide::BottomLine:
ui->bottomLine->setChecked(check);
break;
case BaseDesignIntf::BorderSide::LeftLine:
ui->leftLine->setChecked(check);
break;
case BaseDesignIntf::BorderSide::RightLine:
ui->rightLine->setChecked(check);
break;
case BaseDesignIntf::BorderSide::TopLine:
ui->topLine->setChecked(check);
break;
case BaseDesignIntf::BorderSide::BottomLine:
ui->bottomLine->setChecked(check);
break;
case BaseDesignIntf::BorderSide::LeftLine:
ui->leftLine->setChecked(check);
break;
case BaseDesignIntf::BorderSide::RightLine:
ui->rightLine->setChecked(check);
break;
}
}

View File

@@ -22,6 +22,7 @@ public:
LimeReport::BaseDesignIntf::BorderStyle borderStyle();
QString borderColor();
double borderWidth();
bool isPage();
~BorderEditor();
private slots:

View File

@@ -58,8 +58,8 @@ namespace LimeReport{
TextItem::TextItem(QObject *owner, QGraphicsItem *parent)
: ContentItemDesignIntf(xmlTag,owner,parent), m_angle(Angle0), m_trimValue(true), m_allowHTML(false),
m_allowHTMLInFields(false), m_replaceCarriageReturns(false), m_followTo(""), m_follower(0), m_textIndent(0),
m_textLayoutDirection(Qt::LayoutDirectionAuto), m_hideIfEmpty(false), m_fontLetterSpacing(0)
m_allowHTMLInFields(false), m_replaceCarriageReturns(false), m_followTo(""), m_follower(0), m_textIndent(0),
m_textLayoutDirection(Qt::LayoutDirectionAuto), m_hideIfEmpty(false), m_fontLetterSpacing(0)
{
PageItemDesignIntf* pageItem = dynamic_cast<PageItemDesignIntf*>(parent);
BaseDesignIntf* parentItem = dynamic_cast<BaseDesignIntf*>(parent);
@@ -77,10 +77,6 @@ TextItem::TextItem(QObject *owner, QGraphicsItem *parent)
TextItem::~TextItem(){}
int TextItem::fakeMarginSize() const{
return marginSize()+5;
}
void TextItem::preparePopUpMenu(QMenu &menu)
{
QAction* editAction = menu.addAction(QIcon(":/report/images/edit_pecil2.png"),tr("Edit"));
@@ -179,62 +175,62 @@ void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, Q
qreal hOffset = 0, vOffset = 0;
switch (m_angle){
case Angle0:
hOffset = fakeMarginSize();
if ((tmpSize.height() > 0) && (m_alignment & Qt::AlignVCenter)){
vOffset = tmpSize.height() / 2;
}
if ((tmpSize.height() > 0) && (m_alignment & Qt::AlignBottom)) // allow html
vOffset = tmpSize.height();
painter->translate(hOffset,vOffset);
case Angle0:
hOffset = marginSize();
if ((tmpSize.height() > 0) && (m_alignment & Qt::AlignVCenter)){
vOffset = tmpSize.height() / 2;
}
if ((tmpSize.height() > 0) && (m_alignment & Qt::AlignBottom)) // allow html
vOffset = tmpSize.height();
painter->translate(hOffset,vOffset);
break;
case Angle90:
hOffset = width() - fakeMarginSize();
vOffset = fakeMarginSize();
if (m_alignment & Qt::AlignVCenter){
hOffset = (width() - text->size().height()) / 2 + text->size().height();
}
case Angle90:
hOffset = width() - marginSize();
vOffset = marginSize();
if (m_alignment & Qt::AlignVCenter){
hOffset = (width() - text->size().height()) / 2 + text->size().height();
}
if (m_alignment & Qt::AlignBottom){
hOffset = (text->size().height());
}
painter->translate(hOffset,vOffset);
painter->rotate(90);
if (m_alignment & Qt::AlignBottom){
hOffset = (text->size().height());
}
painter->translate(hOffset,vOffset);
painter->rotate(90);
break;
case Angle180:
hOffset = width() - fakeMarginSize();
vOffset = height() - fakeMarginSize();
if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){
vOffset = tmpSize.height() / 2+ text->size().height();
}
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)){
vOffset = (text->size().height());
}
painter->translate(hOffset,vOffset);
painter->rotate(180);
case Angle180:
hOffset = width() - marginSize();
vOffset = height() - marginSize();
if ((tmpSize.width()>0) && (m_alignment & Qt::AlignVCenter)){
vOffset = tmpSize.height() / 2+ text->size().height();
}
if ((tmpSize.height()>0) && (m_alignment & Qt::AlignBottom)){
vOffset = (text->size().height());
}
painter->translate(hOffset,vOffset);
painter->rotate(180);
break;
case Angle270:
hOffset = fakeMarginSize();
vOffset = height()-fakeMarginSize();
if (m_alignment & Qt::AlignVCenter){
hOffset = (width() - text->size().height())/2;
}
case Angle270:
hOffset = marginSize();
vOffset = height()-marginSize();
if (m_alignment & Qt::AlignVCenter){
hOffset = (width() - text->size().height())/2;
}
if (m_alignment & Qt::AlignBottom){
hOffset = (width() - text->size().height());
}
painter->translate(hOffset,vOffset);
painter->rotate(270);
if (m_alignment & Qt::AlignBottom){
hOffset = (width() - text->size().height());
}
painter->translate(hOffset,vOffset);
painter->rotate(270);
break;
case Angle45:
painter->translate(width()/2,0);
painter->rotate(45);
text->setTextWidth(sqrt(2*(pow(width()/2,2))));
case Angle45:
painter->translate(width()/2,0);
painter->rotate(45);
text->setTextWidth(sqrt(2*(pow(width()/2,2))));
break;
case Angle315:
painter->translate(0,height()/2);
painter->rotate(315);
text->setTextWidth(sqrt(2*(pow(height()/2,2))));
case Angle315:
painter->translate(0,height()/2);
painter->rotate(315);
text->setTextWidth(sqrt(2*(pow(height()/2,2))));
break;
}
@@ -321,7 +317,7 @@ void TextItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, i
initTextSizes();
if (m_textSize.width()>width() && ((m_autoWidth==MaxWordLength)||(m_autoWidth==MaxStringLength))){
setWidth(m_textSize.width() + fakeMarginSize()*2);
setWidth(m_textSize.width() + marginSize()*2);
}
if (m_textSize.height()>height()) {
@@ -338,22 +334,22 @@ void TextItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, i
void TextItem::updateLayout()
{
// m_layout.setFont(transformToSceneFont(font()));
// m_layout.setText(content());
// qreal linePos = 0;
// m_layout.beginLayout();
// while(true){
// QTextLine line = m_layout.createLine();
// if (!line.isValid()) break;
// line.setLineWidth(width()-marginSize()*2);
// line.setPosition(QPoint(marginSize(),linePos));
// linePos+=line.height();
// }
// m_layout.endLayout();
// m_layout.setFont(transformToSceneFont(font()));
// m_layout.setText(content());
// qreal linePos = 0;
// m_layout.beginLayout();
// while(true){
// QTextLine line = m_layout.createLine();
// if (!line.isValid()) break;
// line.setLineWidth(width()-marginSize()*2);
// line.setPosition(QPoint(marginSize(),linePos));
// linePos+=line.height();
// }
// m_layout.endLayout();
}
bool TextItem::isNeedExpandContent() const
{
{
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
QRegExp rx("$*\\{[^{]*\\}");
#else
@@ -380,21 +376,21 @@ QString TextItem::replaceReturns(QString text) const
void TextItem::setTextFont(TextPtr text, const QFont& value) const {
text->setDefaultFont(value);
if ((m_angle==Angle0)||(m_angle==Angle180)){
text->setTextWidth(rect().width()-fakeMarginSize()*2);
text->setTextWidth(rect().width()-marginSize()*2);
} else {
text->setTextWidth(rect().height()-fakeMarginSize()*2);
text->setTextWidth(rect().height()-marginSize()*2);
}
}
void TextItem::adaptFontSize(TextPtr text) const{
QFont _font = transformToSceneFont(font());
do{
// qApp->processEvents();
// qApp->processEvents();
setTextFont(text,_font);
if (_font.pixelSize()>2)
_font.setPixelSize(_font.pixelSize()-1);
else break;
} while(text->size().height()>this->height() || text->size().width()>(this->width()) - fakeMarginSize() * 2);
} while(text->size().height()>this->height() || text->size().width()>(this->width()) - marginSize() * 2);
}
int TextItem::underlineLineSize() const
@@ -419,8 +415,8 @@ void TextItem::setLineSpacing(int value)
{
int oldValue = m_lineSpacing;
m_lineSpacing = value;
// if (autoHeight())
// initTextSizes();
// if (autoHeight())
// initTextSizes();
update();
notify("lineSpacing",oldValue,value);
}
@@ -473,40 +469,40 @@ QString TextItem::formatFieldValue()
if (m_valueType != Default) {
switch (m_valueType) {
case DateTime:
{
QDateTime dt = QDateTime::fromString(value.toString(), Qt::ISODate);
value = (dt.isValid() ? QVariant(dt) : m_varValue);
break;
}
{
QDateTime dt = QDateTime::fromString(value.toString(), Qt::ISODate);
value = (dt.isValid() ? QVariant(dt) : m_varValue);
break;
}
case Double:
{
bool bOk = false;
double dbl = value.toDouble(&bOk);
value = (bOk ? QVariant(dbl) : m_varValue);
}
{
bool bOk = false;
double dbl = value.toDouble(&bOk);
value = (bOk ? QVariant(dbl) : m_varValue);
}
default: break;
}
}
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
switch (value.type()) {
case QVariant::Date:
case QVariant::DateTime:
return formatDateTime(value.toDateTime());
case QVariant::Double:
return formatNumber(value.toDouble());
default:
return value.toString();
case QVariant::Date:
case QVariant::DateTime:
return formatDateTime(value.toDateTime());
case QVariant::Double:
return formatNumber(value.toDouble());
default:
return value.toString();
}
#else
switch (value.typeId()) {
case QMetaType::QDate:
case QMetaType::QDateTime:
return formatDateTime(value.toDateTime());
case QMetaType::Double:
return formatNumber(value.toDouble());
default:
return value.toString();
case QMetaType::QDate:
case QMetaType::QDateTime:
return formatDateTime(value.toDateTime());
case QMetaType::Double:
return formatNumber(value.toDouble());
default:
return value.toString();
}
#endif
@@ -679,7 +675,7 @@ void TextItem::setFollowTo(const QString &followTo)
tr("TextItem \" %1 \" already has folower \" %2 \" ")
.arg(fi->objectName())
.arg(fi->follower()->objectName())
);
);
notify("followTo",followTo,"");
}
} else if (m_followTo != ""){
@@ -688,7 +684,7 @@ void TextItem::setFollowTo(const QString &followTo)
tr("Error"),
tr("TextItem \" %1 \" not found!")
.arg(m_followTo)
);
);
notify("followTo",followTo,"");
}
}
@@ -774,13 +770,13 @@ void TextItem::setAllowHTML(bool allowHTML)
{
if (m_allowHTML!=allowHTML){
m_allowHTML = allowHTML;
// if (m_text){
// if (allowHTML)
// m_text->setHtml(m_strText);
// else
// m_text->setPlainText(m_strText);
// update();
// }
// if (m_text){
// if (allowHTML)
// m_text->setHtml(m_strText);
// else
// m_text->setPlainText(m_strText);
// update();
// }
update();
notify("allowHTML",!m_allowHTML,allowHTML);
}
@@ -811,9 +807,9 @@ bool TextItem::isNeedUpdateSize(RenderPass pass) const
}
bool res = (m_textSize.height()>geometry().height()&&autoHeight()) ||
(m_textSize.width()>geometry().width()&&autoWidth()) ||
m_follower ||
isNeedExpandContent();
(m_textSize.width()>geometry().width()&&autoWidth()) ||
m_follower ||
isNeedExpandContent();
return res;
}
@@ -896,7 +892,7 @@ void TextItem::setAdaptFontToSize(bool value)
if (m_adaptFontToSize!=value){
bool oldValue = m_adaptFontToSize;
m_adaptFontToSize=value;
// initText();
// initText();
invalidateRect(rect());
notify("updateFontToSize",oldValue,value);
}
@@ -918,10 +914,10 @@ QString TextItem::extractText(QTextBlock& curBlock, int height){
linesHeight += curBlock.layout()->lineAt(curLine).height() + lineSpacing();
if (height > 0 && linesHeight > (height-borderLineSize() * 2)) {goto loop_exit;}
resultText += curBlock.text().mid(curBlock.layout()->lineAt(curLine).textStart(),
curBlock.layout()->lineAt(curLine).textLength());
curBlock.layout()->lineAt(curLine).textLength());
}
}
loop_exit: return resultText;
loop_exit: return resultText;
}
QString TextItem::getTextPart(int height, int skipHeight){
@@ -1003,10 +999,10 @@ BaseDesignIntf *TextItem::cloneEmpty(int height, QObject *owner, QGraphicsItem *
void TextItem::objectLoadFinished()
{
ItemDesignIntf::objectLoadFinished();
// if (itemMode() == DesignMode || !isNeedExpandContent()){
// if (autoHeight() && autoWidth())
// initTextSizes();
// }
// if (itemMode() == DesignMode || !isNeedExpandContent()){
// if (autoHeight() && autoWidth())
// initTextSizes();
// }
}
void TextItem::setTextItemFont(QFont value)
@@ -1023,8 +1019,8 @@ void TextItem::setTextItemFont(QFont value)
QWidget *TextItem::defaultEditor()
{
QSettings* l_settings = (page()->settings() != 0) ?
page()->settings() :
(page()->reportEditor()!=0) ? page()->reportEditor()->settings() : 0;
page()->settings() :
(page()->reportEditor()!=0) ? page()->reportEditor()->settings() : 0;
QWidget* editor = new TextItemEditor(this,page(),l_settings);
editor->setAttribute(Qt::WA_DeleteOnClose);
return editor;

View File

@@ -177,7 +177,7 @@ public:
void setTextLayoutDirection(const Qt::LayoutDirection &textLayoutDirection);
void setWatermark(bool watermark);
bool isReplaceCarriageReturns() const;
void setReplaceCarriageReturns(bool isReplaceCarriageReturns);
@@ -192,7 +192,6 @@ protected:
bool isNeedExpandContent() const;
QString replaceBR(QString text) const;
QString replaceReturns(QString text) const;
int fakeMarginSize() const;
QString getTextPart(int height, int skipHeight);
void restoreLinksEvent();
void preparePopUpMenu(QMenu &menu);

View File

@@ -60,7 +60,6 @@ void BandMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem* /**opt
boundingRect().bottomLeft().y()-4,
boundingRect().width(),4), Qt::lightGray
);
qDebug()<<boundingRect().width();
painter->setRenderHint(QPainter::Antialiasing);
qreal size = (boundingRect().width()<boundingRect().height()) ? boundingRect().width() : boundingRect().height();
QRectF r = QRectF(0,0,size,size);
@@ -199,12 +198,6 @@ BandDesignIntf::BandDesignIntf(BandsType bandType, const QString &xmlTypeName, Q
BandDesignIntf::~BandDesignIntf()
{
// if (itemMode()&DesignMode){
// foreach(BandDesignIntf* band,childBands()) {
// removeChildBand(band);
// delete band;
// }
// }
delete m_bandMarker;
delete m_bandNameLabel;
}
@@ -643,19 +636,6 @@ void BandDesignIntf::processPopUpAction(QAction *action)
ItemsContainerDesignInft::processPopUpAction(action);
}
//void BandDesignIntf::recalcItems(DataSourceManager* dataManager)
//{
// foreach(BaseDesignIntf* bi, childBaseItems()){
// ContentItemDesignIntf* ci = dynamic_cast<ContentItemDesignIntf*>(bi);
// if (bi){
// ContentItemDesignIntf* pci = dynamic_cast<ContentItemDesignIntf*>(bi->patternItem());
// ci->setContent(pci->content());
// }
// }
// updateItemSize(dataManager,FirstPass,height());
//}
BaseDesignIntf* BandDesignIntf::cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent)
{
int maxBottom = 0;
@@ -922,9 +902,9 @@ void BandDesignIntf::setAlternateBackgroundColor(const QColor &alternateBackgrou
}
}
qreal BandDesignIntf::bottomSpace() const
qreal BandDesignIntf::bottomSpace()
{
return height()-findMaxBottom();
return m_bottomSpace;
}
void BandDesignIntf::slotPropertyObjectNameChanged(const QString &, const QString& newName)
@@ -958,14 +938,9 @@ void BandDesignIntf::setKeepTopSpace(bool value)
}
}
int BandDesignIntf::bootomSpace() const
void BandDesignIntf::setBottomSpace(qreal bottomSpace)
{
return m_bottomSpace;
}
void BandDesignIntf::setBootomSpace(int bootomSpace)
{
m_bottomSpace = bootomSpace;
m_bottomSpace = bottomSpace;
}
bool BandDesignIntf::repeatOnEachRow() const
@@ -1138,7 +1113,6 @@ void BandDesignIntf::updateItemSize(DataSourceManager* dataManager, RenderPass p
spaceBorder += borderLineSize() + 2;
}
spaceBorder += m_bottomSpace;
restoreLinks();
snapshotItemsLayout();
@@ -1150,6 +1124,7 @@ void BandDesignIntf::updateItemSize(DataSourceManager* dataManager, RenderPass p
item->setY(item->y() - minTop);
}
}
setHeight(findMaxBottom() + spaceBorder);
}
if ((maxHeight > 0) && (height() > maxHeight)){
@@ -1164,6 +1139,15 @@ void BandDesignIntf::updateBandNameLabel()
if (m_bandNameLabel) m_bandNameLabel->updateLabel(bandTitle());
}
void BandDesignIntf::initFromItem(BaseDesignIntf *source)
{
ItemsContainerDesignInft::initFromItem(source);
BandDesignIntf* source_band = dynamic_cast<BandDesignIntf*>(source);
if (source_band){
this->setBottomSpace(source_band->bottomSpace());
}
}
QColor BandDesignIntf::selectionColor() const
{
return Qt::yellow;

View File

@@ -156,8 +156,8 @@ public:
virtual bool isUnique() const;
void setItemMode(BaseDesignIntf::ItemMode mode);
void updateItemSize(DataSourceManager *dataManager, RenderPass pass=FirstPass, int maxHeight=0);
// void recalcItems(DataSourceManager* dataManager);
void updateBandNameLabel();
void initFromItem(BaseDesignIntf* source);
virtual QColor selectionColor() const;
int bandIndex() const;
@@ -261,11 +261,10 @@ public:
void setAlternateBackgroundColor(const QColor &alternateBackgroundColor);
bool useAlternateBackgroundColor() const;
void setUseAlternateBackgroundColor(bool useAlternateBackgroundColor);
qreal bottomSpace() const;
qreal bottomSpace();
void setBottomSpace(qreal bottomSpace);
void setBackgroundModeProperty(BGMode value);
void setBackgroundOpacity(int value);
int bootomSpace() const;
void setBootomSpace(int bootomSpace);
void updateBandMarkerGeometry();
int shiftItems() const;
void setShiftItems(int shiftItems);

View File

@@ -413,6 +413,7 @@ void BaseDesignIntf::mousePressEvent(QGraphicsSceneMouseEvent *event)
void BaseDesignIntf::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
removeGuideLines();
QRectF newGeometry = geometry();
m_isChangingPos = false;
if (newGeometry != m_oldGeometry) {
@@ -429,7 +430,10 @@ void BaseDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *o
ppainter->save();
setupPainter(ppainter);
if(!isPageItem())
drawBorder(ppainter, rect());
else
drawBorder(ppainter, page()->pageItem()->pageRect());
if(m_shadow)
drawShadow(ppainter, rect(), 6);
// if (m_joinMarkerOn) { drawMarker(ppainter, Const::JOIN_COLOR);}
@@ -544,13 +548,14 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
return;
}
int hStep = dynamic_cast<PageDesignIntf*>(scene())->horizontalGridStep();
int vStep = dynamic_cast<PageDesignIntf*>(scene())->verticalGridStep();
if (m_resizeDirectionFlags & ResizeLeft) {
if ((event->scenePos().x()) <= (mapToScene(0, 0).x() + (width() - Const::MINIMUM_ITEM_WIDTH)) &&
(width() + (event->lastScenePos().x() - event->scenePos().x()) > Const::MINIMUM_ITEM_WIDTH)
) {
(width() + (event->lastScenePos().x() - event->scenePos().x()) > Const::MINIMUM_ITEM_WIDTH)
) {
qreal posRightCorner = mapToScene(0, 0).x() + width();
qreal posLeftCorner = div(mapToParent(event->pos()).x(), hStep).quot * hStep;
if (posLeftCorner < 0 )
@@ -562,15 +567,15 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (m_resizeDirectionFlags & ResizeRight) {
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(event->scenePos().x() - mapToScene(0, 0).x(), hStep).quot * hStep);
}
}
if (m_resizeDirectionFlags & ResizeTop) {
if ((event->scenePos().y()) <= (mapToScene(0, 0).y() + (height() - Const::MINIMUM_ITEM_HEIGHT)) &&
(height() + (event->lastScenePos().y() - event->scenePos().y()) > Const::MINIMUM_ITEM_HEIGHT)
) {
(height() + (event->lastScenePos().y() - event->scenePos().y()) > Const::MINIMUM_ITEM_HEIGHT)
) {
qreal posBottomCorner = mapToScene(0, 0).y() + height();
qreal posTopCorner = div(mapToParent(event->pos()).y(), vStep).quot * vStep;
if (posTopCorner < 0 )
@@ -582,8 +587,8 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (m_resizeDirectionFlags & ResizeBottom) {
if ((event->scenePos().y() > (mapToScene(0, 0).y() + height())) ||
(event->scenePos().y() > (mapToScene(0, 0).y() + Const::MINIMUM_ITEM_HEIGHT))
) {
(event->scenePos().y() > (mapToScene(0, 0).y() + Const::MINIMUM_ITEM_HEIGHT))
) {
setHeight(div(event->scenePos().y() - mapToScene(0, 0).y(), vStep).quot * vStep);
}
}
@@ -618,6 +623,32 @@ void BaseDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
}
if (scene() && !scene()->selectedItems().isEmpty()) {
QGraphicsItem *movingItem = scene()->selectedItems().first();
removeGuideLines();
for (QGraphicsItem *item : scene()->items()) {
if (item != movingItem) {
qreal topDiff = qAbs(item->sceneBoundingRect().bottom() - movingItem->sceneBoundingRect().bottom());
qreal bottomDiff = qAbs(item->sceneBoundingRect().top() - movingItem->sceneBoundingRect().top());
qreal leftDiff = qAbs(item->sceneBoundingRect().left() - movingItem->sceneBoundingRect().left());
qreal rightDiff = qAbs(item->sceneBoundingRect().right() - movingItem->sceneBoundingRect().right());
if (topDiff == 0)
addGuideLine(item->sceneBoundingRect().left(), item->sceneBoundingRect().top(),
movingItem->sceneBoundingRect().left(), movingItem->sceneBoundingRect().top());
if (bottomDiff == 0)
addGuideLine(item->sceneBoundingRect().left(), item->sceneBoundingRect().bottom(),
movingItem->sceneBoundingRect().left(), movingItem->sceneBoundingRect().bottom());
if (leftDiff == 0)
addGuideLine(item->sceneBoundingRect().left(), item->sceneBoundingRect().top(),
movingItem->sceneBoundingRect().left(), movingItem->sceneBoundingRect().top());
if (rightDiff == 0)
addGuideLine(item->sceneBoundingRect().right(), item->sceneBoundingRect().top(),
movingItem->sceneBoundingRect().right(), movingItem->sceneBoundingRect().top());
}
}
}
}
int BaseDesignIntf::possibleResizeDirectionFlags() const
@@ -659,11 +690,11 @@ Qt::CursorShape BaseDesignIntf::getPossibleCursor(int cursorFlags)
if ((cursorFlags == Fixed) || (scene()->selectedItems().count() > 1)) return Qt::ArrowCursor;
if (((cursorFlags & ResizeRight) && (cursorFlags & ResizeTop)) ||
((cursorFlags & ResizeLeft) && (cursorFlags & ResizeBottom))) {
((cursorFlags & ResizeLeft) && (cursorFlags & ResizeBottom))) {
return Qt::SizeBDiagCursor;
}
if (((cursorFlags & ResizeLeft) && (cursorFlags & ResizeTop)) ||
((cursorFlags & ResizeRight) && (cursorFlags & ResizeBottom))) {
((cursorFlags & ResizeRight) && (cursorFlags & ResizeBottom))) {
return Qt::SizeFDiagCursor;
}
if ((cursorFlags & ResizeLeft) || (cursorFlags & ResizeRight)) { return Qt::SizeHorCursor; }
@@ -760,6 +791,23 @@ void BaseDesignIntf::updatePossibleDirectionFlags(){
}
}
void BaseDesignIntf::addGuideLine(qreal x1, qreal y1, qreal x2, qreal y2)
{
QGraphicsLineItem *line = new QGraphicsLineItem(x1, y1, x2, y2);
line->setPen(QPen(Qt::red,2,Qt::DashLine));
if(scene())scene()->addItem(line);
guideLines.append(line);
}
void BaseDesignIntf::removeGuideLines()
{
for (QGraphicsLineItem *line : guideLines) {
if(scene())scene()->removeItem(line);
delete line;
}
guideLines.clear();
}
bool BaseDesignIntf::isChangingPos() const
{
return m_isChangingPos;
@@ -775,6 +823,11 @@ bool BaseDesignIntf::isShapeItem() const
return QString(metaObject()->className()) == "LimeReport::ShapeItem";
}
bool BaseDesignIntf::isPageItem() const
{
return QString(metaObject()->className()) == "LimeReport::PageItemDesignIntf";
}
bool BaseDesignIntf::hasShadow()
{
return m_shadow;
@@ -1014,7 +1067,7 @@ void BaseDesignIntf::moveUp()
void BaseDesignIntf::sizeRight()
{
if ((m_possibleResizeDirectionFlags & ResizeLeft) ||
(m_possibleResizeDirectionFlags & ResizeRight)) {
(m_possibleResizeDirectionFlags & ResizeRight)) {
if (page()) setWidth(width() + page()->horizontalGridStep());
}
}
@@ -1022,7 +1075,7 @@ void BaseDesignIntf::sizeRight()
void BaseDesignIntf::sizeLeft()
{
if ((m_possibleResizeDirectionFlags & ResizeLeft) ||
(m_possibleResizeDirectionFlags & ResizeRight)) {
(m_possibleResizeDirectionFlags & ResizeRight)) {
if(page()) setWidth(width() - page()->horizontalGridStep());
}
}
@@ -1030,7 +1083,7 @@ void BaseDesignIntf::sizeLeft()
void BaseDesignIntf::sizeUp()
{
if ((m_possibleResizeDirectionFlags & ResizeTop) ||
(m_possibleResizeDirectionFlags & ResizeBottom)) {
(m_possibleResizeDirectionFlags & ResizeBottom)) {
if (page()) setHeight(height() - page()->verticalGridStep());
}
}
@@ -1038,7 +1091,7 @@ void BaseDesignIntf::sizeUp()
void BaseDesignIntf::sizeDown()
{
if ((m_possibleResizeDirectionFlags & ResizeTop) ||
(m_possibleResizeDirectionFlags & ResizeBottom)) {
(m_possibleResizeDirectionFlags & ResizeBottom)) {
if (page()) setHeight(height() + page()->verticalGridStep());
}
}
@@ -1066,12 +1119,32 @@ void BaseDesignIntf::drawTopLine(QPainter *painter, QRectF rect) const
if(isShapeItem())
return;
painter->setPen(borderPen(TopLine));
painter->drawLine(rect.x(), rect.y(), rect.width(), rect.y());
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(rect.x()+3+m_borderLineSize,
rect.y()+3+m_borderLineSize,
rect.width()-3-m_borderLineSize,
rect.y()+3+m_borderLineSize);
if(!isPageItem())
{
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(rect.x()+3+m_borderLineSize,
rect.y()+3+m_borderLineSize,
rect.width()-3-m_borderLineSize,
rect.y()+3+m_borderLineSize);
painter->drawLine(rect.x(), rect.y(), rect.width(), rect.y());
}
else
{
painter->drawLine(page()->pageItem()->pageRect().x(),
page()->pageItem()->pageRect().y(),
page()->pageItem()->pageRect().width() + (page()->pageItem()->leftMargin()*10),
page()->pageItem()->pageRect().y());
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(page()->pageItem()->pageRect().x()+3+m_borderLineSize,
page()->pageItem()->pageRect().y()+3+m_borderLineSize,
page()->pageItem()->pageRect().width()-3-m_borderLineSize + (page()->pageItem()->leftMargin()*10),
page()->pageItem()->pageRect().y()+3+m_borderLineSize);
}
}
void BaseDesignIntf::drawBootomLine(QPainter *painter, QRectF rect) const
@@ -1080,12 +1153,29 @@ void BaseDesignIntf::drawBootomLine(QPainter *painter, QRectF rect) const
return;
painter->setPen(borderPen(BottomLine));
if(!isPageItem())
{
painter->drawLine(rect.x(), rect.height(), rect.width(), rect.height());
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(rect.x()+3+m_borderLineSize,
rect.height()-3-m_borderLineSize,
rect.width()-3-m_borderLineSize,
rect.height()-3-m_borderLineSize);
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(rect.x()+3+m_borderLineSize,
rect.height()-3-m_borderLineSize,
rect.width()-3-m_borderLineSize,
rect.height()-3-m_borderLineSize);
}
else
{
painter->drawLine(page()->pageItem()->pageRect().x(),
page()->pageItem()->pageRect().height() + (page()->pageItem()->topMargin()*10)
, page()->pageItem()->pageRect().width() + (page()->pageItem()->leftMargin()*10),
page()->pageItem()->pageRect().height() + (page()->pageItem()->topMargin()*10));
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(page()->pageItem()->pageRect().x()+3+m_borderLineSize,
page()->pageItem()->pageRect().height()-3-m_borderLineSize + (page()->pageItem()->topMargin()*10),
page()->pageItem()->pageRect().width()-3-m_borderLineSize + (page()->pageItem()->leftMargin()*10),
page()->pageItem()->pageRect().height()-3-m_borderLineSize + (page()->pageItem()->topMargin()*10));
}
}
void BaseDesignIntf::drawRightLine(QPainter *painter, QRectF rect) const
@@ -1093,13 +1183,28 @@ void BaseDesignIntf::drawRightLine(QPainter *painter, QRectF rect) const
if(isShapeItem())
return;
painter->setPen(borderPen(RightLine));
if(!isPageItem())
{
painter->drawLine(rect.width(), rect.y(), rect.width(), rect.height());
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(rect.width()-3 - m_borderLineSize,
rect.y()+3+m_borderLineSize,
rect.width()-3-m_borderLineSize,
rect.height()-3-m_borderLineSize);
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(rect.width()-3 - m_borderLineSize,
rect.y()+3+m_borderLineSize,
rect.width()-3-m_borderLineSize,
rect.height()-3-m_borderLineSize);
}
else
{
painter->drawLine(page()->pageItem()->pageRect().width() + (page()->pageItem()->leftMargin()*10), page()->pageItem()->pageRect().y(),
page()->pageItem()->pageRect().width() + (page()->pageItem()->leftMargin()*10),
page()->pageItem()->pageRect().height() + (page()->pageItem()->topMargin()*10));
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(page()->pageItem()->pageRect().width()-3 - m_borderLineSize + (page()->pageItem()->leftMargin()*10),
page()->pageItem()->pageRect().y()+3+m_borderLineSize,
page()->pageItem()->pageRect().width()-3-m_borderLineSize + (page()->pageItem()->leftMargin()*10),
page()->pageItem()->pageRect().height()-3-m_borderLineSize + (page()->pageItem()->topMargin()*10));
}
}
void BaseDesignIntf::drawLeftLine(QPainter *painter, QRectF rect) const
@@ -1107,12 +1212,29 @@ void BaseDesignIntf::drawLeftLine(QPainter *painter, QRectF rect) const
if(isShapeItem())
return;
painter->setPen(borderPen(LeftLine));
if(!isPageItem())
{
painter->drawLine(rect.x(), rect.y(), rect.x(), rect.height());
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(rect.x()+3+m_borderLineSize,
rect.y()+3+m_borderLineSize,
rect.x()+3+m_borderLineSize,
rect.height()-3-m_borderLineSize);
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(page()->pageItem()->pageRect().x()+3+m_borderLineSize,
page()->pageItem()->pageRect().y()+3+m_borderLineSize,
page()->pageItem()->pageRect().x()+3+m_borderLineSize,
page()->pageItem()->pageRect().height()-3-m_borderLineSize);
}
else
{
painter->drawLine(page()->pageItem()->pageRect().x(),
page()->pageItem()->pageRect().y(),
page()->pageItem()->pageRect().x(),
page()->pageItem()->pageRect().height() + (page()->pageItem()->topMargin()*10));
if(borderStyle() == BorderStyle::Doubled)
painter->drawLine(page()->pageItem()->pageRect().x()+3+m_borderLineSize,
page()->pageItem()->pageRect().y()+3+m_borderLineSize,
page()->pageItem()->pageRect().x()+3+m_borderLineSize,
page()->pageItem()->pageRect().height()-3-m_borderLineSize + (page()->pageItem()->topMargin()*10));
}
}
void BaseDesignIntf::drawDesignModeBorder(QPainter *painter, QRectF rect) const
@@ -1214,7 +1336,7 @@ void BaseDesignIntf::setGeometryProperty(QRect rect)
}
}
PageDesignIntf *BaseDesignIntf::page()
PageDesignIntf *BaseDesignIntf::page() const
{
return dynamic_cast<PageDesignIntf*>(scene());
}
@@ -1230,7 +1352,7 @@ QPen BaseDesignIntf::borderPen(BorderSide side/*, bool selected*/) const
if (m_borderLinesFlags & side) {
pen.setColor(m_borderColor);
if(borderStyle() != BorderStyle::Doubled)
pen.setStyle(static_cast<Qt::PenStyle>(m_borderStyle));
pen.setStyle(static_cast<Qt::PenStyle>(m_borderStyle));
//pen.setCosmetic(true);
pen.setWidthF(m_borderLineSize+1); //To draw with point precision (By default: 2px = 1 pt)
@@ -1424,8 +1546,8 @@ void BaseDesignIntf::showEditorDialog()
void BaseDesignIntf::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton &&
((itemMode()&EditMode)||(itemMode()&DesignMode))
) {
((itemMode()&EditMode)||(itemMode()&DesignMode))
) {
showEditorDialog();
}
QGraphicsItem::mouseDoubleClickEvent(event);
@@ -1448,7 +1570,7 @@ void BaseDesignIntf::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
menu.addSeparator();
QAction* copyAction = menu.addAction(QIcon(":/report/images/copy"), tr("Copy"));
QAction* cutAction = menu.addAction(QIcon(":/report/images/cut"), tr("Cut"));
QAction* cutAction = menu.addAction(QIcon(":/report/images/cut"), tr("Cut"));
QAction* pasteAction = menu.addAction(QIcon(":/report/images/paste"), tr("Paste"));
pasteAction->setEnabled(false);
@@ -1484,6 +1606,54 @@ void BaseDesignIntf::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QAction* noBordersAction = menu.addAction(QIcon(":/report/images/noLines"), tr("No borders"));
QAction* allBordersAction = menu.addAction(QIcon(":/report/images/allLines"), tr("All borders"));
QAction* editBorderAction = menu.addAction(QIcon(":/report/images/borderEditor"), tr("Edit borders..."));
QMenu *alignement = menu.addMenu(tr("Align items"));
QAction* alignLeft = new QAction(QIcon(":/report/images/alignToLeft"),tr("Align to left"));
QAction* alignRight = new QAction(QIcon(":/report/images/alignToRight"),tr("Align to right"));
QAction* alignTop = new QAction(QIcon(":/report/images/alignToTop"),tr("Align to top"));
QAction* alignBottom = new QAction(QIcon(":/report/images/alignToBottom"),tr("Align to bottom"));
QAction* alignHCenter = new QAction(QIcon(":/report/images/alignToHCenter"),tr("Align to horizontal center"));
QAction* alignVCenter = new QAction(QIcon(":/report/images/alignToHCenter"),tr("Align to vertical center"));
QMenu *resize = menu.addMenu(tr("Resize items"));
QAction* toSameWidth = new QAction(QIcon(":/report/images/sameWidth"),tr("Same width"));
QAction* toSameHeight = new QAction(QIcon(":/report/images/sameHeight"),tr("Same height"));
QMenu *itemAlign = menu.addMenu(tr("Align items to page"));
QAction* itemAlignToLeft = new QAction(tr("Align to left"));
QAction* itemAlignToRight = new QAction(tr("Align to right"));
QAction* itemAlignToCenter = new QAction(tr("Align to center"));
QAction* cancelItemAlign = new QAction(tr("cancel alignement"));
QAction* itemAlignParent = new QAction(tr("Align to page width"));
menu.addMenu(itemAlign);
itemAlign->addAction(itemAlignToLeft);
itemAlignToLeft->setChecked(m_itemAlign == LeftItemAlign);
itemAlignToRight->setChecked(m_itemAlign == RightItemAlign);
itemAlignToCenter->setChecked(m_itemAlign == CenterItemAlign);
itemAlignParent->setChecked(m_itemAlign == ParentWidthItemAlign);
cancelItemAlign->setChecked(m_itemAlign == DesignedItemAlign);
itemAlign->addAction(itemAlignToRight);
itemAlign->addAction(itemAlignToCenter);
itemAlign->addAction(itemAlignParent);
itemAlign->addAction(cancelItemAlign);
resize->addAction(toSameWidth);
resize->addAction(toSameHeight);
alignement->addAction(alignLeft);
alignement->addAction(alignRight);
alignement->addAction(alignTop);
alignement->addAction(alignBottom);
connect(alignLeft,&QAction::triggered,this,[=](){page->alignToLeft();});
connect(alignRight,&QAction::triggered,this,[=](){page->alignToRigth();});
connect(alignTop,&QAction::triggered,this,[=](){page->alignToTop();});
connect(alignBottom,&QAction::triggered,this,[=](){page->alignToBottom();});
connect(alignHCenter,&QAction::triggered,this,[=](){page->alignToHCenter();});
connect(alignVCenter,&QAction::triggered,this,[=](){page->alignToVCenter();});
connect(toSameWidth,&QAction::triggered,this,[=](){page->sameWidth();});
connect(toSameHeight,&QAction::triggered,this,[=](){page->sameHeight();});
connect(itemAlignToLeft,&QAction::triggered,this,[=](){page->setItemAlign(BaseDesignIntf::LeftItemAlign);});
connect(itemAlignToRight,&QAction::triggered,this,[=](){page->setItemAlign(BaseDesignIntf::RightItemAlign);});
connect(itemAlignToCenter,&QAction::triggered,this,[=](){page->setItemAlign(BaseDesignIntf::CenterItemAlign);});
connect(itemAlignParent,&QAction::triggered,this,[=](){page->setItemAlign(BaseDesignIntf::ParentWidthItemAlign);});
connect(cancelItemAlign,&QAction::triggered,this,[=](){page->setItemAlign(BaseDesignIntf::DesignedItemAlign);});
preparePopUpMenu(menu);
QAction* a = menu.exec(event->screenPos());
if (a){
@@ -1515,8 +1685,12 @@ void BaseDesignIntf::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
page->addHLayout();
if (a == createVLayout)
page->addVLayout();
processPopUpAction(a);
}
}
int BaseDesignIntf::possibleMoveDirectionFlags() const

View File

@@ -253,7 +253,7 @@ public:
virtual void setBorderLinesFlags(LimeReport::BaseDesignIntf::BorderLines flags);
void setGeometryProperty(QRect rect);
PageDesignIntf* page();
PageDesignIntf* page() const;
BorderLines borderLines() const;
@@ -265,7 +265,7 @@ public:
virtual BaseDesignIntf* cloneItem(LimeReport::BaseDesignIntf::ItemMode mode, QObject* owner=0, QGraphicsItem* parent=0);
virtual BaseDesignIntf* cloneItemWOChild(LimeReport::BaseDesignIntf::ItemMode mode, QObject* owner=0, QGraphicsItem* parent=0);
virtual BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0) = 0;
void initFromItem(BaseDesignIntf* source);
virtual void initFromItem(BaseDesignIntf* source);
virtual bool canBeSplitted(int height) const;
virtual qreal minHeight() const {return 0;}
@@ -339,6 +339,7 @@ public:
bool isChangingPos() const;
void setIsChangingPos(bool isChangingPos);
bool isShapeItem() const;
bool isPageItem() const;
bool hasShadow();
void setShadow(bool sh);
Q_INVOKABLE QString setItemWidth(qreal width);
@@ -427,7 +428,8 @@ private:
void moveSelectedItems(QPointF delta);
Qt::CursorShape getPossibleCursor(int cursorFlags);
void updatePossibleDirectionFlags();
void addGuideLine(qreal x1, qreal y1, qreal x2, qreal y2);
void removeGuideLines();
private slots:
void onChangeGeometryTimeOut();
@@ -495,6 +497,7 @@ private:
bool m_isChangingPos;
bool m_isMoveable;
bool m_shadow;
QList<QGraphicsLineItem*> guideLines;
signals:
void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry);

View File

@@ -44,8 +44,11 @@ public:
Q_DECLARE_METATYPE(ACollectionProperty)
namespace LimeReport{
#if __cplusplus >= 201703L
const int inline COLLECTION_TYPE_ID = qMetaTypeId<ACollectionProperty>();
#else
const int COLLECTION_TYPE_ID = qMetaTypeId<ACollectionProperty>();
#endif
class LIMEREPORT_EXPORT ICollectionContainer{
public:
virtual QObject* createElement(const QString& collectionName,const QString& elementType)=0;

View File

@@ -272,6 +272,24 @@ QVariant ModelToDataSource::dataByRowIndex(const QString &columnName, int rowInd
return QVariant();
}
QVariant ModelToDataSource::dataByRowIndex(const QString &columnName, int rowIndex, int roleName)
{
if(m_model->rowCount() > rowIndex)
return m_model->data(m_model->index(rowIndex, columnIndexByName(columnName)));
return QVariant();
}
QVariant ModelToDataSource::dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName)
{
if(m_model->rowCount() > rowIndex) {
int roleCode{roleName.isEmpty() ? Qt::DisplayRole
: m_model->roleNames().key(roleName.toUtf8(), Qt::DisplayRole)};
return m_model->data(m_model->index(rowIndex, columnIndexByName(columnName)), roleCode);
}
return QVariant();
}
QVariant ModelToDataSource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData)
{
for( int i=0; i < m_model->rowCount(); ++i ){
@@ -310,6 +328,13 @@ int ModelToDataSource::columnIndexByName(QString name)
return -1;
}
QVariant ModelToDataSource::headerData(const QString &columnName, const QString &roleName)
{
int roleCode{roleName.isEmpty() ? Qt::DisplayRole
: m_model->roleNames().key(roleName.toUtf8(), Qt::DisplayRole)};
return m_model->headerData(columnIndexByName(columnName), Qt::Horizontal, roleCode);
}
QString ModelToDataSource::lastError()
{
return m_lastError;
@@ -722,6 +747,18 @@ QVariant CallbackDatasource::dataByRowIndex(const QString &columnName, int rowIn
return result;
}
QVariant CallbackDatasource::dataByRowIndex(const QString &columnName, int rowIndex, int roleName)
{
Q_UNUSED(roleName)
return dataByRowIndex(columnName, rowIndex);
}
QVariant CallbackDatasource::dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName)
{
Q_UNUSED(roleName)
return dataByRowIndex(columnName, rowIndex);
}
QVariant CallbackDatasource::dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData)
{
int backupCurrentRow = m_currentRow;
@@ -816,6 +853,12 @@ int CallbackDatasource::columnIndexByName(QString name)
return -1;
}
QVariant CallbackDatasource::headerData(const QString &columnName, const QString &roleName)
{
Q_UNUSED(roleName)
return columnName; // STUB
}
bool CallbackDatasource::checkNextRecord(int recordNum){
if (bof()) checkIfEmpty();
if (m_rowCount > 0) {

View File

@@ -388,10 +388,13 @@ public:
bool bof();
QVariant data(const QString& columnName);
QVariant dataByRowIndex(const QString &columnName, int rowIndex);
QVariant dataByRowIndex(const QString &columnName, int rowIndex, int roleName);
QVariant dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName);
QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData);
int columnCount();
QString columnNameByIndex(int columnIndex);
int columnIndexByName(QString name);
QVariant headerData(const QString &columnName, const QString &roleName);
QString lastError();
virtual QAbstractItemModel* model();
int currentRow();
@@ -421,6 +424,8 @@ public:
bool eof(){return m_eof;}
QVariant data(const QString &columnName);
QVariant dataByRowIndex(const QString& columnName, int rowIndex);
QVariant dataByRowIndex(const QString &columnName, int rowIndex, int roleName);
QVariant dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName);
QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData);
int columnCount();
QString columnNameByIndex(int columnIndex);
@@ -428,6 +433,7 @@ public:
bool isInvalid() const{ return false;}
QString lastError(){ return "";}
QAbstractItemModel *model(){return 0;}
QVariant headerData(const QString &columnName, const QString &roleName);
private:
bool checkNextRecord(int recordNum);
bool checkIfEmpty();
@@ -441,6 +447,7 @@ private:
QHash<QString, QVariant> m_valuesCache;
bool m_getDataFromCache;
int m_lastKeyRow;
};
class CallbackDatasourceHolder :public QObject, public IDataSourceHolder{

View File

@@ -18,9 +18,12 @@ public:
virtual bool eof() = 0;
virtual QVariant data(const QString& columnName) = 0;
virtual QVariant dataByRowIndex(const QString& columnName, int rowIndex) = 0;
virtual QVariant dataByRowIndex(const QString &columnName, int rowIndex, int roleName) = 0;
virtual QVariant dataByRowIndex(const QString &columnName, int rowIndex, const QString &roleName) = 0;
virtual QVariant dataByKeyField(const QString& columnName, const QString& keyColumnName, QVariant keyData) = 0;
virtual int columnCount() = 0;
virtual QString columnNameByIndex(int columnIndex) = 0;
virtual QVariant headerData(const QString &columnName, const QString &roleName) = 0;
virtual int columnIndexByName(QString name) = 0;
virtual bool isInvalid() const = 0;
virtual QString lastError() = 0;

View File

@@ -466,7 +466,7 @@ QString DataSourceManager::replaceVariables(QString value){
}
}
}
return value;
return value;
#endif
return QString();
}
@@ -612,13 +612,13 @@ QString DataSourceManager::replaceFields(QString query, QMap<QString,QString> &a
query.replace(pos,rx.cap(0).length(),":"+extractField(field));
}
}
return query;
return query;
#endif
return query;
}
void DataSourceManager::setReportVariable(const QString &name, const QVariant &value)
{
{
if (!containsVariable(name)){
addVariable(name,value);
} else changeVariable(name,value);
@@ -1689,6 +1689,28 @@ QVariant DataSourceManager::fieldDataByRowIndex(const QString &fieldName, int ro
return QVariant();
}
QVariant DataSourceManager::fieldDataByRowIndex(const QString &fieldName, int rowIndex, int role)
{
if(containsField(fieldName)) {
IDataSource *ds = dataSource(extractDataSource(fieldName));
if(ds) {
return ds->dataByRowIndex(extractFieldName(fieldName), rowIndex, role);
}
}
return QVariant();
}
QVariant DataSourceManager::fieldDataByRowIndex(const QString &fieldName, int rowIndex, const QString &roleName)
{
if(containsField(fieldName)) {
IDataSource *ds = dataSource(extractDataSource(fieldName));
if(ds) {
return ds->dataByRowIndex(extractFieldName(fieldName), rowIndex, roleName);
}
}
return QVariant();
}
QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const QString& valueFieldName, const QString& keyFieldName, QVariant keyValue)
{
IDataSource* ds = dataSource(datasourceName);
@@ -1698,6 +1720,44 @@ QVariant DataSourceManager::fieldDataByKey(const QString& datasourceName, const
return QVariant();
}
QVariant DataSourceManager::headerData(const QString &fieldName, const QString &roleName)
{
if(containsField(fieldName)) {
IDataSource *ds = dataSource(extractDataSource(fieldName));
if(ds) {
return ds->headerData(extractFieldName(fieldName), roleName);
}
}
return QVariant();
}
QString DataSourceManager::columnName(const QString &datasourceName, int index)
{
IDataSource *ds = dataSource(datasourceName);
if(ds && !ds->isInvalid() && ds->columnCount() > index) {
return ds->columnNameByIndex(index);
}
return QString("unknown");
}
int DataSourceManager::columnCount(const QString &datasourceName)
{
IDataSource *ds = dataSource(datasourceName);
if(ds && !ds->isInvalid()) {
return ds->columnCount();
}
return -1;
}
int DataSourceManager::columnIndex(const QString &datasourceName, const QString &columnName)
{
IDataSource *ds = dataSource(datasourceName);
if(ds && !ds->isInvalid()) {
return ds->columnIndexByName(columnName);
}
}
void DataSourceManager::reopenDatasource(const QString& datasourceName)
{
QueryHolder* qh = dynamic_cast<QueryHolder*>(dataSourceHolder(datasourceName));

View File

@@ -173,12 +173,18 @@ public:
bool containsField(const QString& fieldName);
QVariant fieldData(const QString& fieldName);
QVariant fieldDataByRowIndex(const QString& fieldName, int rowIndex);
QVariant fieldDataByRowIndex(const QString &fieldName, int rowIndex, int role);
QVariant fieldDataByRowIndex(const QString &fieldName, int rowIndex, const QString &roleName);
QVariant fieldDataByKey(
const QString& datasourceName,
const QString& valueFieldName,
const QString& keyFieldName,
QVariant keyValue
);
QVariant headerData(const QString &fieldName, const QString &roleName);
QString columnName(const QString &datasourceName, int index);
int columnCount(const QString &datasourceName);
int columnIndex(const QString &datasourceName,const QString& columnName);
void reopenDatasource(const QString& datasourceName);
QString extractDataSource(const QString& fieldName);

View File

@@ -55,6 +55,7 @@ public:
virtual bool containsVariable(const QString& variableName) = 0;
virtual QVariant variable(const QString& variableName) = 0;
virtual bool addModel(const QString& name, QAbstractItemModel *model, bool owned) = 0;
virtual void addCSV(const QString& name, const QString& csvText, const QString& separator, bool firstRowIsHeader) = 0;
virtual void removeModel(const QString& name) = 0;
virtual bool containsDatasource(const QString& dataSourceName) = 0;
virtual void clearUserVariables()=0;

View File

@@ -102,6 +102,8 @@ qreal ItemsContainerDesignInft::findMaxBottom() const
if(subItem)
if ( subItem->isVisible() && (subItem->geometry().bottom()>maxBottom) )
maxBottom = subItem->geometry().bottom();
if(subItem->objectName() == "VerticalLayout22")
qDebug()<<subItem->height();
}
return maxBottom;
}

View File

@@ -73,7 +73,7 @@ PageDesignIntf::PageDesignIntf(QObject *parent):
m_itemInsertRect(0),
m_itemMode(DesignMode),
m_cutterBorder(0),
m_infoPosRect(0),
// m_infoPosRect(0),
m_currentCommand(-1),
m_changeSizeMode(false),
m_changePosMode(false),
@@ -120,10 +120,10 @@ void PageDesignIntf::updatePageRect()
if (m_pageItem.isNull()) {
m_pageItem = PageItemDesignIntf::create(this);
addItem(m_pageItem.data());
m_pageItem->setTopMargin(5);
m_pageItem->setBottomMargin(5);
m_pageItem->setLeftMargin(5);
m_pageItem->setRightMargin(5);
m_pageItem->setTopMargin(10);
m_pageItem->setBottomMargin(10);
m_pageItem->setLeftMargin(10);
m_pageItem->setRightMargin(10);
m_pageItem->setObjectName("ReportPage1");
connect(m_pageItem.data(), SIGNAL(itemSelected(LimeReport::BaseDesignIntf *)), this, SIGNAL(itemSelected(LimeReport::BaseDesignIntf *)));
connect(m_pageItem.data(), SIGNAL(geometryChanged(QObject *, QRectF, QRectF)), this, SLOT(slotPageGeometryChanged(QObject *, QRectF, QRectF)));
@@ -324,24 +324,23 @@ void PageDesignIntf::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
saveSelectedItemsGeometry();
m_changePosOrSizeMode = true;
}
qreal posY = div(page->mapFromScene(event->scenePos()).y(), verticalGridStep()).quot * verticalGridStep();
qreal posX = div(page->mapFromScene(event->scenePos()).x(), verticalGridStep()).quot * horizontalGridStep();
if(!m_infoPosRect)
{
// qreal posY = div(page->mapFromScene(event->scenePos()).y(), verticalGridStep()).quot * verticalGridStep();
// qreal posX = div(page->mapFromScene(event->scenePos()).x(), verticalGridStep()).quot * horizontalGridStep();
// if(!m_infoPosRect)
// {
// m_infoPosRect = new QGraphicsTextItem();
// m_infoPosRect->setDefaultTextColor(QColor(100,150,50));
m_infoPosRect = new QGraphicsTextItem();
m_infoPosRect->setDefaultTextColor(QColor(100,150,50));
// QFont font("Arial");
// font.setPointSize(16);
// font.setBold(true);
// m_infoPosRect->setFont(font);
// addItem(m_infoPosRect);
// }
QFont font("Arial");
font.setPointSize(16);
font.setBold(true);
m_infoPosRect->setFont(font);
addItem(m_infoPosRect);
}
m_infoPosRect->setPlainText("(x: "+QString::number(posX/100)+", y: "+QString::number(posY/100)+") cm");
m_infoPosRect->setPos(posX,posY+30);
// m_infoPosRect->setPlainText("(x: "+QString::number(posX/100)+", y: "+QString::number(posY/100)+") cm");
// m_infoPosRect->setPos(posX,posY+30);
}
@@ -423,11 +422,11 @@ void PageDesignIntf::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
m_selectionRect = 0;
m_multiSelectStarted = false;
}
if(m_infoPosRect)
{
delete m_infoPosRect;
m_infoPosRect = 0;
}
// if(m_infoPosRect)
// {
// delete m_infoPosRect;
// m_infoPosRect = 0;
// }
QGraphicsScene::mouseReleaseEvent(event);
}
@@ -1749,6 +1748,11 @@ void PageDesignIntf::addVLayout()
}
}
void PageDesignIntf::setItemAlign(BaseDesignIntf::ItemAlign itemAlign)
{
changeSelectedGroupProperty("itemAlign",QVariant(itemAlign));
}
bool hLayoutLessThen(QGraphicsItem *c1, QGraphicsItem *c2)
{
return c1->pos().x() < c2->pos().x();
@@ -2158,10 +2162,9 @@ bool PasteCommand::insertItem(ItemsReaderIntf::Ptr reader)
reader->readItem(item);
item->setParent(parentItem);
item->setParentItem(parentItem);
if (page()->reportItemsByName(item->objectName()).size() > 0){
if (page()->reportItemsByName(item->objectName()).size()>1){
item->setObjectName(objectName);
}
else
foreach (BaseDesignIntf* child, item->childBaseItems()){
changeName(page(), child);
};

View File

@@ -251,6 +251,7 @@ namespace LimeReport {
void sameHeight();
void addHLayout();
void addVLayout();
void setItemAlign(BaseDesignIntf::ItemAlign itemAlign);
void setFont(const QFont &font);
void setTextAlign(const Qt::Alignment& alignment);
void setBorders(const BaseDesignIntf::BorderLines& border);
@@ -271,7 +272,7 @@ namespace LimeReport {
void bandDeleted(QObject* band);
void slotPageItemLoaded(QObject *);
void slotSelectionChanged();
void slotAnimationStoped(QObject *animation);
void slotAnimationStoped(QObject *animation);
private:
template <typename T>
BaseDesignIntf* internalAddBand(T bandType);
@@ -300,7 +301,7 @@ namespace LimeReport {
BaseDesignIntf::ItemMode m_itemMode;
QGraphicsRectItem* m_cutterBorder;
QGraphicsRectItem* m_pageRect;
QGraphicsTextItem* m_infoPosRect;
// QGraphicsTextItem* m_infoPosRect;
QVector<CommandIf::Ptr> m_commandsList;
QVector<ReportItemPos> m_positionStamp;
QVector<ReportItemSize> m_geometryStamp;

View File

@@ -91,13 +91,14 @@ void PageItemDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsIte
QRectF rect = pageRect();
if (isExtendedInDesignMode()) rect.adjust(0,0,0,m_extendedHeight);
ppainter->save();
ppainter->setOpacity(0.8);
ppainter->setOpacity(1);
ppainter->fillRect(boundingRect(), pageBorderColor());
ppainter->setOpacity(1);
ppainter->fillRect(rect, Qt::white);
paintGrid(ppainter, rect);
ppainter->setPen(gridColor());
ppainter->drawRect(boundingRect());
drawBorder(ppainter,pageRect());
drawShadow(ppainter, boundingRect(), 10);
ppainter->restore();
}
@@ -113,6 +114,8 @@ void PageItemDesignIntf::paint(QPainter *ppainter, const QStyleOptionGraphicsIte
QRectF tmpRect = rect();
tmpRect.adjust(-4,-4,4,4);
ppainter->drawRect(tmpRect);
//drawShadow(ppainter, tmpRect, 10);
drawBorder(ppainter,pageRect());
ppainter->restore();
BaseDesignIntf::paint(ppainter,option,widget);
}
@@ -142,7 +145,7 @@ QColor PageItemDesignIntf::selectionColor() const
QColor PageItemDesignIntf::pageBorderColor() const
{
return QColor(100,150,50);
return QColor(255,255,255);
}
QColor PageItemDesignIntf::gridColor() const

View File

@@ -169,12 +169,12 @@ public:
bool canAcceptPaste() const{ return true;}
bool resetPageNumber() const;
void setResetPageNumber(bool resetPageNumber);
void updateSubItemsSize(RenderPass pass, DataSourceManager *dataManager);
void swapBands(BandDesignIntf *band, BandDesignIntf *bandToSwap);
void updateSubItemsSize(RenderPass pass, DataSourceManager *dataManager);
void swapBands(BandDesignIntf *band, BandDesignIntf *bandToSwap);
void moveBandFromTo(int from, int to);
QList<BandDesignIntf *> createBandGroup(int beginIndex, int endIndex);
bool isExtendedInDesignMode() const;
void setExtendedInDesignMode(bool isExtendedInDesignMode);
int extendedHeight() const;
@@ -197,7 +197,7 @@ public:
void placeTearOffBand();
BandDesignIntf *pageFooter() const;
void setPageFooter(BandDesignIntf *pageFooter);
PrintBehavior printBehavior() const;
void setPrintBehavior(const PrintBehavior &printBehavior);
@@ -211,6 +211,8 @@ public:
bool mixWithPriorPage() const;
void setMixWithPriorPage(bool value);
QRectF& pageRect(){return m_pageRect;}
signals:
void beforeFirstPageRendered();
@@ -222,7 +224,6 @@ protected slots:
void setUnitTypeProperty(BaseDesignIntf::UnitType value);
protected:
void collectionLoadFinished(const QString& collectionName);
QRectF& pageRect(){return m_pageRect;}
void updateMarginRect();
QSizeF getRectByPageSize(const PageSize &size);
void initPageSize(const PageSize &size);

View File

@@ -215,7 +215,7 @@ void ReportDesignWindow::createActions()
m_useMagnetAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_M));
connect(m_useMagnetAction,SIGNAL(toggled(bool)),this,SLOT(slotUseMagnet(bool)));
m_newTextItemAction = new QAction(tr("Text Item"),this);
m_newTextItemAction->setIcon(QIcon(":/items/TextItem"));
m_actionMap.insert("TextItem",m_newTextItemAction);
@@ -253,7 +253,10 @@ void ReportDesignWindow::createActions()
m_previewReportAction->setIcon(QIcon(":/report/images/render"));
m_previewReportAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_P));
connect(m_previewReportAction,SIGNAL(triggered()),this,SLOT(slotPreviewReport()));
m_printReportAction = new QAction(tr("Print Report"),this);
m_printReportAction->setIcon(QIcon(":/report/images/print"));
m_printReportAction->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_P));
connect(m_printReportAction,SIGNAL(triggered()),this,SLOT(slotPrintReport()));
m_testAction = new QAction("test",this);
m_testAction->setIcon(QIcon(":/report/images/pin"));
connect(m_testAction,SIGNAL(triggered()),this,SLOT(slotTest()));
@@ -372,13 +375,13 @@ void ReportDesignWindow::createToolBars()
m_mainToolBar->addSeparator();
m_mainToolBar->addAction(m_zoomInReportAction);
m_mainToolBar->addAction(m_zoomOutReportAction);
m_mainToolBar->addAction(m_zoomOutReportAction);
m_mainToolBar->addSeparator();
m_mainToolBar->addAction(m_previewReportAction);
//m_mainToolBar->addSeparator();
//m_mainToolBar->addAction(m_useGridAction);
//m_mainToolBar->addAction(m_printReportAction);
m_mainToolBar->addAction(m_printReportAction);
m_fontEditorBar = new FontEditorWidgetForDesigner(m_reportDesignWidget,tr("Font"),this);
m_fontEditorBar->setIconSize(m_mainToolBar->iconSize());
@@ -517,7 +520,7 @@ void ReportDesignWindow::createMainMenu()
m_fileMenu->addAction(m_saveReportAction);
m_fileMenu->addAction(m_saveReportAsAction);
m_fileMenu->addAction(m_previewReportAction);
//m_fileMenu->addAction(m_printReportAction);
m_fileMenu->addAction(m_printReportAction);
m_editMenu = menuBar()->addMenu(tr("Edit"));
m_editMenu->addAction(m_redoAction);
m_editMenu->addAction(m_undoAction);
@@ -858,7 +861,7 @@ void ReportDesignWindow::restoreSetting()
QDesktopWidget *desktop = QApplication::desktop();
int screenWidth = desktop->screenGeometry().width();
int screenHeight = desktop->screenGeometry().height();
int screenHeight = desktop->screenGeometry().height();
#endif
int x = screenWidth * 0.1;
int y = screenHeight * 0.1;
@@ -973,7 +976,7 @@ QSettings*ReportDesignWindow::settings()
}
void ReportDesignWindow::slotNewReport()
{
{
if (checkNeedToSave()) {
m_lblReportName->setText("");
startNewReport();
@@ -1601,7 +1604,7 @@ void ReportDesignWindow::closeEvent(QCloseEvent * event)
event->ignore();
return;
}
if (checkNeedToSave()){
if (checkNeedToSave()){
m_dataBrowser->closeAllDataWindows();
writeState();
#ifdef Q_OS_WIN

View File

@@ -277,9 +277,9 @@ bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer)
QPrinterInfo pi;
if (!pi.defaultPrinter().isNull())
#if QT_VERSION >= 0x050300
m_printer.data()->setPrinterName(pi.defaultPrinterName());
m_printer.data()->setPrinterName(pi.defaultPrinterName());
#else
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
#endif
QPrintDialog dialog(m_printer.data(),QApplication::activeWindow());
m_printerSelected = dialog.exec()!=QDialog::Rejected;
@@ -310,22 +310,22 @@ void ReportEnginePrivate::internalPrintPages(ReportPages pages, QPrinter &printe
printProcessors.insert("default",QSharedPointer<PrintProcessor>(new PrintProcessor(&printer)));
int pageCount = (printer.printRange() == QPrinter::AllPages) ?
pages.size() :
printer.toPage() - printer.fromPage();
pages.size() :
printer.toPage() - printer.fromPage();
emit printingStarted(pageCount);
foreach(PageItemDesignIntf::Ptr page, pages){
if ( !m_cancelPrinting &&
((printer.printRange() == QPrinter::AllPages) ||
( (printer.printRange()==QPrinter::PageRange) &&
(currenPage >= printer.fromPage()) &&
(currenPage <= printer.toPage())
))
)
((printer.printRange() == QPrinter::AllPages) ||
( (printer.printRange()==QPrinter::PageRange) &&
(currenPage >= printer.fromPage()) &&
(currenPage <= printer.toPage())
))
)
{
printProcessors["default"]->printPage(page);
emit pagePrintingFinished(currenPage);
QApplication::processEvents();
printProcessors["default"]->printPage(page);
emit pagePrintingFinished(currenPage);
QApplication::processEvents();
}
currenPage++;
@@ -382,9 +382,9 @@ QStringList ReportEnginePrivate::aviableReportTranslations()
void ReportEnginePrivate::setReportTranslation(const QString &languageName)
{
foreach(QLocale::Language language, aviableLanguages()){
if (QLocale::languageToString(language).compare(languageName) == 0){
setReportLanguage(language);
}
if (QLocale::languageToString(language).compare(languageName) == 0){
setReportLanguage(language);
}
}
}
@@ -504,7 +504,7 @@ bool ReportEnginePrivate::showPreviewWindow(ReportPages pages, PreviewHints hint
w->setPages(pages);
w->setLayoutDirection(m_previewLayoutDirection);
w->setStyleSheet(styleSheet());
// w->setDefaultPrinter()
// w->setDefaultPrinter()
if (!dataManager()->errorsList().isEmpty()){
w->setErrorMessages(dataManager()->errorsList());
@@ -542,15 +542,15 @@ void ReportEnginePrivate::previewReport(PreviewHints hints)
void ReportEnginePrivate::previewReport(QPrinter* printer, PreviewHints hints)
{
try{
dataManager()->setDesignTime(false);
ReportPages pages = renderToPages();
dataManager()->setDesignTime(true);
showPreviewWindow(pages, hints, printer);
} catch (ReportError &exception){
saveError(exception.what());
showError(exception.what());
}
try{
dataManager()->setDesignTime(false);
ReportPages pages = renderToPages();
dataManager()->setDesignTime(true);
showPreviewWindow(pages, hints, printer);
} catch (ReportError &exception){
saveError(exception.what());
showError(exception.what());
}
}
ReportDesignWindowInterface*ReportEnginePrivate::getDesignerWindow()
@@ -569,7 +569,7 @@ ReportDesignWindowInterface*ReportEnginePrivate::getDesignerWindow()
m_designerWindow->setShowProgressDialog(m_showProgressDialog);
#endif
}
}
}
if (m_designerWindow){
m_datasources->updateDatasourceModel();
}
@@ -664,19 +664,19 @@ bool ReportEnginePrivate::slotLoadFromFile(const QString &fileName)
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 )
);
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();
clearReport();
currentPreview->close();
}
currentPreview->close();
}
return false;
return false;
}
clearReport();
@@ -708,7 +708,7 @@ bool ReportEnginePrivate::slotLoadFromFile(const QString &fileName)
if ( hasActivePreview() )
{
currentPreview->reloadPreview();
currentPreview->reloadPreview();
}
EASY_END_BLOCK;
return true;
@@ -778,23 +778,23 @@ QSettings*ReportEnginePrivate::settings()
bool ReportEnginePrivate::loadFromFile(const QString &fileName, bool autoLoadPreviewOnChange)
{
// only watch one file at a time
// only watch one file at a time
if ( !m_fileWatcher->files().isEmpty() )
{
m_fileWatcher->removePaths( m_fileWatcher->files() );
}
if ( !m_fileWatcher->files().isEmpty() )
{
m_fileWatcher->removePaths( m_fileWatcher->files() );
}
if ( autoLoadPreviewOnChange )
{
m_fileWatcher->addPath( fileName );
}
if ( autoLoadPreviewOnChange )
{
m_fileWatcher->addPath( fileName );
}
bool result = slotLoadFromFile( fileName );
if (result) {
emit loadFinished();
}
return result;
bool result = slotLoadFromFile( fileName );
if (result) {
emit loadFinished();
}
return result;
}
bool ReportEnginePrivate::loadFromByteArray(QByteArray* data, const QString &name){
@@ -1302,7 +1302,7 @@ ReportPages ReportEnginePrivate::renderToPages()
scriptContext()->qobjectToScript("engine",this);
#ifdef USE_QTSCRIPTENGINE
ScriptEngineManager::instance().scriptEngine()->pushContext();
ScriptEngineManager::instance().scriptEngine()->pushContext();
#endif
if (m_scriptEngineContext->runInitScript()){
@@ -1320,10 +1320,10 @@ ReportPages ReportEnginePrivate::renderToPages()
if (!page->isTOC() && page->isPrintable()){
page->setReportSettings(&m_reportSettings);
result = appendPages(
result,
m_reportRender->renderPageToPages(page),
page->mixWithPriorPage() ? MixPages : AppendPages
);
result,
m_reportRender->renderPageToPages(page),
page->mixWithPriorPage() ? MixPages : AppendPages
);
} else if (page->isTOC()){
startTOCPage = result.count();
pageAfterTOCIndex = i+1;
@@ -1340,20 +1340,20 @@ ReportPages ReportEnginePrivate::renderToPages()
if ( m_renderingPages.count() > (pageAfterTOCIndex))
secondPage = m_renderingPages.at(pageAfterTOCIndex);
ReportPages pages = m_reportRender->renderTOC(
page,
true,
secondPage && secondPage->resetPageNumber()
);
page,
true,
secondPage && secondPage->resetPageNumber()
);
for (int j=0; j<pages.count(); ++j){
result.insert(startTOCPage+j,pages.at(j));
}
} else {
result = appendPages(
result,
m_reportRender->renderPageToPages(page),
page->mixWithPriorPage() ? MixPages : AppendPages
);
result,
m_reportRender->renderPageToPages(page),
page->mixWithPriorPage() ? MixPages : AppendPages
);
}
}
}
@@ -1367,7 +1367,7 @@ ReportPages ReportEnginePrivate::renderToPages()
m_reportRendering = false;
#ifdef USE_QTSCRIPTENGINE
ScriptEngineManager::instance().scriptEngine()->popContext();
ScriptEngineManager::instance().scriptEngine()->popContext();
#endif
return result;
} else {
@@ -1818,7 +1818,7 @@ PrintProcessor::PrintProcessor(QPrinter* printer)
bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page)
{
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
if (!m_firstPage && !m_painter->isActive()) return false;
PageDesignIntf* backupPage = dynamic_cast<PageDesignIntf*>(page->scene());
@@ -1836,91 +1836,47 @@ bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page)
m_firstPage = false;
}
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
qreal leftMargin, topMargin, rightMargin, bottomMargin;
m_printer->getPageMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin, QPrinter::Millimeter);
QRectF printerPageRect = m_printer->pageRect(QPrinter::Millimeter);
printerPageRect = QRectF(0,0,(printerPageRect.size().width() + rightMargin + leftMargin) * page->unitFactor(),
(printerPageRect.size().height() + bottomMargin +topMargin) * page->unitFactor());
if (page->printBehavior() == PageItemDesignIntf::Split && m_printer->pageSize() != static_cast<QPrinter::PageSize>(page->pageSize()) &&
printerPageRect.width() < page->geometry().width())
{
qreal pageWidth = page->geometry().width();
qreal pageHeight = page->geometry().height();
QRectF currentPrintingRect = printerPageRect;
qreal curHeight = 0;
qreal curWidth = 0;
bool first = true;
while (pageHeight > 0){
while (curWidth < pageWidth){
if (!first) m_printer->newPage(); else first = false;
m_renderPage.render(m_painter, m_printer->pageRect(), currentPrintingRect);
currentPrintingRect.adjust(printerPageRect.size().width(), 0, printerPageRect.size().width(), 0);
curWidth += printerPageRect.size().width();
}
pageHeight -= printerPageRect.size().height();
curHeight += printerPageRect.size().height();
currentPrintingRect = printerPageRect;
currentPrintingRect.adjust(0, curHeight, 0, curHeight);
curWidth = 0;
}
} else {
if (page->getSetPageSizeToPrinter()){
QRectF source = page->geometry();
QSizeF inchSize = source.size() / (100 * 2.54);
QRectF target = QRectF(QPoint(0,0), inchSize * m_printer->resolution());
m_renderPage.render(m_painter, target, source);
} else {
m_renderPage.render(m_painter);
}
}
page->setPos(backupPagePos);
m_renderPage.removePageItem(page);
if (backupPage) backupPage->reactivatePageItem(page);
#else
if (!m_firstPage && !m_painter->isActive()) return false;
PageDesignIntf* backupPage = dynamic_cast<PageDesignIntf*>(page->scene());
QPointF backupPagePos = page->pos();
page->setPos(0,0);
m_renderPage.setPageItem(page);
m_renderPage.setSceneRect(m_renderPage.pageItem()->mapToScene(m_renderPage.pageItem()->rect()).boundingRect());
initPrinter(m_renderPage.pageItem());
if (!m_firstPage){
m_printer->newPage();
} else {
m_painter = new QPainter(m_printer);
if (!m_painter->isActive()) return false;
m_firstPage = false;
}
qreal leftMargin = m_printer->pageLayout().margins().left();
qreal topMargin = m_printer->pageLayout().margins().top();
qreal rightMargin = m_printer->pageLayout().margins().right();
qreal bottomMargin = m_printer->pageLayout().margins().bottom();
#endif
QRectF printerPageRect = m_printer->pageRect(QPrinter::Millimeter);
printerPageRect = QRectF(0,0,(printerPageRect.size().width() + rightMargin + leftMargin) * page->unitFactor(),
(printerPageRect.size().height() + bottomMargin + topMargin) * page->unitFactor());
if (page->printBehavior() == PageItemDesignIntf::Split && m_printer->pageLayout().pageSize() != QPageSize((QPageSize::PageSizeId)page->pageSize()) &&
(printerPageRect.size().height() + bottomMargin + topMargin) * page->unitFactor());
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
if (page->printBehavior() == PageItemDesignIntf::Split &&
m_printer->pageSize() != static_cast<QPrinter::PageSize>(page->pageSize()) &&
printerPageRect.width() < page->geometry().width())
{
#else
if (
page->printBehavior() == PageItemDesignIntf::Split &&
m_printer->pageLayout().pageSize() != QPageSize((QPageSize::PageSizeId)page->pageSize()) &&
printerPageRect.width() < page->geometry().width()
){
#endif
qreal pageWidth = page->geometry().width();
qreal pageHeight = page->geometry().height();
QRectF currentPrintingRect = printerPageRect;
qreal curHeight = 0;
qreal curWidth = 0;
QRectF currentPrintingRect = printerPageRect;
bool first = true;
while (pageHeight > 0){
while (curWidth < pageWidth){
if (!first) m_printer->newPage(); else first = false;
m_renderPage.render(m_painter, m_printer->pageRect(QPrinter::Millimeter), currentPrintingRect);
currentPrintingRect.adjust(printerPageRect.size().width(), 0, printerPageRect.size().width(), 0);
m_renderPage.render(m_painter, QRectF(), currentPrintingRect);
curWidth += printerPageRect.size().width();
currentPrintingRect = QRectF(
curWidth, 0,
printerPageRect.size().width() > (pageWidth - curWidth) ? (pageWidth - curWidth) : printerPageRect.size().width(), pageHeight
);
}
pageHeight -= printerPageRect.size().height();
@@ -1943,7 +1899,6 @@ bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page)
page->setPos(backupPagePos);
m_renderPage.removePageItem(page);
if (backupPage) backupPage->reactivatePageItem(page);
#endif
return true;
}
@@ -1952,14 +1907,14 @@ void PrintProcessor::initPrinter(PageItemDesignIntf* page)
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
if (page->oldPrintMode()){
m_printer->setPageMargins(page->leftMargin(),
page->topMargin(),
page->rightMargin(),
page->bottomMargin(),
QPrinter::Millimeter);
page->topMargin(),
page->rightMargin(),
page->bottomMargin(),
QPrinter::Millimeter);
m_printer->setOrientation(static_cast<QPrinter::Orientation>(page->pageOrientation()));
QSizeF pageSize = (page->pageOrientation()==PageItemDesignIntf::Landscape)?
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
m_printer->setPaperSize(pageSize,QPrinter::Millimeter);
} else {
m_printer->setFullPage(page->fullPage());
@@ -1968,13 +1923,13 @@ void PrintProcessor::initPrinter(PageItemDesignIntf* page)
m_printer->setOrientation(static_cast<QPrinter::Orientation>(page->pageOrientation()));
if (page->pageSize()==PageItemDesignIntf::Custom){
QSizeF pageSize = (page->pageOrientation()==PageItemDesignIntf::Landscape)?
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
m_printer->setPaperSize(pageSize, QPrinter::Millimeter);
m_printer->setPaperSize(pageSize, QPrinter::Millimeter);
} else {
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
m_printer->setPaperSize(static_cast<QPrinter::PageSize>(page->pageSize()));
m_printer->setPaperSize(static_cast<QPrinter::PageSize>(page->pageSize()));
}
}
#else
@@ -1982,23 +1937,23 @@ void PrintProcessor::initPrinter(PageItemDesignIntf* page)
m_printer->setPageMargins(QMarginsF(page->leftMargin(), page->topMargin(), page->rightMargin(), page->bottomMargin()),QPageLayout::Millimeter);
m_printer->setPageOrientation((QPageLayout::Orientation)page->pageOrientation());
QSizeF pageSize = (page->pageOrientation()==PageItemDesignIntf::Landscape)?
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
m_printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter));
} else {
} else {
m_printer->setFullPage(page->fullPage());
if (page->dropPrinterMargins())
m_printer->setPageMargins(QMarginsF(0, 0, 0, 0), QPageLayout::Point);
m_printer->setPageOrientation((QPageLayout::Orientation)page->pageOrientation());
if (page->pageSize()==PageItemDesignIntf::Custom){
QSizeF pageSize = (page->pageOrientation()==PageItemDesignIntf::Landscape)?
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
m_printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter));
m_printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter));
} else {
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
m_printer->setPageSize(QPageSize((QPageSize::PageSizeId)page->pageSize()));
m_printer->setPageSize(QPageSize((QPageSize::PageSizeId)page->pageSize()));
}
}
#endif
@@ -2181,4 +2136,3 @@ qreal WatermarkHelper::valueToPixels(qreal value)
}// namespace LimeReport

View File

@@ -32,6 +32,7 @@
#include "lrglobal.h"
#include "lrreportrender.h"
#include "lrgroupbands.h"
#include "lrpagedesignintf.h"
#include "lrbanddesignintf.h"
#include "lritemdesignintf.h"
@@ -66,9 +67,9 @@ bool ReportRender::isNeedToRearrangeColumnsItems()
maxHeightColumn = i;
}
if (maxHeightColumn>0 && columnItemsCount(maxHeightColumn)<avg &&
maxHeight> lastColumnItem(maxHeightColumn-1)->height()
){
return true;
maxHeight> lastColumnItem(maxHeightColumn-1)->height()
){
return true;
}
}
return false;
@@ -78,8 +79,8 @@ BandDesignIntf *ReportRender::lastColumnItem(int columnIndex)
{
if (columnIndex<0) return 0;
for(int i=0;i<m_columnedBandItems.size();++i){
if (m_columnedBandItems[i]->columnIndex()>columnIndex)
return m_columnedBandItems[i-1];
if (m_columnedBandItems[i]->columnIndex()>columnIndex)
return m_columnedBandItems[i-1];
}
return m_columnedBandItems.last();
}
@@ -90,15 +91,15 @@ void ReportRender::rearrangeColumnsItems()
qreal startHeight = columnHeigth(0);
int avg = m_columnedBandItems.size() / m_columnedBandItems[0]->columnsCount();
for (int i = 1; i < m_columnedBandItems[0]->columnsCount(); ++i){
if (columnItemsCount(i) < avg){
int getCount = avg * (m_columnedBandItems[0]->columnsCount()-i) - columnItemsCount(i);
for (int j = 0; j < getCount; ++j){
BandDesignIntf* band = lastColumnItem(i-1);
band->setPos(band->pos().x()+band->width(),m_columnedBandItems[0]->pos().y());
band->setColumnIndex(i);
}
if (columnItemsCount(i) < avg){
int getCount = avg * (m_columnedBandItems[0]->columnsCount()-i) - columnItemsCount(i);
for (int j = 0; j < getCount; ++j){
BandDesignIntf* band = lastColumnItem(i-1);
band->setPos(band->pos().x()-30,m_columnedBandItems[0]->pos().y());
band->setColumnIndex(i);
}
}
}
}
m_renderPageItem->relocateBands();
m_maxHeightByColumn[0]+=startHeight-maxColumnHeight();
@@ -122,9 +123,9 @@ qreal ReportRender::columnHeigth(int columnIndex)
{
qreal result = 0;
for(int i=0;i<m_columnedBandItems.size();++i){
if (m_columnedBandItems[i]->columnIndex()==columnIndex)
result += m_columnedBandItems[i]->height();
if (m_columnedBandItems[i]->columnIndex()>columnIndex) break;
if (m_columnedBandItems[i]->columnIndex()==columnIndex)
result += m_columnedBandItems[i]->height();
if (m_columnedBandItems[i]->columnIndex()>columnIndex) break;
}
return result;
}
@@ -206,7 +207,7 @@ void ReportRender::analizeItem(ContentItemDesignIntf* contentItem, BandDesignInt
rx.setMinimal(true);
if (rx.indexIn(content)>=0){
functions.append(functionName);
}
}
#endif
}
if (functions.size()>0)
@@ -270,7 +271,7 @@ void ReportRender::renderPage(PageItemDesignIntf* patternPage, bool isTOC, bool
startNewPage(true);
renderReportHeader(m_patternPageItem, AfterPageHeader);
m_dataSourceSorted = false;
BandDesignIntf* lastRenderedBand = 0;
for (int i=0;i<m_patternPageItem->dataBandCount() && !m_renderCanceled; i++){
lastRenderedBand = m_patternPageItem->dataBandAt(i);
@@ -416,7 +417,7 @@ void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentIt
if (dataBand){
GroupFunction* gf = datasources()->addGroupFunction(
functionName, captures.at(Const::VALUE_INDEX), band->objectName(), dataBand->objectName()
);
);
if (gf){
connect(dataBand, SIGNAL(bandRendered(BandDesignIntf*)),
gf, SLOT(slotBandRendered(BandDesignIntf*)));
@@ -426,7 +427,7 @@ void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentIt
} else {
GroupFunction* gf = datasources()->addGroupFunction(
functionName, captures.at(Const::VALUE_INDEX), band->objectName(), captures.at(dsIndex)
);
);
gf->setInvalid(tr("Databand \"%1\" not found").arg(captures.at(dsIndex)));
}
}
@@ -474,7 +475,7 @@ void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentIt
gf->setInvalid(tr("Wrong using function %1").arg(functionName));
}
}
}
}
#endif
}
@@ -510,14 +511,14 @@ void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentIte
QString expressionIndex = datasources()->putGroupFunctionsExpressions(captures.at(Const::VALUE_INDEX));
if (captures.size()<5){
content.replace(captures.at(0), QString("%1(%2,%3)")
.arg(functionName).arg('"'+expressionIndex+'"').arg('"'+band->objectName()+'"'));
.arg(functionName).arg('"'+expressionIndex+'"').arg('"'+band->objectName()+'"'));
} else {
content.replace(captures.at(0), QString("%1(%2,%3,%4)").arg(
functionName,
'"'+expressionIndex+'"',
'"'+band->objectName()+'"',
captures.at(4)
));
functionName,
'"'+expressionIndex+'"',
'"'+band->objectName()+'"',
captures.at(4)
));
}
}
match = rx.match(content, pos + match.capturedLength());
@@ -536,11 +537,11 @@ void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentIte
content.replace(captures.at(0),QString("%1(%2,%3)").arg(functionName).arg('"'+expressionIndex+'"').arg('"'+band->objectName()+'"'));
} else {
content.replace(captures.at(0),QString("%1(%2,%3,%4)").arg(
functionName,
'"'+expressionIndex+'"',
'"'+band->objectName()+'"',
captures.at(4)
));
functionName,
'"'+expressionIndex+'"',
'"'+band->objectName()+'"',
captures.at(4)
));
}
}
pos += rx.matchedLength();
@@ -573,8 +574,8 @@ void ReportRender::replaceGroupsFunction(BandDesignIntf *band)
QColor ReportRender::makeBackgroundColor(BandDesignIntf* band){
if (band->useAlternateBackgroundColor()){
return datasources()->variable(QLatin1String("line_") + band->objectName().toLower()).toInt() %2 == 0 ?
band->backgroundColor() :
band->alternateBackgroundColor();
band->backgroundColor() :
band->alternateBackgroundColor();
}
return band->backgroundColor();
}
@@ -591,12 +592,12 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
BandDesignIntf* bandClone = 0;
if (bandData){
bandClone = bandData;
bandClone = bandData;
} else {
bandClone = renderData(patternBand);
}
if (isLast) bandClone->setBootomSpace(1);
if (isLast) bandClone->setBottomSpace(1);
if (mode == ForcedStartPage){
savePage();
@@ -613,7 +614,7 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
if ( isLast && bandClone->keepFooterTogether() && bandClone->sliceLastRow() ){
if (m_maxHeightByColumn[m_currentColumn] < (bandClone->height()+m_reportFooterHeight))
m_maxHeightByColumn[m_currentColumn] -= ((m_maxHeightByColumn[m_currentColumn]-bandClone->height())+(bandClone->height()*calcSlicePercent(bandClone->height())));
}
}
if (!bandClone->isEmpty() || patternBand->printIfEmpty()){
if (!registerBand(bandClone)){
@@ -645,7 +646,7 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
patternBand->bandHeader()->columnsCount()>1 &&
!m_lostHeadersMoved &&
patternBand->bandNestingLevel() == 0
){
){
renderBand(patternBand->bandHeader(), 0, mode);
}
} else {
@@ -697,7 +698,7 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
m_lastRenderedFooter = 0;
if (!dataBand->datasourceName().isEmpty())
bandDatasource = datasources()->dataSource(dataBand->datasourceName());
bandDatasource = datasources()->dataSource(dataBand->datasourceName());
BandDesignIntf* header = dataBand->bandHeader();
BandDesignIntf* footer = dataBand->bandFooter();
@@ -778,7 +779,7 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
}
if (!dataBand->keepFooterTogether())
m_reprintableBands.removeOne(header);
m_reprintableBands.removeOne(header);
if (header) recalcIfNeeded(header);
bool didGoBack = !bandDatasource->eof() && bandDatasource->prior();
@@ -812,7 +813,7 @@ void ReportRender::renderPageHeader(PageItemDesignIntf *patternPage)
if (band){
if (m_datasources->variable("#PAGE").toInt()!=1 ||
band->property("printOnFirstPage").toBool()
)
)
renderBand(band, 0);
}
}
@@ -964,6 +965,14 @@ void ReportRender::renderDataHeader(BandDesignIntf *header)
void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* dataSource, bool firstTime)
{
GroupBandHeader *group = dynamic_cast<GroupBandHeader*>(parentBand);
if(dataSource->model() && group && !group->groupFieldName().isEmpty() && !m_dataSourceSorted)
{
dataSource->model()->sort(dataSource->columnIndexByName(group->groupFieldName()),group->SortFieldNameBy());
qDebug()<<"sorted;";
m_dataSourceSorted = true;
}
foreach(BandDesignIntf* band,parentBand->childrenByType(BandDesignIntf::GroupHeader)){
IGroupBand* gb = dynamic_cast<IGroupBand*>(band);
if (gb&&gb->isNeedToClose(datasources())){
@@ -1153,7 +1162,7 @@ void ReportRender::placeBandOnPage(BandDesignIntf* band, int columnIndex){
bool isMultiColumnHeader(BandDesignIntf* band){
return ( (band->columnsCount() > 1 ) &&
(band->isHeader() &&
(band->isHeader() &&
((band->bandNestingLevel() == 0) || (band->columnsFillDirection() == BandDesignIntf::Horizontal))));
}
@@ -1182,7 +1191,7 @@ bool ReportRender::registerBand(BandDesignIntf *band, bool registerInChildren)
}
if ( (band->columnsCount() > 1) &&
(!band->isHeader() || (band->bandNestingLevel() > 0 && band->columnsFillDirection() != BandDesignIntf::Horizontal ))){
(!band->isHeader() || (band->bandNestingLevel() > 0 && band->columnsFillDirection() != BandDesignIntf::Horizontal ))){
if (band->columnsFillDirection() == BandDesignIntf::Horizontal){
if (m_currentColumn < band->columnsCount()-1)
@@ -1194,7 +1203,7 @@ bool ReportRender::registerBand(BandDesignIntf *band, bool registerInChildren)
if ((m_currentColumn !=0) &&
(m_maxHeightByColumn[0] == m_maxHeightByColumn[m_currentColumn]) &&
(m_maxHeightByColumn[0] >= band->height())
){
){
m_currentColumn = 0;
}
}
@@ -1203,13 +1212,13 @@ bool ReportRender::registerBand(BandDesignIntf *band, bool registerInChildren)
m_currentColumn = m_currentColumn == -1 ? 0: m_currentColumn;
if ( (band->height() <= m_maxHeightByColumn[m_currentColumn]) ||
m_patternPageItem->endlessHeight() ||
(isMultiColumnHeader(band) && (band->height() <= m_maxHeightByColumn[0]))
){
m_patternPageItem->endlessHeight() ||
(isMultiColumnHeader(band) && (band->height() <= m_maxHeightByColumn[0]))
){
if ( (band->bandType() == BandDesignIntf::PageFooter) ){
for (int i=0; i < m_maxHeightByColumn.size(); ++i)
m_maxHeightByColumn[i]+=band->height();
for (int i=0; i < m_maxHeightByColumn.size(); ++i)
m_maxHeightByColumn[i]+=band->height();
}
if ( isMultiColumnHeader(band)){
@@ -1245,7 +1254,7 @@ bool ReportRender::registerBand(BandDesignIntf *band, bool registerInChildren)
band->bandType()!=BandDesignIntf::ReportFooter &&
!list->contains(band) &&
!band->reprintOnEachPage()
)
)
list->append(band);
}
@@ -1283,7 +1292,7 @@ BandDesignIntf* ReportRender::sliceBand(BandDesignIntf *band, BandDesignIntf* pa
DataBandDesignIntf* data = dynamic_cast<DataBandDesignIntf*>(band);
if (isLast && data && data->keepFooterTogether() &&
band->height()<m_maxHeightByColumn[m_currentColumn] && band->sliceLastRow()
){
){
if (band->height()>(m_maxHeightByColumn[m_currentColumn]-m_reportFooterHeight)){
m_maxHeightByColumn[m_currentColumn] -= ((m_maxHeightByColumn[m_currentColumn]-band->height())+(band->height()*calcSlicePercent(band->height())));
}
@@ -1341,9 +1350,9 @@ void ReportRender::createTOCMarker(bool startNewRange)
BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, int height, BandDesignIntf* patternBand)
{
int sliceHeight = height;
BandDesignIntf* upperBandPart = dynamic_cast<BandDesignIntf*>(band->cloneUpperPart(sliceHeight));
BandDesignIntf* bottomBandPart = dynamic_cast<BandDesignIntf*>(band->cloneBottomPart(sliceHeight));
//int sliceHeight = height;
BandDesignIntf* upperBandPart = dynamic_cast<BandDesignIntf*>(band->cloneUpperPart(height));
BandDesignIntf* bottomBandPart = dynamic_cast<BandDesignIntf*>(band->cloneBottomPart(height));
if (!bottomBandPart->isEmpty()){
if (patternBand->keepFooterTogether())
closeFooterGroup(patternBand);
@@ -1351,6 +1360,7 @@ BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, i
bottomBandPart->copyBookmarks(band);
}
if (!upperBandPart->isEmpty()){
upperBandPart->setBottomSpace(0);
upperBandPart->updateItemSize(m_datasources, FirstPass, height);
registerBand(upperBandPart);
upperBandPart->copyBookmarks(band);
@@ -1366,7 +1376,7 @@ BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, i
patternBand->bandHeader()->columnsCount()>1 &&
!m_lostHeadersMoved &&
patternBand->bandNestingLevel() == 0
){
){
renderBand(patternBand->bandHeader(), 0, StartNewPageAsNeeded);
}
@@ -1398,6 +1408,7 @@ BandDesignIntf *ReportRender::renderData(BandDesignIntf *patternBand, bool emitB
emit(patternBand->preparedForRender());
bandClone->updateItemSize(m_datasources);
bandClone->setBottomSpace(patternBand->height() - patternBand->findMaxBottom());
//m_scriptEngineContext->baseDesignIntfToScript(bandClone);
emit(patternBand->afterData());
@@ -1484,7 +1495,7 @@ void ReportRender::checkFooterGroup(BandDesignIntf *groupBand)
foreach(BandDesignIntf* band, *holder){
qreal percent = band->height()*100 / m_dataAreaSize;
if (m_renderedDataBandCount<=1 || percent>20 ){
holder->removeAll(band);
holder->removeAll(band);
}
}
}
@@ -1523,8 +1534,8 @@ void ReportRender::checkLostHeadersOnPrevPage()
it.toBack();
if (it.hasPrevious()){
if (it.previous()->isFooter()){
if (it.hasPrevious()) it.previous();
else return;
if (it.hasPrevious()) it.previous();
else return;
}
}
@@ -1561,8 +1572,8 @@ void ReportRender::checkLostHeadersInPrevColumn()
it.toBack();
if (it.hasPrevious()){
if (it.previous()->isFooter()){
if (it.hasPrevious()) it.previous();
else return;
if (it.hasPrevious()) it.previous();
else return;
}
}
@@ -1578,7 +1589,7 @@ void ReportRender::checkLostHeadersInPrevColumn()
if (lostHeaders.size() > 0){
m_lostHeadersMoved = true;
// std::sort(lostHeaders.begin(), lostHeaders.end(), bandLessThen);
// std::sort(lostHeaders.begin(), lostHeaders.end(), bandLessThen);
std::sort(lostHeaders.begin(), lostHeaders.end(), bandLessThen);
foreach(BandDesignIntf* header, lostHeaders){
registerBand(header);
@@ -1596,7 +1607,7 @@ BandDesignIntf* ReportRender::findEnclosingGroup()
foreach(BandDesignIntf* gb, m_childBands.keys()){
if (m_childBands.value(gb)->tryToKeepTogether()&&
((gb->bandIndex()<groupIndex)||(groupIndex==-1))
){
){
result=gb;
groupIndex=result->bandIndex();
}
@@ -1671,7 +1682,7 @@ void ReportRender::savePage(bool isLast)
pageHeight += band->height();
}
m_renderPageItem->setHeight(pageHeight + 10 +
(m_patternPageItem->topMargin() + m_patternPageItem->bottomMargin()) * Const::mmFACTOR);
(m_patternPageItem->topMargin() + m_patternPageItem->bottomMargin()) * Const::mmFACTOR);
}
}

View File

@@ -92,7 +92,7 @@ public:
enum BandPrintMode {PrintAlwaysPrintable, PrintNotAlwaysPrintable };
enum ResetPageNuberType{BandReset, PageReset};
enum PageRenderStage{BeforePageHeader, AfterPageHeader};
typedef QSharedPointer<ReportRender> Ptr;
typedef QSharedPointer<ReportRender> Ptr;
~ReportRender();
ReportRender(QObject *parent = 0);
void setDatasources(DataSourceManager* value);
@@ -220,6 +220,7 @@ private:
unsigned long long m_currentNameIndex;
bool m_newPageStarted;
bool m_lostHeadersMoved;
bool m_dataSourceSorted = false;
};
} // namespace LimeReport

View File

@@ -649,7 +649,7 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){
QVariant varValue;
if (script.contains(rx)){
#else
#else
QRegularExpression rx = getScriptRegEx();
QVariant varValue;
@@ -712,9 +712,12 @@ int ScriptEngineManager::getPageFreeSpace(PageItemDesignIntf* page){
height += band->geometry().height() * m_dataManager->dataSource(band->datasourceName())->model()->rowCount();
}
else height += band->height();
}
height += (page->topMargin() + page->bottomMargin()) * Const::mmFACTOR;
return page->height() - height - (page->pageFooter()?page->pageFooter()->height() : 0);
} else return -1;
} else return 0;
}
void ScriptEngineManager::addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent)
@@ -1073,6 +1076,79 @@ bool ScriptEngineManager::createReopenDatasourceFunction()
return addFunction(fd);
}
bool ScriptEngineManager::createGetFieldByRowIndexEx()
{
JSFunctionDesc fd;
fd.setManager(m_functionManager);
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
fd.setCategory(tr("GENERAL"));
fd.setName("getFieldByRowIndexEx");
fd.setDescription("getFieldByRowIndexEx(\"" + tr("FieldName") + "\", \"" + tr("RowIndex")
+ "\", \"" + tr("RoleIndex") + "\")");
fd.setScriptWrapper(QString("function getFieldByRowIndexEx(fieldName, rowIndex, role){"
"return %1.getFieldByRowIndexEx(fieldName, rowIndex, role);}")
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
return addFunction(fd);
}
bool ScriptEngineManager::createGetFieldByRowIndexEx2()
{
JSFunctionDesc fd;
fd.setManager(m_functionManager);
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
fd.setCategory(tr("GENERAL"));
fd.setName("getFieldByRowIndexEx2");
fd.setDescription("getFieldByRowIndexEx2(\"" + tr("FieldName") + "\", \"" + tr("RowIndex")
+ "\", \"" + tr("RoleName") + "\")");
fd.setScriptWrapper(QString("function getFieldByRowIndexEx2(fieldName, rowIndex, role){"
"return %1.getFieldByRowIndexEx2(fieldName, rowIndex, role);}")
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
return addFunction(fd);
}
bool ScriptEngineManager::createHeaderData()
{
JSFunctionDesc fd;
fd.setManager(m_functionManager);
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
fd.setCategory(tr("GENERAL"));
fd.setName("getHeaderData");
fd.setDescription("getHeaderData(\"" + tr("FieldName") + "\", \"" + tr("RoleName") + "\")");
fd.setScriptWrapper(QString("function getHeaderData(fieldName, role){"
"return %1.getHeaderData(fieldName, role);}")
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
return addFunction(fd);
}
bool ScriptEngineManager::createHeaderColumnNameByIndex()
{
JSFunctionDesc fd;
fd.setManager(m_functionManager);
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
fd.setCategory(tr("GENERAL"));
fd.setName("getHeaderColumnNameByIndex");
fd.setDescription("getHeaderColumnNameByIndex(\"" + tr("datasourceName") + "\", \""
+ tr("columnIndex") + "\")");
fd.setScriptWrapper(QString("function getHeaderColumnNameByIndex(datasourceName, columnIndex){"
"return %1.getHeaderColumnNameByIndex(datasourceName, columnIndex);}")
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
return addFunction(fd);
}
bool ScriptEngineManager::createColumnCount()
{
JSFunctionDesc fd;
fd.setManager(m_functionManager);
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
fd.setCategory(tr("GENERAL"));
fd.setName("getColumnCount");
fd.setDescription("getColumnCount(\"" + tr("datasourceName") + "\")");
fd.setScriptWrapper(QString("function getColumnCount(datasourceName){"
"return %1.getColumnCount(datasourceName);}")
.arg(LimeReport::Const::FUNCTION_MANAGER_NAME));
return addFunction(fd);
}
ScriptEngineManager::ScriptEngineManager()
:m_model(0), m_context(0), m_dataManager(0)
{
@@ -1114,6 +1190,11 @@ ScriptEngineManager::ScriptEngineManager()
createAddTableOfContentsItemFunction();
createClearTableOfContentsFunction();
createReopenDatasourceFunction();
createGetFieldByRowIndexEx();
createGetFieldByRowIndexEx2();
createHeaderData();
createHeaderColumnNameByIndex();
createColumnCount();
m_model = new ScriptEngineModel(this);
}
@@ -1866,6 +1947,42 @@ QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool it
return result;
}
QVariant ScriptFunctionsManager::getFieldByRowIndexEx(const QString &fieldName, int rowIndex, const int role)
{
DataSourceManager *dm = scriptEngineManager()->dataManager();
return dm->fieldDataByRowIndex(fieldName, rowIndex, role);
}
QVariant ScriptFunctionsManager::getFieldByRowIndexEx2(const QString &fieldName, int rowIndex, const QString &roleName)
{
DataSourceManager *dm = scriptEngineManager()->dataManager();
return dm->fieldDataByRowIndex(fieldName, rowIndex, roleName);
}
QVariant ScriptFunctionsManager::getHeaderData(const QString &fieldName, const QString &roleName)
{
DataSourceManager *dm = scriptEngineManager()->dataManager();
return dm->headerData(fieldName, roleName);
}
QVariant ScriptFunctionsManager::getHeaderColumnNameByIndex(const QString &datasourceName, const int columnIndex)
{
DataSourceManager *dm = scriptEngineManager()->dataManager();
return dm->columnName(datasourceName, columnIndex);
}
int ScriptFunctionsManager::getColumnCount(const QString &datasourceName)
{
DataSourceManager *dm = scriptEngineManager()->dataManager();
return dm->columnCount(datasourceName);
}
int ScriptFunctionsManager::columnIndexByName(const QString &datasourceName, const QString &columnName)
{
DataSourceManager *dm = scriptEngineManager()->dataManager();
return dm->columnIndex(datasourceName,columnName);
}
#ifdef USE_QJSENGINE
void ScriptFunctionsManager::addItemsToComboBox(QJSValue object, const QStringList &values)

View File

@@ -378,6 +378,44 @@ public:
Q_INVOKABLE void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent = 0);
Q_INVOKABLE void clearTableOfContents();
Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false);
/*!
* \brief getFieldByRowIndexEx Выдает для поля значение заданной роли
* \param fieldName имя источника данных + имя поля
* \param rowIndex индекс строки
* \param role код роли
* \return
*/
Q_INVOKABLE QVariant getFieldByRowIndexEx(const QString &fieldName, int rowIndex, const int role);
/*!
* \brief getFieldByRowIndexEx2 Выдает для поля значение заданной роли
* \param fieldName имя источника данных + имя поля
* \param rowIndex индекс строки
* \param roleName имя роли из roleNames()
* \return
*/
Q_INVOKABLE QVariant getFieldByRowIndexEx2(const QString &fieldName, int rowIndex, const QString &roleName);
/*!
* \brief getHeaderData Выдает для поля заголовка значение заданной роли
* \param fieldName имя источника данных + имя поля
* \param role имя роли из roleNames()
* \return
*/
Q_INVOKABLE QVariant getHeaderData(const QString &fieldName, const QString &roleName);
/*!
* \brief getHeaderColumnNameByIndex Выдает имя колонки по ее индексу (имя используемое LR)
* \param datasourceName имя источника данных
* \param columnIndex индекс колонки
* \return
*/
Q_INVOKABLE QVariant getHeaderColumnNameByIndex(const QString &datasourceName, const int columnIndex);
/*!
* \brief getColumnCount Выдает число столбцов в источнике данных
* \param datasourceName имя источника данных
* \return возможно -1 при ошибке
*/
Q_INVOKABLE int getColumnCount(const QString &datasourceName);
Q_INVOKABLE int columnIndexByName(const QString &datasourceName, const QString &columnName);
#ifdef USE_QJSENGINE
Q_INVOKABLE void addItemsToComboBox(QJSValue object, const QStringList& values);
Q_INVOKABLE void addItemToComboBox(QJSValue object, const QString& value);
@@ -506,6 +544,12 @@ private:
bool createAddTableOfContentsItemFunction();
bool createClearTableOfContentsFunction();
bool createReopenDatasourceFunction();
bool createGetFieldByRowIndexEx();
bool createGetFieldByRowIndexEx2();
bool createHeaderData();
bool createHeaderColumnNameByIndex();
bool createColumnCount();
private:
ScriptEngineManager();
ScriptEngineType* m_scriptEngine;

View File

@@ -174,6 +174,8 @@ void QObjectPropertyModel::translatePropertyName()
tr("gridChartLines");
tr("horizontalAxisOnTop");
tr("mixWithPriorPage");
tr("shadow");
tr("borderStyle");
}
void QObjectPropertyModel::clearObjectsList()

View File

@@ -135,9 +135,6 @@ void EnumPropItem::translateEnumItemName()
tr("Pie");
tr("VerticalBar");
tr("HorizontalBar");
tr("LegendAlignTop");
tr("LegendAlignCenter");
tr("LegendAlignBottom");
tr("TitleAlignLeft");
tr("TitleAlignRight");
tr("TitleAlignCenter");
@@ -147,6 +144,31 @@ void EnumPropItem::translateEnumItemName()
tr("Inches");
tr("Scale");
tr("Split");
tr("GridLines");
tr("Lines");
tr("Solid");
tr("NoStyle");
tr("Dashed");
tr("Dot");
tr("DashDot");
tr("DashDotDot");
tr("Doubled");
tr("LegendPoints");
tr("LegendLines");
tr("LegendAlignRightCenter");
tr("LegendAlignRightTop");
tr("LegendAlignRightBottom");
tr("LegendAlignBottomRight");
tr("LegendAlignBottomCenter");
tr("LegendAlignBottomLeft");
tr("SolidLine");
tr("NoPen");
tr("DashLine");
tr("DotLine");
tr("DashDotLine");
tr("DashDotDotLine");
tr("CustomDashLine");
}
void EnumPropItem::setPropertyEditorData(QWidget *propertyEditor, const QModelIndex &) const

View File

@@ -22,16 +22,17 @@ QModelIndex CompleterModel::index(int row, int column, const QModelIndex &parent
return createIndex(row, column, parentItem->child(row));
}
QModelIndex CompleterModel::parent(const QModelIndex &child) const
{
if (child.isValid()){
CompleterItem *childItem = static_cast<CompleterItem*>(child.internalPointer());
CompleterItem *parentItem = childItem->parent();
if (parentItem != &m_root) {
return indexFromItem(parentItem);
}
QModelIndex CompleterModel::parent(const QModelIndex &child) const {
if(child.isValid()) {
if(CompleterItem *childItem = static_cast<CompleterItem *>(child.internalPointer());
childItem) {
CompleterItem *parentItem = childItem->parent();
if(parentItem != &m_root) {
return indexFromItem(parentItem);
}
}
return QModelIndex();
}
return QModelIndex();
}
int CompleterModel::rowCount(const QModelIndex &parent) const

View File

@@ -12,7 +12,9 @@ public:
CompleterItem(QString text, QIcon icon):m_parent(0), m_text(text), m_icon(icon), m_model(0){}
~CompleterItem();
int rowCount() const {return m_children.count();}
CompleterItem* child(int row) const {return m_children.at(row).data();}
CompleterItem *child(int row) const {
return m_children.count() > row ? m_children.at(row).data() : nullptr;
}
CompleterItem* parent() const {return m_parent;}
int row() const{
if (m_parent){
@@ -33,7 +35,7 @@ public:
void appendRow(CompleterItem* child);
void appendRows(const QList<CompleterItem *> &children);
private:
CompleterItem* m_parent;
CompleterItem* m_parent{nullptr};
QVector<QSharedPointer<CompleterItem> > m_children;
QString m_text;
QIcon m_icon;

View File

@@ -80,7 +80,8 @@ bool XMLWriter::setContent(QString fileName)
{
QFile xmlFile(fileName);
if (xmlFile.open(QFile::ReadOnly)){
return m_doc->setContent(&xmlFile);
m_doc->setContent(&xmlFile);
return true;
}
return false;
}