[qet] [3834] Clean up some code

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


Revision: 3834
Author:   blacksun
Date:     2015-03-18 19:07:18 +0100 (Wed, 18 Mar 2015)
Log Message:
-----------
Clean up some code

Modified Paths:
--------------
    trunk/sources/bordertitleblock.cpp
    trunk/sources/bordertitleblock.h
    trunk/sources/diagram.cpp
    trunk/sources/diagram.h
    trunk/sources/diagramcommands.cpp
    trunk/sources/diagramprintdialog.cpp
    trunk/sources/diagramview.cpp
    trunk/sources/dvevent/dveventaddshape.cpp
    trunk/sources/qetgraphicsitem/qgraphicsitemutility.cpp
    trunk/sources/qetgraphicsitem/terminal.cpp

Modified: trunk/sources/bordertitleblock.cpp
===================================================================
--- trunk/sources/bordertitleblock.cpp	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/bordertitleblock.cpp	2015-03-18 18:07:18 UTC (rev 3834)
@@ -66,22 +66,15 @@
 }
 
 /**
-	@return la hauteur du cartouche
-*/
-qreal BorderTitleBlock::titleBlockHeight() const {
-	return(titleblock_template_renderer_ -> height());
-}
-
-/**
  * @brief BorderTitleBlock::titleBlockRect
  * @return the rectangle of the titleblock in scene coordinate.
  */
 QRectF BorderTitleBlock::titleBlockRect() const
 {
 	if (m_edge == Qt::BottomEdge)
-		return QRectF(diagram_rect_.bottomLeft(), QSize(diagram_rect_.width(), titleBlockHeight()));
+		return QRectF(diagram_rect_.bottomLeft(), QSize(diagram_rect_.width(), titleblock_template_renderer_ -> height()));
 	else
-		return QRectF(diagram_rect_.topRight(), QSize(titleBlockHeight(), diagram_rect_.height()));
+		return QRectF(diagram_rect_.topRight(), QSize(titleblock_template_renderer_ -> height(), diagram_rect_.height()));
 }
 
 /**
@@ -99,35 +92,74 @@
 	if (m_edge == Qt::BottomEdge) //Rect at bottom have same position and dimension of displayed rect
 		return titleBlockRect();
 	else
-		return QRectF (diagram_rect_.bottomRight(), QSize(diagram_rect_.height(), titleBlockHeight()));
+		return QRectF (diagram_rect_.bottomRight(), QSize(diagram_rect_.height(), titleblock_template_renderer_ -> height()));
 
 }
 
 /**
- * @brief BorderTitleBlock::borderRect
+ * @brief BorderTitleBlock::borderAndTitleBlockRect
  * @return the bounding rectangle of diagram and titleblock.
+ * It's like unite outsideBorderRect and titleBlockRect.
+ * The rect is in scene coordinate
  */
