[qet] [2878] master propertie widget:

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2878
Author:   blacksun
Date:     2014-02-27 00:57:22 +0100 (Thu, 27 Feb 2014)
Log Message:
-----------
master propertie widget:
can link/unlink slave to master
can show element by double clic item on the list
reset modification 

Modified Paths:
--------------
    trunk/sources/diagramcommands.cpp
    trunk/sources/diagramcommands.h
    trunk/sources/ui/elementpropertieswidget.cpp
    trunk/sources/ui/folioreportproperties.cpp
    trunk/sources/ui/folioreportproperties.h
    trunk/sources/ui/masterpropertieswidget.cpp
    trunk/sources/ui/masterpropertieswidget.h

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2014-02-26 14:09:25 UTC (rev 2877)
+++ trunk/sources/diagramcommands.cpp	2014-02-26 23:57:22 UTC (rev 2878)
@@ -1152,11 +1152,11 @@
 LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCommand *parent) :
 	QUndoCommand(parent),
 	diagram_(elmt1->diagram()),
-	elmt_1(elmt1),
-	elmt_2(elmt2),
+	element_(elmt1),
 	previous_report(0),
 	first_redo(true)
 {
+	elmt_list << elmt2;
 	if (elmt1->linkType() & Element::AllReport &&
 		elmt2->linkType() & Element::AllReport) {
 		setText(QObject::tr("Lier deux reports de folio",
@@ -1164,6 +1164,21 @@
 		if(!elmt1->isFree())
 			previous_report = elmt1->linkedElements().first();
 	}
+	else if (element_->linkType() & Element::Master)
+			setText(QObject::tr("Editer les r\351f\351rence crois\351", "edite the cross reference"));
+	else	setText(QObject::tr("Lier deux éléments"));
+}
+
+LinkElementsCommand::LinkElementsCommand(Element *elmt1, QList<Element *> &elmtList, QUndoCommand *parent) :
+	QUndoCommand(parent),
+	diagram_(elmt1->diagram()),
+	element_(elmt1),
+	elmt_list(elmtList),
+	previous_report(0),
+	first_redo(true)
+{
+	if (element_->linkType() & Element::Master)
+				 setText(QObject::tr("Editer les r\351f\351rence crois\351"));
 	else setText(QObject::tr("Lier deux éléments"));
 }
 
@@ -1179,9 +1194,13 @@
  */
 void LinkElementsCommand::undo() {
 	diagram_->showMe();
-	elmt_1->unlinkElement(elmt_2);
+
+	foreach (Element *elmt, elmt_list)
+		element_->unlinkElement(elmt);
+
 	if (previous_report)
-		elmt_1->linkToElement(previous_report);
+		element_->linkToElement(previous_report);
+	QUndoCommand::undo();
 }
 
 /**
@@ -1190,14 +1209,18 @@
  */
 void LinkElementsCommand::redo() {
 	diagram_->showMe();
-	elmt_1->linkToElement(elmt_2);
-	//Check if text of this potential is identical.
-	if (first_redo) {
-		if(elmt_1->conductors().count() && elmt_2->conductors().count()) {
-			ConductorAutoNumerotation::checkPotential(elmt_1->conductors().first());
+
+	foreach (Element *elmt, elmt_list)
+		element_->linkToElement(elmt);
+
+	//If element are report, check if text of this potential is identical.
+	if ((element_->linkType() &Element::AllReport) && first_redo) {
+		if(element_->conductors().count() && elmt_list.first()->conductors().count()) {
+			ConductorAutoNumerotation::checkPotential(element_->conductors().first());
 		}
 		first_redo = false;
 	}
+	QUndoCommand::redo();
 }
 
 /**
@@ -1218,6 +1241,21 @@
 }
 
 /**
+ * @brief unlinkElementsCommand::unlinkElementsCommand
+ * @param elmt1 Element to set the link
+ * @param elmtList list of all element to be linked to elmt1
+ * @param parent undo command
+ */
+unlinkElementsCommand::unlinkElementsCommand(Element *elmt1, QList<Element *> &elmtList, QUndoCommand *parent):
+	QUndoCommand(parent),
+	diagram_(elmt1->diagram()),
+	element_(elmt1),
+	elmt_list(elmtList)
+{
+	setText(QObject::tr("D\351lier %n \351l\351ment(s)", "", elmt_list.size()));
+}
+
+/**
  * @brief unlinkElementsCommand::~unlinkElementsCommand
  * destructor
  */
@@ -1230,6 +1268,7 @@
 void unlinkElementsCommand::undo() {
 	foreach (Element *elmt, elmt_list)
 		element_->linkToElement(elmt);
+	QUndoCommand::undo();
 }
 
 /**
@@ -1239,4 +1278,5 @@
 void unlinkElementsCommand::redo() {
 	foreach (Element *elmt, elmt_list)
 		element_->unlinkElement(elmt);
+	QUndoCommand::redo();
 }

Modified: trunk/sources/diagramcommands.h
===================================================================
--- trunk/sources/diagramcommands.h	2014-02-26 14:09:25 UTC (rev 2877)
+++ trunk/sources/diagramcommands.h	2014-02-26 23:57:22 UTC (rev 2878)
@@ -591,6 +591,7 @@
 	public:
 	// constructor destructor
 	LinkElementsCommand (Element *elmt1, Element *elmt2, QUndoCommand *parent = 0);
+	LinkElementsCommand (Element *elmt1, QList <Element *> &elmtList, QUndoCommand *parent = 0);
 	virtual ~LinkElementsCommand();
 	//methods
 	virtual void undo();
@@ -599,7 +600,8 @@
 	private:
 	//attributes
 	Diagram *diagram_;
-	Element *elmt_1, *elmt_2, *previous_report;
+	Element *element_, *previous_report;
+	QList <Element *> elmt_list;
 	bool first_redo;
 };
 
@@ -607,6 +609,7 @@
 	public:
 	//constructor destructor
 	unlinkElementsCommand (Element *elmt1, Element *elmt2 = 0, QUndoCommand *parent = 0);
+	unlinkElementsCommand (Element *elmt1, QList <Element *> &elmtList, QUndoCommand *parent = 0);
 	virtual ~unlinkElementsCommand();
 	//methods
 	virtual void undo();

Modified: trunk/sources/ui/elementpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/elementpropertieswidget.cpp	2014-02-26 14:09:25 UTC (rev 2877)
+++ trunk/sources/ui/elementpropertieswidget.cpp	2014-02-26 23:57:22 UTC (rev 2878)
@@ -158,10 +158,12 @@
 
 	switch (answer) {
 		case QDialogButtonBox::ResetRole:
+			if (mpw_) mpw_->reset();
 			break;
 		case QDialogButtonBox::ApplyRole:
-			if (frp_) frp_->Apply();		//folio report widget
-			else if (eiw_) eiw_->apply();	//element information widget
+			if (frp_) frp_->Apply();	//folio report widget
+			if (eiw_) eiw_->apply();	//element information widget
+			if (mpw_) mpw_->apply();	//master property widget
 			this->accept();
 		case QDialogButtonBox::RejectRole:
 			this->reject();

Modified: trunk/sources/ui/folioreportproperties.cpp
===================================================================
--- trunk/sources/ui/folioreportproperties.cpp	2014-02-26 14:09:25 UTC (rev 2877)
+++ trunk/sources/ui/folioreportproperties.cpp	2014-02-26 23:57:22 UTC (rev 2878)
@@ -140,8 +140,10 @@
  * @param elmt: element to be displayed
  */
 void FolioReportProperties::showElement(Element *elmt) {
+	QList <Element *> elmt_list = element_list;
+	elmt_list << element_->linkedElements() << element_;
+	foreach (Element *elmt, elmt_list) elmt->setSelected(false);
 	elmt->diagram()->showMe();
-	foreach (QGraphicsItem *qgi, elmt->diagram()->selectedItems()) qgi->setSelected(false);
 	elmt->setSelected(true);
 }
 

Modified: trunk/sources/ui/folioreportproperties.h
===================================================================
--- trunk/sources/ui/folioreportproperties.h	2014-02-26 14:09:25 UTC (rev 2877)
+++ trunk/sources/ui/folioreportproperties.h	2014-02-26 23:57:22 UTC (rev 2878)
@@ -25,6 +25,11 @@
 	class FolioReportProperties;
 }
 
+/**
+ * @brief The FolioReportProperties class
+ * This class is a widget for make link between two reports element.
+ * This class embendded the undo/redo command when apply new connection.
+ */
 class FolioReportProperties : public QWidget
 {
 	Q_OBJECT

Modified: trunk/sources/ui/masterpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/masterpropertieswidget.cpp	2014-02-26 14:09:25 UTC (rev 2877)
+++ trunk/sources/ui/masterpropertieswidget.cpp	2014-02-26 23:57:22 UTC (rev 2878)
@@ -20,7 +20,14 @@
 #include <QListWidgetItem>
 #include <diagramposition.h>
 #include <elementprovider.h>
+#include <diagramcommands.h>
 
+/**
+ * @brief MasterPropertiesWidget::MasterPropertiesWidget
+ * Default constructor
+ * @param elmt
+ * @param parent
+ */
 MasterPropertiesWidget::MasterPropertiesWidget(Element *elmt, QWidget *parent) :
 	QWidget(parent),
 	ui(new Ui::MasterPropertiesWidget),
@@ -28,14 +35,80 @@
 {
 	ui->setupUi(this);
 	buildInterface();
+	connect(ui->free_list,		SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
+	connect(ui->linked_list,	SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showElementFromLWI(QListWidgetItem*)));
 }
 
+/**
+ * @brief MasterPropertiesWidget::~MasterPropertiesWidget
+ * Destructor
+ */
 MasterPropertiesWidget::~MasterPropertiesWidget()
 {
+	foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false);
 	delete ui;
 }
 
+/**
+ * @brief MasterPropertiesWidget::apply
+ * Do what we need when apply new conf
+ */
+void MasterPropertiesWidget::apply() {
+	QList <Element *> to_link;
+	QList <Element *> linked_ = element_->linkedElements();
+
+	for (int i=0; i<ui->linked_list->count(); i++) {
+		to_link << lwi_hash[ui->linked_list->item(i)];
+	}
+
+	//If same element are find in to_link and linked, that means
+	// element are already linked, so we remove element on the two list
+	//if linked_ contains element at the end of the operation,
+	//that means this element must be unlinked from @element_
+	foreach (Element *elmt, to_link) {
+		if(linked_.contains(elmt)) {
+			to_link.removeAll(elmt);
+			linked_.removeAll(elmt);
+		}
+	}
+
+	// if two list, contain element, we link and unlink @element_ with corresponding
+	//undo command, and add first command for parent of the second, user see only one
+	//undo command
+	if (linked_.count() && to_link.count()) {
+		LinkElementsCommand *lec = new LinkElementsCommand(element_, to_link);
+		new unlinkElementsCommand(element_, linked_, lec);
+		element_->diagram()->undoStack().push(lec);
+	}
+	//Else do the single undo command corresponding to the link.
+	else if (to_link.count()) {
+		LinkElementsCommand *lec = new LinkElementsCommand(element_, to_link);
+		element_->diagram()->undoStack().push(lec);
+	}
+	else if (linked_.count()) {
+		unlinkElementsCommand *uec = new unlinkElementsCommand(element_, linked_);
+		element_->diagram()->undoStack().push(uec);
+	}
+}
+
+/**
+ * @brief MasterPropertiesWidget::reset
+ * Reset curent widget, clear eveything and rebuild widget.
+ */
+void MasterPropertiesWidget::reset() {
+	foreach (QListWidgetItem *lwi, lwi_hash.keys()) {
+		delete lwi;
+	}
+	lwi_hash.clear();
+	buildInterface();
+}
+
+/**
+ * @brief MasterPropertiesWidget::buildInterface
+ * Build the interface of the widget
+ */
 void MasterPropertiesWidget::buildInterface() {
+	//build the free list
 	ElementProvider elmt_prov(element_->diagram()->project());
 
 	foreach(Element *elmt, elmt_prov.freeElement(Element::Slave)) {
@@ -47,8 +120,23 @@
 																	  .arg(title)
 																	  .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
 		QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text);
+		lwi_hash.insert(lwi_, elmt);
 		ui->free_list->addItem(lwi_);
 	}
+
+	//build the linked list
+	foreach(Element *elmt, element_->linkedElements()) {
+		//label for list widget
+		QString widget_text;
+		QString title = elmt->diagram()->title();
+		if (title.isEmpty()) title = tr("Sans titre");
+		widget_text += QString(tr("Folio\240 %1 (%2), position %3.")).arg(elmt->diagram()->folioIndex() + 1)
+																	  .arg(title)
+																	  .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString());
+		QListWidgetItem *lwi_ = new QListWidgetItem(elmt->pixmap(), widget_text);
+		lwi_hash.insert(lwi_, elmt);
+		ui->linked_list->addItem(lwi_);
+	}
 }
 
 /**
@@ -62,9 +150,25 @@
 					ui->free_list->currentRow()));
 }
 
+/**
+ * @brief MasterPropertiesWidget::on_unlink_button_clicked
+ * move curent item in linked_list to free_list
+ */
 void MasterPropertiesWidget::on_unlink_button_clicked() {
 	//take the curent item from linked_list and push it to free_list
 	ui->free_list->addItem(
 				ui->linked_list->takeItem(
 					ui->linked_list->currentRow()));
 }
+
+/**
+ * @brief MasterPropertiesWidget::showElementFromLWI
+ * Show the element corresponding to the given QListWidgetItem
+ * @param lwi
+ */
+void MasterPropertiesWidget::showElementFromLWI(QListWidgetItem *lwi) {
+	foreach(Element *elmt, lwi_hash.values()) elmt->setHighlighted(false);
+	Element *elmt = lwi_hash[lwi];
+	elmt->diagram()->showMe();
+	elmt->setHighlighted(true);
+}

Modified: trunk/sources/ui/masterpropertieswidget.h
===================================================================
--- trunk/sources/ui/masterpropertieswidget.h	2014-02-26 14:09:25 UTC (rev 2877)
+++ trunk/sources/ui/masterpropertieswidget.h	2014-02-26 23:57:22 UTC (rev 2878)
@@ -25,6 +25,12 @@
 	class MasterPropertiesWidget;
 }
 
+/**
+ * @brief The MasterPropertiesWidget class
+ * This class is a widget for make link between a master element with several slave element.
+ * This class embenddedthe undo/redo command when apply new connection.
+ */
+
 class MasterPropertiesWidget : public QWidget
 {
 	Q_OBJECT
@@ -33,16 +39,21 @@
 	explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0);
 	~MasterPropertiesWidget();
 
+	void apply();
+	void reset();
+
 	private:
 	void buildInterface();
 
 	private slots:
 	void on_link_button_clicked();
 	void on_unlink_button_clicked();
+	void showElementFromLWI(QListWidgetItem *lwi);
 
 	private:
 	Ui::MasterPropertiesWidget *ui;
 	Element *element_;
+	QHash <QListWidgetItem *, Element *> lwi_hash;
 };
 
 #endif // MASTERPROPERTIESWIDGET_H


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/