Clean up some code

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3834 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-03-18 18:07:18 +00:00
parent e29ed4372a
commit 72c68c0d8d
10 changed files with 86 additions and 122 deletions

View File

@@ -65,13 +65,6 @@ BorderTitleBlock::BorderTitleBlock(QObject *parent) :
BorderTitleBlock::~BorderTitleBlock() {
}
/**
@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.
@@ -79,9 +72,9 @@ qreal BorderTitleBlock::titleBlockHeight() const {
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,32 +92,71 @@ QRectF BorderTitleBlock::titleBlockRectForQPainter() const
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);
}
/**
@@ -609,31 +641,23 @@ void BorderTitleBlock::setDiagramHeight(const qreal &height) {
}
/**
@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()
);
* @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));
if (!grid_rect.contains(pos)) {
return(DiagramPosition("", 0));
}
QPointF relative_pos = pos - grid_rect.topLeft();
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));
}

View File

@@ -74,17 +74,16 @@ class BorderTitleBlock : public QObject
/// @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

View File

@@ -134,7 +134,7 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
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 @@ bool Diagram::toPaintDevice(QPaintDevice &pix, int width, int height, Qt::Aspect
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 @@ QSize Diagram::imageSize() const {
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;
@@ -1069,41 +1069,6 @@ void Diagram::invertSelection() {
emit(selectionChanged());
}
/**
* @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
*/
@@ -1246,11 +1211,8 @@ ExportProperties Diagram::applyProperties(const ExportProperties &new_properties
@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);

View File

@@ -180,9 +180,6 @@ class Diagram : public QGraphicsScene
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);
QSize imageSize() const;

View File

@@ -876,14 +876,14 @@ ChangeTitleBlockCommand::~ChangeTitleBlockCommand() {
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());
}
/**

View File

@@ -92,9 +92,9 @@ QString DiagramPrintDialog::docName() const {
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);
}

View File

@@ -778,7 +778,7 @@ void DiagramView::adjustSceneRect() {
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 @@ void DiagramView::mouseDoubleClickEvent(QMouseEvent *e) {
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;

View File

@@ -190,7 +190,7 @@ void DVEventAddShape::updateHelpCross(const QPoint &p)
pen.setCosmetic(true);
pen.setColor(Qt::darkGray);
QRectF rect = m_diagram -> drawingRect();
QRectF rect = m_diagram -> border_and_titleblock.insideBorderRect();
if (!m_help_horiz)
{

View File

@@ -54,12 +54,10 @@ bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_f
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

View File

@@ -318,7 +318,7 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg
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 @@ void Terminal::drawHelpLine(bool draw)
QLineF Terminal::HelpLine() const
{
QPointF scene_dock = dockConductor();
QRectF rect = diagram() -> drawingRect();
QRectF rect = diagram() -> border_and_titleblock.insideBorderRect();
QLineF line(scene_dock , QPointF());