-QRectF BorderTitleBlock::borderRect() const {
+QRectF BorderTitleBlock::borderAndTitleBlockRect() const {
 	return diagram_rect_ | titleBlockRect();
 }
 
 /**
- * @brief BorderTitleBlock::borderWidth
- * @return the border width
+ * @brief BorderTitleBlock::columnsRect
+ * @return The columns rect in scene coordinate.
+ * If column is not displayed, return a null QRectF
  */
-qreal BorderTitleBlock::borderWidth() const {
-	return borderRect().width();
+QRectF BorderTitleBlock::columnsRect() const
+{
+	if (!display_columns_) return QRectF();
+	return QRectF (Diagram::margin, Diagram::margin, (columns_count_*columns_width_) + rows_header_width_, columns_header_height_);
 }
 
 /**
- * @brief BorderTitleBlock::borderHeight
- * @return the border height
+ * @brief BorderTitleBlock::rowsRect
+ * @return The rows rect in scene coordinate.
+ * If row is not displayed, return a null QRectF
  */
-qreal BorderTitleBlock::borderHeight() const {
-	return borderRect().height();
+QRectF BorderTitleBlock::rowsRect() const
+{
+	if (!display_rows_) return QRectF();
+	return QRectF (Diagram::margin, Diagram::margin, rows_header_width_, (rows_count_*rows_height_) + columns_header_height_);
 }
 
 /**
+ * @brief BorderTitleBlock::outsideBorderRect
+ * @return The rect of outside border (diagram with columns and rows)
+ * The rect is in scene coordinate
+ */
+QRectF BorderTitleBlock::outsideBorderRect() const
+{
+	return QRectF (Diagram::margin, Diagram::margin,
+				  (columns_width_*columns_count_) + rows_header_width_,
+				  (rows_height_*rows_count_) + columns_header_height_);
+}
+
+/**
+ * @brief BorderTitleBlock::insideBorderRect
+ * @return The rect of the inside border, in other word, the drawing area.
+ * This method take care about if rows or columns are displayed or not.
+ * The rect is in scene coordinate
+ */
+QRectF BorderTitleBlock::insideBorderRect() const
+{
+	qreal left = Diagram::margin;
+	qreal top  = Diagram::margin;
+	qreal width  = columns_width_*columns_count_;
+	qreal height = rows_height_*rows_count_;
+
+	display_rows_ ? left += rows_header_width_ : width += rows_header_width_;
+	display_columns_ ? top += columns_header_height_ : height += columns_header_height_;
+
+	return QRectF (left, top, width, height);
+}
+
+/**
 	Exports the title block current values to XML.
 	@param xml_elmt the XML element attributes will be added to
 */
@@ -609,31 +641,23 @@
 }
 
 /**
-	@param pos Position cartesienne (ex : 10.3, 45.2) a transformer en position
-	dans la grille (ex : B2)
-	@return la position dans la grille correspondant a pos
-*/
-DiagramPosition BorderTitleBlock::convertPosition(const QPointF &pos) {
-	// recupere le rectangle quadrille par les en-tetes
-	QRectF grid_rect(
-		rowsHeaderWidth(),
-		columnsHeaderHeight(),
-		diagramWidth(),
-		diagramHeight()
-	);
-	
-	if (!grid_rect.contains(pos)) {
-		return(DiagramPosition("", 0));
-	}
-	
-	QPointF relative_pos = pos - grid_rect.topLeft();
+ * @brief BorderTitleBlock::convertPosition
+ * Convert a Point in cartesian coordinate (x : 12.5, 56.9) to a point in grid coordinate (ex : B2)
+ * @param pos : position to convert
+ * @return the converted point in grid coordinate.
+ */
+DiagramPosition BorderTitleBlock::convertPosition(const QPointF &pos)
+{
+	if(!insideBorderRect().contains(pos))
+		return (DiagramPosition("", 0));
+
+	QPointF relative_pos = pos - insideBorderRect().topLeft();
 	int row_number    = int(ceil(relative_pos.x() / columnsWidth()));
 	int column_number = int(ceil(relative_pos.y() / rowsHeight()));
 	
 	QString letter = "A";
-	for (int i = 1 ; i < column_number ; ++ i) {
+	for (int i = 1 ; i < column_number ; ++ i)
 		letter = incrementLetters(letter);
-	}
 	
 	return(DiagramPosition(letter, row_number));
 }

Modified: trunk/sources/bordertitleblock.h
===================================================================
--- trunk/sources/bordertitleblock.h	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/bordertitleblock.h	2015-03-18 18:07:18 UTC (rev 3834)
@@ -73,18 +73,17 @@
 		qreal diagramWidth() const { return(columnsTotalWidth() + rowsHeaderWidth()); }
 			/// @return the diagram height, i.e. the height of the border without title block
 		qreal diagramHeight() const { return(rowsTotalHeight() + columnsHeaderHeight()); }
-	
-		// title block
-		qreal titleBlockHeight() const;
 
 		QRectF titleBlockRect () const;
 	private:
 		QRectF titleBlockRectForQPainter () const;
 
 	public:
-		QRectF borderRect () const;
-		qreal borderWidth () const;
-		qreal borderHeight() const;
+		QRectF borderAndTitleBlockRect () const;
+		QRectF columnsRect () const;
+		QRectF rowsRect () const;
+		QRectF outsideBorderRect() const;
+		QRectF insideBorderRect() const;
 	
 	// methods to get title block basic data
 	/// @return the value of the title block "Author" field

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/diagram.cpp	2015-03-18 18:07:18 UTC (rev 3834)
@@ -134,7 +134,7 @@
 		p->setPen(pen);
 
 		p -> setBrush(Qt::NoBrush);
-		QRectF rect = drawingRect().intersected(r);
+		QRectF rect = border_and_titleblock.insideBorderRect().intersected(r);
 		qreal limite_x = rect.x() + rect.width();
 		qreal limite_y = rect.y() + rect.height();
 		
@@ -372,8 +372,8 @@
 		source_area = QRectF(
 			0.0,
 			0.0,
-			border_and_titleblock.borderWidth () + 2.0 * margin,
-			border_and_titleblock.borderHeight() + 2.0 * margin
+			border_and_titleblock.borderAndTitleBlockRect().width()  + 2.0 * margin,
+			border_and_titleblock.borderAndTitleBlockRect().height() + 2.0 * margin
 		);
 	}
 	
@@ -415,8 +415,8 @@
 		image_width  = items_rect.width();
 		image_height = items_rect.height();
 	} else {
-		image_width  = border_and_titleblock.borderWidth();
-		image_height = border_and_titleblock.borderHeight();
+		image_width  = border_and_titleblock.borderAndTitleBlockRect().width();
+		image_height = border_and_titleblock.borderAndTitleBlockRect().height();
 	}
 	
 	image_width  += 2.0 * margin;
@@ -1070,41 +1070,6 @@
 }
 
 /**
- * @brief Diagram::border
- * @return The rectangle (coordinates relative to the scene)
- * delimiting the edge of the diagram
- */
-QRectF Diagram::border() const {
-	return border_and_titleblock.borderRect();
-}
-
-/**
- * @brief Diagram::drawingRect
- * @return The rectangle (coordinates relative to the scene)
- * delimiting the drawing area of the diagram.
- * It's like border without columns, rows, and titleblock
- */
-QRectF Diagram::drawingRect() const
-{
-	QPointF topleft(margin, margin);
-	QSizeF size;
-	size.setWidth (border_and_titleblock.columnsTotalWidth());
-	size.setHeight(border_and_titleblock.rowsTotalHeight());
-
-	if (border_and_titleblock.rowsAreDisplayed())
-		topleft.rx() += border_and_titleblock.rowsHeaderWidth();
-	else
-		size.rwidth() += border_and_titleblock.rowsHeaderWidth();
-
-	if (border_and_titleblock.columnsAreDisplayed())
-		topleft.ry() += border_and_titleblock.columnsHeaderHeight();
-	else
-		size.rheight() += border_and_titleblock.columnsHeaderHeight();
-
-	return (QRectF (topleft, size));
-}
-
-/**
 	@return le titre du cartouche
 */
 QString Diagram::title() const {
@@ -1246,11 +1211,8 @@
 	@return la position dans la grille correspondant a pos
 */
 DiagramPosition Diagram::convertPosition(const QPointF &pos) {
-	// decale la position pour prendre en compte les marges en haut a gauche du schema
-	QPointF final_pos = pos - QPointF(margin, margin);
-	
 	// delegue le calcul au BorderTitleBlock
-	DiagramPosition diagram_position = border_and_titleblock.convertPosition(final_pos);
+	DiagramPosition diagram_position = border_and_titleblock.convertPosition(pos);
 	
 	// embarque la position cartesienne
 	diagram_position.setPosition(pos);

Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/diagram.h	2015-03-18 18:07:18 UTC (rev 3834)
@@ -179,9 +179,6 @@
 	void setDrawTerminals(bool);
 	bool drawColoredConductors() const;
 	void setDrawColoredConductors(bool);
-	
-		QRectF border      () const;
-		QRectF drawingRect () const;
 
 	QString title() const;
 	bool toPaintDevice(QPaintDevice &, int = -1, int = -1, Qt::AspectRatioMode = Qt::KeepAspectRatio);

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/diagramcommands.cpp	2015-03-18 18:07:18 UTC (rev 3834)
@@ -876,14 +876,14 @@
 void ChangeTitleBlockCommand::undo() {
 	diagram -> showMe();
 	diagram -> border_and_titleblock.importTitleBlock(old_titleblock);
-	diagram -> invalidate(diagram -> border());
+	diagram -> invalidate(diagram -> border_and_titleblock.borderAndTitleBlockRect());
 }
 
 /// Refait la modification de cartouche
 void ChangeTitleBlockCommand::redo() {
 	diagram -> showMe();
 	diagram -> border_and_titleblock.importTitleBlock(new_titleblock);
-	diagram -> invalidate(diagram -> border());
+	diagram -> invalidate(diagram -> border_and_titleblock.borderAndTitleBlockRect());
 }
 
 /**

Modified: trunk/sources/diagramprintdialog.cpp
===================================================================
--- trunk/sources/diagramprintdialog.cpp	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/diagramprintdialog.cpp	2015-03-18 18:07:18 UTC (rev 3834)
@@ -92,9 +92,9 @@
 QRect DiagramPrintDialog::diagramRect(Diagram *diagram, const ExportProperties &options) const {
 	if (!diagram) return(QRect());
 	
-	QRectF diagram_rect = diagram -> border();
+	QRectF diagram_rect = diagram -> border_and_titleblock.borderAndTitleBlockRect();
 	if (!options.draw_titleblock) {
-		qreal titleblock_height = diagram -> border_and_titleblock.titleBlockHeight();
+		qreal titleblock_height = diagram -> border_and_titleblock.titleBlockRect().height();
 		diagram_rect.setHeight(diagram_rect.height() - titleblock_height);
 	}
 	

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/diagramview.cpp	2015-03-18 18:07:18 UTC (rev 3834)
@@ -778,7 +778,7 @@
 	QRectF elements_bounding_rect = scene -> itemsBoundingRect();
 	
 	// rectangle contenant le cadre = colonnes + cartouche
-	QRectF border_bounding_rect = scene -> border().adjusted(-Diagram::margin, -Diagram::margin, Diagram::margin, Diagram::margin);
+	QRectF border_bounding_rect = scene -> border_and_titleblock.borderAndTitleBlockRect().adjusted(-Diagram::margin, -Diagram::margin, Diagram::margin, Diagram::margin);
 	
 	// ajuste la sceneRect
 	QRectF new_scene_rect = elements_bounding_rect.united(border_bounding_rect);
@@ -1180,26 +1180,10 @@
 
 	BorderTitleBlock &bi = scene -> border_and_titleblock;
 	
-	// Get the rectangle of the header column
-	QRectF columns_rect(
-		Diagram::margin,
-		Diagram::margin,
-		bi.borderWidth(),
-		bi.columnsHeaderHeight()
-	);
-	
-	// Get the rectangle of the header row
-	QRectF rows_rect(
-		Diagram::margin,
-		Diagram::margin,
-		bi.rowsHeaderWidth(),
-		bi.diagramHeight()
-	);
-	
 	//Get the click pos on the diagram
 	QPointF click_pos = viewportTransform().inverted().map(e -> pos());
 	
-	if (bi.titleBlockRect().contains(click_pos) || columns_rect.contains(click_pos) || rows_rect.contains(click_pos)) {
+	if (bi.titleBlockRect().contains(click_pos) || bi.columnsRect().contains(click_pos) || bi.rowsRect().contains(click_pos)) {
 		e->accept();
 		editDiagramProperties();
 		return;

Modified: trunk/sources/dvevent/dveventaddshape.cpp
===================================================================
--- trunk/sources/dvevent/dveventaddshape.cpp	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/dvevent/dveventaddshape.cpp	2015-03-18 18:07:18 UTC (rev 3834)
@@ -190,7 +190,7 @@
 		pen.setCosmetic(true);
 		pen.setColor(Qt::darkGray);
 
-		QRectF rect = m_diagram -> drawingRect();
+		QRectF rect = m_diagram -> border_and_titleblock.insideBorderRect();
 
 		if (!m_help_horiz)
 		{

Modified: trunk/sources/qetgraphicsitem/qgraphicsitemutility.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qgraphicsitemutility.cpp	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/qetgraphicsitem/qgraphicsitemutility.cpp	2015-03-18 18:07:18 UTC (rev 3834)
@@ -54,12 +54,10 @@
 		return false;
 	}
 
-	QRectF  border = element_to_follow -> diagram() -> border();
+	QRectF  border = element_to_follow -> diagram() -> border_and_titleblock.insideBorderRect();
 	QPointF point  = element_to_follow -> sceneBoundingRect().center();
 
-	point.setY(border.height() -
-			   element_to_follow -> diagram() -> border_and_titleblock.titleBlockHeight() -
-			   item_to_center -> boundingRect().height());
+	point.setY(border.bottom() - item_to_center -> boundingRect().height() - 5);
 
 	point.rx() -= (item_to_center -> boundingRect().width()/2 +
 				   item_to_center -> boundingRect().left()); //< we add boundingrect.left because this value can be négative

Modified: trunk/sources/qetgraphicsitem/terminal.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.cpp	2015-03-18 14:10:25 UTC (rev 3833)
+++ trunk/sources/qetgraphicsitem/terminal.cpp	2015-03-18 18:07:18 UTC (rev 3834)
@@ -318,7 +318,7 @@
 			m_help_line_a -> setPen(pen);
 		}
 
-		QRectF rect = diagram() -> drawingRect();
+		QRectF rect = diagram() -> border_and_titleblock.insideBorderRect();
 		QLineF line;
 
 		if (Qet::isHorizontal(orientation()))
@@ -376,7 +376,7 @@
 QLineF Terminal::HelpLine() const
 {
 	QPointF scene_dock = dockConductor();
-	QRectF  rect       = diagram() -> drawingRect();
+	QRectF  rect       = diagram() -> border_and_titleblock.insideBorderRect();
 
 	QLineF line(scene_dock , QPointF());
 


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