folio report: improve GUI and add unlinkcommand

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2720 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-01-08 19:27:38 +00:00
parent ae7e6938d1
commit 601e4faaa0
5 changed files with 142 additions and 18 deletions

View File

@@ -1143,12 +1143,16 @@ LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCo
QUndoCommand(parent),
diagram_(elmt1->diagram()),
elmt_1(elmt1),
elmt_2(elmt2)
elmt_2(elmt2),
previous_report(0)
{
if (elmt1->linkType() & Element::AllReport &&
elmt2->linkType() & Element::AllReport)
elmt2->linkType() & Element::AllReport) {
setText(QObject::tr("Lier deux reports de folio",
"title for undo LinkElementsCommand if two elements are folio report"));
if(!elmt1->isFree())
previous_report = elmt1->linkedElements().first();
}
else setText(QObject::tr("Lier deux éléments"));
}
@@ -1165,6 +1169,8 @@ LinkElementsCommand::~LinkElementsCommand(){}
void LinkElementsCommand::undo() {
diagram_->showMe();
elmt_1->unlinkElement(elmt_2);
if (previous_report)
elmt_1->linkToElement(previous_report);
}
/**
@@ -1175,3 +1181,44 @@ void LinkElementsCommand::redo() {
diagram_->showMe();
elmt_1->linkToElement(elmt_2);
}
/**
* @brief unlinkElementsCommand::unlinkElementsCommand
* Constructor, unlink elmt2 or all elements if elmt2 isn't specified
* @param elmt1 element to set undo command
* @param elmt2 element to be unlinked
* @param parent undo parent
*/
unlinkElementsCommand::unlinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCommand *parent):
QUndoCommand(parent),
diagram_(elmt1->diagram()),
element_(elmt1)
{
if (elmt2) elmt_list << elmt2;
else elmt_list << elmt1->linkedElements();
setText(QObject::tr("D\351lier %n \351l\351ment(s)", "", elmt_list.size()));
}
/**
* @brief unlinkElementsCommand::~unlinkElementsCommand
* destructor
*/
unlinkElementsCommand::~unlinkElementsCommand(){}
/**
* @brief unlinkElementsCommand::undo
*undo command
*/
void unlinkElementsCommand::undo() {
foreach (Element *elmt, elmt_list)
element_->linkToElement(elmt);
}
/**
* @brief unlinkElementsCommand::redo
*redo command
*/
void unlinkElementsCommand::redo() {
foreach (Element *elmt, elmt_list)
element_->unlinkElement(elmt);
}

View File

@@ -599,7 +599,23 @@ class LinkElementsCommand : public QUndoCommand {
private:
//attributes
Diagram *diagram_;
Element *elmt_1, *elmt_2;
Element *elmt_1, *elmt_2, *previous_report;
};
class unlinkElementsCommand : public QUndoCommand {
public:
//constructor destructor
unlinkElementsCommand (Element *elmt1, Element *elmt2 = 0, QUndoCommand *parent = 0);
virtual ~unlinkElementsCommand();
//methods
virtual void undo();
virtual void redo();
private:
//attributes
Diagram *diagram_;
Element *element_;
QList <Element *> elmt_list;
};
#endif

View File

