[qet] qet/qet: [5294] Remove, move and clean some functions of diagram view, among other things because it is not the role of the diagram view to provide these functions.

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


Revision: 5294
Author:   blacksun
Date:     2018-04-04 13:02:40 +0200 (Wed, 04 Apr 2018)
Log Message:
-----------
Remove, move and clean some functions of diagram view, among other things because it is not the role of the diagram view to provide these functions.

Modified Paths:
--------------
    trunk/sources/diagramcontent.cpp
    trunk/sources/diagramcontent.h
    trunk/sources/diagramview.cpp
    trunk/sources/diagramview.h
    trunk/sources/qetdiagrameditor.cpp

Modified: trunk/sources/diagramcontent.cpp
===================================================================
--- trunk/sources/diagramcontent.cpp	2018-04-02 18:31:01 UTC (rev 5293)
+++ trunk/sources/diagramcontent.cpp	2018-04-04 11:02:40 UTC (rev 5294)
@@ -198,6 +198,20 @@
 }
 
 /**
+ * @brief DiagramContent::hasCopiableItems
+ * @return true if this diagram content have copiable items.
+ */
+bool DiagramContent::hasCopiableItems() const
+{
+	if(!m_images.isEmpty())      return true;
+	if(!m_shapes.isEmpty())      return true;
+	if(!m_elements.isEmpty())    return true;
+	if(!m_text_fields.isEmpty()) return true;
+	
+	return false;
+}
+
+/**
  * @brief DiagramContent::clear
  * Remove all items from the diagram content
  */

Modified: trunk/sources/diagramcontent.h
===================================================================
--- trunk/sources/diagramcontent.h	2018-04-02 18:31:01 UTC (rev 5293)
+++ trunk/sources/diagramcontent.h	2018-04-04 11:02:40 UTC (rev 5294)
@@ -79,6 +79,7 @@
 		QList<ElementTextItemGroup *> selectedTextsGroup() const;
 		QList<Conductor *> conductors(int = AnyConductor) const;
 		bool hasDeletableItems() const;
+		bool hasCopiableItems() const;
 		QList<QGraphicsItem *> items(int = All) const;
 		QString sentence(int = All) const;
 		int count(int = All) const;

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2018-04-02 18:31:01 UTC (rev 5293)
+++ trunk/sources/diagramview.cpp	2018-04-04 11:02:40 UTC (rev 5294)
@@ -539,7 +539,7 @@
 			current_project->changeTabDown();
 			return;
 		case Qt::Key_Home:
