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

Items context menu has been added

Fields drag & drop init  band datasource if it empty
This commit is contained in:
Arin Alexander 2017-02-24 07:13:43 +03:00
parent 117023e920
commit a2c93601d0
10 changed files with 177 additions and 12 deletions

View File

@ -42,6 +42,7 @@
#include "lrsimpletagparser.h"
#include "lrtextitemeditor.h"
#include "lrreportengine_p.h"
#include <QMenu>
namespace{
@ -80,6 +81,51 @@ int TextItem::fakeMarginSize() const{
return marginSize()+5;
}
void TextItem::preparePopUpMenu(QMenu &menu)
{
QAction* editAction = menu.addAction(QIcon(":/report/images/edit_pecil2.png"),tr("Edit"));
menu.insertAction(menu.actions().at(0),editAction);
menu.insertSeparator(menu.actions().at(1));
menu.addSeparator();
QAction* action = menu.addAction(tr("Auto height"));
action->setCheckable(true);
action->setChecked(autoHeight());
action = menu.addAction(tr("Allow HTML"));
action->setCheckable(true);
action->setChecked(allowHTML());
action = menu.addAction(tr("Allow HTML in fields"));
action->setCheckable(true);
action->setChecked(allowHTMLInFields());
action = menu.addAction(tr("Strethc to max height"));
action->setCheckable(true);
action->setChecked(stretchToMaxHeight());
}
void TextItem::processPopUpAction(QAction *action)
{
if (action->text().compare(tr("Edit")) == 0){
this->showEditorDialog();
}
if (action->text().compare(tr("Auto height")) == 0){
setProperty("autoHeight",action->isChecked());
}
if (action->text().compare(tr("Allow HTML")) == 0){
setProperty("allowHTML",action->isChecked());
}
if (action->text().compare(tr("Allow HTML in fields")) == 0){
setProperty("allowHTMLInFields",action->isChecked());
}
if (action->text().compare(tr("Strethc to max height")) == 0){
setProperty("stretchToMaxHeight",action->isChecked());
}
}
void TextItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* style, QWidget* widget) {
Q_UNUSED(widget);
Q_UNUSED(style);

View File

@ -172,6 +172,8 @@ protected:
int fakeMarginSize() const;
QString getTextPart(int height, int skipHeight);
void restoreLinksEvent();
void preparePopUpMenu(QMenu &menu);
void processPopUpAction(QAction *action);
private:
void initTextSizes() const;
void setTextFont(TextPtr text, const QFont &value) const;

View File

@ -33,6 +33,7 @@
#include <algorithm>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QMenu>
namespace LimeReport {
@ -431,6 +432,34 @@ void BandDesignIntf::moveItemsDown(qreal startPos, qreal offset){
}
}
void BandDesignIntf::preparePopUpMenu(QMenu &menu)
{
foreach (QAction* action, menu.actions()) {
if (action->text().compare(tr("Bring to top")) == 0 ||
action->text().compare(tr("Send to back")) == 0 )
action->setEnabled(false);
}
menu.addSeparator();
QAction* autoHeightAction = menu.addAction(tr("Auto height"));
autoHeightAction->setCheckable(true);
autoHeightAction->setChecked(autoHeight());
QAction* autoSplittableAction = menu.addAction(tr("Splittable"));
autoSplittableAction->setCheckable(true);
autoSplittableAction->setChecked(isSplittable());
}
void BandDesignIntf::processPopUpAction(QAction *action)
{
if (action->text().compare(tr("Auto height")) == 0){
setProperty("autoHeight",action->isChecked());
}
if (action->text().compare(tr("Splittable")) == 0){
setProperty("splittable",action->isChecked());
}
}
BaseDesignIntf* BandDesignIntf::cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent)
{
int maxBottom = 0;
@ -804,6 +833,14 @@ void BandDesignIntf::setStartNewPage(bool startNewPage)
m_startNewPage = startNewPage;
}
void BandDesignIntf::setAutoHeight(bool value){
if (m_autoHeight != value){
m_autoHeight=value;
if (!isLoading())
notify("autoHeight",!value,value);
}
}
bool BandDesignIntf::reprintOnEachPage() const
{
return m_reprintOnEachPage;

View File

@ -207,7 +207,7 @@ public:
bool startNewPage() const;
void setStartNewPage(bool startNewPage);
void setAutoHeight(bool value){m_autoHeight=value;}
void setAutoHeight(bool value);
bool autoHeight(){return m_autoHeight;}
bool startFromNewPage() const;
@ -244,6 +244,8 @@ protected:
void setColumnsCount(int value);
void setColumnsFillDirection(BandColumnsLayoutType value);
void moveItemsDown(qreal startPos, qreal offset);
void preparePopUpMenu(QMenu &menu);
void processPopUpAction(QAction *action);
private slots:
void childBandDeleted(QObject* band);
private:

View File

@ -35,6 +35,8 @@
#include "qgraphicsitem.h"
#include "lrdesignelementsfactory.h"
#include "lrhorizontallayout.h"
#include "serializators/lrstorageintf.h"
#include "serializators/lrxmlreader.h"
#include <memory>
@ -43,6 +45,8 @@
#include <QApplication>
#include <QDialog>
#include <QVBoxLayout>
#include <QMenu>
#include <QClipboard>
namespace LimeReport
{
@ -1147,6 +1151,53 @@ void BaseDesignIntf::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
QGraphicsItem::mouseDoubleClickEvent(event);
}
void BaseDesignIntf::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
PageDesignIntf* page = dynamic_cast<PageDesignIntf*>(scene());
if (!page->selectedItems().contains(this)){
page->clearSelection();
this->setSelected(true);
}
QMenu menu;
QAction* copyAction = menu.addAction(QIcon(":/report/images/copy.png"), tr("Copy"));
copyAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
QAction* cutAction = menu.addAction(QIcon(":/report//images/cut"), tr("Cut"));
cutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X));
QAction* pasteAction = menu.addAction(QIcon(":/report/images/paste.png"), tr("Paste"));
pasteAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_V));
pasteAction->setEnabled(false);
QClipboard *clipboard = QApplication::clipboard();
ItemsReaderIntf::Ptr reader = StringXMLreader::create(clipboard->text());
if (reader->first() && reader->itemType() == "Object"){
pasteAction->setEnabled(true);
}
menu.addSeparator();
QAction* brinToTopAction = menu.addAction(QIcon(":/report//images/bringToTop"), tr("Bring to top"));
QAction* sendToBackAction = menu.addAction(QIcon(":/report//images/sendToBack"), tr("Send to back"));
menu.addSeparator();
QAction* noBordersAction = menu.addAction(QIcon(":/report//images/noLines"), tr("No borders"));
QAction* allBordersAction = menu.addAction(QIcon(":/report//images/allLines"), tr("All borders"));
preparePopUpMenu(menu);
QAction* a = menu.exec(event->screenPos());
if (a){
if (a == cutAction)
page->cut();
if (a == copyAction)
page->copy();
if (a == pasteAction)
page->paste();
if (a == brinToTopAction)
page->bringToFront();
if (a == sendToBackAction)
page->sendToBack();
if (a == noBordersAction)
page->setBorders(BaseDesignIntf::NoLine);
if (a == allBordersAction)
page->setBorders(BaseDesignIntf::AllLines);
processPopUpAction(a);
}
}
int BaseDesignIntf::possibleMoveDirectionFlags() const
{
return m_possibleMoveDirectionFlags;

View File

@ -124,10 +124,13 @@ public:
TopBotom=2,
All=3
};
enum BorderSide { TopLine = 1,
BottomLine = 2,
LeftLine = 4,
RightLine = 8
enum BorderSide {
NoLine = 0,
TopLine = 1,
BottomLine = 2,
LeftLine = 4,
RightLine = 8,
AllLines = 15
};
enum ObjectState {ObjectLoading, ObjectLoaded, ObjectCreated};
enum ItemAlign {LeftItemAlign,RightItemAlign,CenterItemAlign,ParentWidthItemAlign,DesignedItemAlign};
@ -293,6 +296,7 @@ protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
virtual void geometryChangedEvent(QRectF newRect, QRectF oldRect);
virtual QPen borderPen(BorderSide side) const;
@ -333,6 +337,9 @@ protected:
QVariant m_varValue;
virtual void preparePopUpMenu(QMenu& menu){Q_UNUSED(menu)}
virtual void processPopUpAction(QAction* action){Q_UNUSED(action)}
private:
void updateSelectionMarker();
int resizeDirectionFlags(QPointF position);

View File

@ -56,6 +56,7 @@
#include <QApplication>
#include <QMessageBox>
namespace LimeReport
{
@ -744,6 +745,15 @@ void PageDesignIntf::dropEvent(QGraphicsSceneDragDropEvent* event)
QString data = event->mimeData()->text().remove(0,event->mimeData()->text().indexOf(":")+1);
if (isVar) data = data.remove(QRegExp(" \\[.*\\]"));
ti->setContent(data);
if (!isVar){
BandDesignIntf* parentBand = dynamic_cast<BandDesignIntf*>(ti->parentItem());
if (parentBand && parentBand->datasourceName().isEmpty()){
QRegExp dataSource("(?:\\$D\\{\\s*(.*)\\..*\\})");
if (dataSource.indexIn(data) != -1){
parentBand->setProperty("datasource",dataSource.cap(1));
}
}
}
}
}
@ -1231,8 +1241,13 @@ BaseDesignIntf* PageDesignIntf::findDestObject(BaseDesignIntf* item){
void PageDesignIntf::paste()
{
QClipboard *clipboard = QApplication::clipboard();
if (!selectedItems().isEmpty()) {
BaseDesignIntf* destItem = findDestObject(dynamic_cast<BaseDesignIntf*>(selectedItems().at(0)));
BaseDesignIntf* destItem = 0;
ItemsReaderIntf::Ptr reader = StringXMLreader::create(clipboard->text());
if (reader->first() && reader->itemType() == "Object"){
if (!selectedItems().isEmpty())
destItem = findDestObject(dynamic_cast<BaseDesignIntf*>(selectedItems().at(0)));
else
destItem = this->pageItem();
if (destItem){
CommandIf::Ptr command = PasteCommand::create(this, clipboard->text(), destItem);
saveCommand(command);

View File

@ -33,6 +33,7 @@
#include <QGraphicsScene>
#include <QPrinter>
#include <QMenu>
namespace LimeReport {
@ -519,6 +520,14 @@ void PageItemDesignIntf::initPageSize(const QSizeF& size)
setHeight(size.height());
m_sizeChainging=false;
}
void PageItemDesignIntf::preparePopUpMenu(QMenu &menu)
{
foreach (QAction* action, menu.actions()) {
if (action->text().compare(tr("Paste")) != 0)
action->setVisible(false);
}
}
void PageItemDesignIntf::initPageSize(const PageItemDesignIntf::PageSize &size)
{
m_sizeChainging = true;

View File

@ -127,6 +127,7 @@ protected:
void initPageSize(const PageSize &size);
void initPageSize(const QSizeF &size);
QColor selectionMarkerColor(){return Qt::transparent;}
void preparePopUpMenu(QMenu &menu);
private:
void paintGrid(QPainter *ppainter);
void initColumnsPos(QVector<qreal>&posByColumns, qreal pos, int columnCount);

View File

@ -63,7 +63,6 @@ protected:
void readCollection(QObject *item, QDomElement *node);
QVariant getValue(QDomElement *node);
protected:
bool extractFirstNode();
QString m_error;
@ -72,10 +71,6 @@ private:
QDomElement m_curNode;
QDomElement m_firstNode;
QString m_passPhrase;
};
class FileXMLReader : public XMLReader{