@@ -5,6 +5,7 @@
#include <elementprovider.h>
#include <qetgraphicsitem/elementtextitem.h>
#include <diagramcommands.h>
#include "qeticons.h"
/**
* @brief FolioReportProperties::FolioReportProperties : Construcor
@@ -18,11 +19,9 @@ FolioReportProperties::FolioReportProperties(Element *elmt, QWidget *parent) :
ui(new Ui::FolioReportProperties)
{
ui->setupUi(this);
sm_ = new QSignalMapper(this);
connect(sm_, SIGNAL(mapped(int)) , this, SLOT(linkToElement(int)));
BuildRadioList();
unlink = false;
if(element_->isFree()) buildRadioList();
else buildUnlinkButton();
}
/**
@@ -36,7 +35,12 @@ FolioReportProperties::~FolioReportProperties()
/**
* @brief FolioReportProperties::BuildRadioList : build the radio list for each available folio report
*/
void FolioReportProperties::BuildRadioList() {
void FolioReportProperties::buildRadioList() {
sm_ = new QSignalMapper(this);
connect(sm_, SIGNAL(mapped(int)), this, SLOT(linkToElement(int)));
sm_show_ = new QSignalMapper(this);
connect(sm_show_, SIGNAL(mapped(int)), this, SLOT(showDiagram(int)));
//Research the invert report of @element_
int rep = element_->linkType() == Element::NextReport? Element::PreviousReport : Element::NextReport;
ElementProvider ep(element_->diagram()->project(), element_->diagram());
@@ -53,23 +57,71 @@ void FolioReportProperties::BuildRadioList() {
.arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
//button himself
QHBoxLayout *hl = new QHBoxLayout(this);
QRadioButton *rb = new QRadioButton(button_text , this);
ui->available_report_layout->addWidget(rb);
QPushButton *pb = new QPushButton(QET::Icons::ZoomDraw,"",this);
hl->addWidget(rb);
hl->addStretch();
hl->addWidget(pb);
ui->available_report_layout->addLayout(hl);
element_list << elmt;
//map the radio button signal
connect(rb, SIGNAL(clicked()), sm_, SLOT(map()));
sm_ -> setMapping(rb, element_list.size()-1);
//map the push button show diagram
connect(pb, SIGNAL(clicked()), sm_show_, SLOT(map()));
sm_show_->setMapping(pb, element_list.size()-1);
}
}
ui->available_report_layout->addStretch();
}
/**
* @brief FolioReportProperties::buildUnlinkButton
*build button for ask user if want to unlink this element
*/
void FolioReportProperties::buildUnlinkButton() {
unlink_widget = new QWidget(this);
QHBoxLayout *unlink_layout = new QHBoxLayout(unlink_widget);
QLabel *lb = new QLabel(tr("Ce report est d\351j\340 lier."), unlink_widget);
QPushButton *pb = new QPushButton(tr("D\351lier"), unlink_widget);
connect(pb, SIGNAL(clicked()), this, SLOT(unlinkClicked()));
unlink_layout->addWidget(lb);
unlink_layout->addStretch();
unlink_layout->addWidget(pb);
ui->v_main_layout->insertWidget(0, unlink_widget);
}
/**
* @brief FolioReportProperties::Apply
* Apply the new properties for this folio report
*/
void FolioReportProperties::Apply() {
if (element_to_link) {
if (unlink && !element_to_link)
element_->diagram()->undoStack().push(new unlinkElementsCommand(element_));
else if (element_to_link)
element_->diagram()->undoStack().push(new LinkElementsCommand(element_, element_to_link));
}
/**
* @brief FolioReportProperties::unlinkClicked
*this slot remove unlink_layout and call buildRadioList
*/
void FolioReportProperties::unlinkClicked() {
ui->v_main_layout->removeWidget(unlink_widget);
delete unlink_widget;
unlink = true;
buildRadioList();
}
/**
* @brief FolioReportProperties::showDiagram
* Show the wanted report element
* @param i position of wanted element in element_list
*/
void FolioReportProperties::showDiagram(const int i) {
Element *elmt = element_list.at(i);
elmt->diagram()->showMe();
foreach (QGraphicsItem *qgi, elmt->diagram()->selectedItems()) qgi->setSelected(false);
elmt->setSelected(true);
}

View File

@@ -15,19 +15,22 @@ class FolioReportProperties : public QWidget
public:
explicit FolioReportProperties(Element *elmt, QWidget *parent = 0);
~FolioReportProperties();
void BuildRadioList();
void buildRadioList();
void buildUnlinkButton();
void Apply();
private slots:
void linkToElement(const int i) {element_to_link = element_list.at(i);}
void unlinkClicked();
void showDiagram(const int i);
private:
Element *element_, *element_to_link;
QList <Element *> element_list;
Ui::FolioReportProperties *ui;
QSignalMapper *sm_;
QSignalMapper *sm_, *sm_show_;
QWidget *unlink_widget;
bool unlink;
};
#endif // FOLIOREPORTPROPERTIES_H

View File

@@ -14,8 +14,11 @@
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" name="main_H_layout">
<layout class="QVBoxLayout" name="v_main_layout">
<item>
<widget class="QGroupBox" name="Report_gb">
<property name="toolTip">
@@ -61,6 +64,9 @@
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
</widget>