-			if (!hasTextItems()) {
+			if (dc.selectedTexts().isEmpty()) {
 				if (
 					qgraphicsitem_cast<IndependentTextItem *>(m_diagram->focusItem()) ||
 					qgraphicsitem_cast<ConductorTextItem *>(m_diagram->focusItem()) ||
@@ -551,7 +551,7 @@
 			}
 			else break;
 		case Qt::Key_End:
-			if (!hasTextItems()) {
+			if (dc.selectedTexts().isEmpty()) {
 				if (
 					qgraphicsitem_cast<IndependentTextItem *>(m_diagram->focusItem()) ||
 					qgraphicsitem_cast<ConductorTextItem *>(m_diagram->focusItem()) ||
@@ -708,84 +708,6 @@
 }
 
 /**
-	@return true s'il y a des items selectionnes sur le schema et que ceux-ci
-	peuvent etre copies dans le presse-papier, false sinon
-*/
-bool DiagramView::hasCopiableItems() {
-	foreach(QGraphicsItem *qgi, m_diagram -> selectedItems()) {
-		if (
-			qgraphicsitem_cast<Element *>(qgi) ||
-			qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
-			qgraphicsitem_cast<QetShapeItem *>(qgi) ||
-			qgraphicsitem_cast<DiagramImageItem *>(qgi)
-		) {
-			return(true);
-		}
-	}
-	return(false);
-}
-
-/**
-	@return true if there is any Text Item selected
-*/
-bool DiagramView::hasTextItems() {
-	foreach(QGraphicsItem *qgi, m_diagram -> selectedItems()) {
-		if (
-			qgraphicsitem_cast<IndependentTextItem *>(qgi) ||
-			qgraphicsitem_cast<ConductorTextItem *>(qgi) ||
-			qgraphicsitem_cast<DiagramTextItem *>(qgi)
-		) {
-			return(true);
-		}
-	}
-	return(false);
-}
-
-/**
-	Ajoute une colonne au schema.
-*/
-void DiagramView::addColumn() {
-	if (m_diagram -> isReadOnly()) return;
-	BorderProperties old_bp = m_diagram -> border_and_titleblock.exportBorder();
-	BorderProperties new_bp = m_diagram -> border_and_titleblock.exportBorder();
-	new_bp.columns_count += 1;
-	m_diagram -> undoStack().push(new ChangeBorderCommand(m_diagram, old_bp, new_bp));
-}
-
-/**
-	Enleve une colonne au schema.
-*/
-void DiagramView::removeColumn() {
-	if (m_diagram -> isReadOnly()) return;
-	BorderProperties old_bp = m_diagram -> border_and_titleblock.exportBorder();
-	BorderProperties new_bp = m_diagram -> border_and_titleblock.exportBorder();
-	new_bp.columns_count -= 1;
-	m_diagram -> undoStack().push(new ChangeBorderCommand(m_diagram, old_bp, new_bp));
-}
-
-/**
-	Agrandit le schema en hauteur
-*/
-void DiagramView::addRow() {
-	if (m_diagram -> isReadOnly()) return;
-	BorderProperties old_bp = m_diagram -> border_and_titleblock.exportBorder();
-	BorderProperties new_bp = m_diagram -> border_and_titleblock.exportBorder();
-	new_bp.rows_count += 1;
-	m_diagram -> undoStack().push(new ChangeBorderCommand(m_diagram, old_bp, new_bp));
-}
-
-/**
-	Retrecit le schema en hauteur
-*/
-void DiagramView::removeRow() {
-	if (m_diagram -> isReadOnly()) return;
-	BorderProperties old_bp = m_diagram -> border_and_titleblock.exportBorder();
-	BorderProperties new_bp = m_diagram -> border_and_titleblock.exportBorder();
-	new_bp.rows_count -= 1;
-	m_diagram -> undoStack().push(new ChangeBorderCommand(m_diagram, old_bp, new_bp));
-}
-
-/**
  * @brief DiagramView::adjustSceneRect
  * Calcul and set the area of the scene visualized by this view
  */

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2018-04-02 18:31:01 UTC (rev 5293)
+++ trunk/sources/diagramview.h	2018-04-04 11:02:40 UTC (rev 5294)
@@ -60,14 +60,8 @@
 	public:
 		QString title() const;
 		void editDiagramProperties();
-		void addColumn();
-		void removeColumn();
-		void addRow();
-		void removeRow();
 		Diagram *diagram() { return(m_diagram); }
 		QETDiagramEditor *diagramEditor() const;
-		bool hasCopiableItems();
-		bool hasTextItems();
 		void editSelection();
 		void setEventInterface (DVEventInterface *event_interface);
 	

Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp	2018-04-02 18:31:01 UTC (rev 5293)
+++ trunk/sources/qetdiagrameditor.cpp	2018-04-04 11:02:40 UTC (rev 5294)
@@ -1279,16 +1279,22 @@
 	QString value = action->data().toString();
 	DiagramView *dv = currentDiagram();
 
-	if (!dv || value.isEmpty()) return;
+	if (!dv || value.isEmpty() || dv->diagram()->isReadOnly()) return;
 
+	Diagram *d = dv->diagram();
+	BorderProperties old_bp = d->border_and_titleblock.exportBorder();
+	BorderProperties new_bp = d->border_and_titleblock.exportBorder();
+	
 	if (value == "add_column")
-		dv->addColumn();
+		new_bp.columns_count += 1;
 	else if (value == "remove_column")
-		dv->removeColumn();
+		new_bp.columns_count -= 1;
 	else if (value == "add_row")
-		dv->addRow();
+		new_bp.rows_count += 1;
 	else if (value == "remove_row")
-		dv->removeRow();
+		new_bp.rows_count -= 1;
+	
+	d->undoStack().push(new ChangeBorderCommand(d, old_bp, new_bp));
 }
 
 /**
@@ -1408,7 +1414,7 @@
 	m_find_element->setEnabled(selected_elements_count == 1);
 	
 		//Action that need items (elements, conductors, texts...) selected, to be enabled
-	bool copiable_items  = dv->hasCopiableItems();
+	bool copiable_items  = dc.hasCopiableItems();
 	bool deletable_items = dc.hasDeletableItems();
 	m_cut              -> setEnabled(!ro && copiable_items);
 	m_copy             -> setEnabled(copiable_items);


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