Commit 2bb909c2 authored by Alexander Schuch's avatar Alexander Schuch
Browse files

Clean up code.

As MiniMapView::hasSelection() now properly checks for a valid selection,
there is no need anymore to repeat that condition.
parent 81b30322
...@@ -90,17 +90,17 @@ void MiniMapView::paintEvent(QPaintEvent * /*event*/) ...@@ -90,17 +90,17 @@ void MiniMapView::paintEvent(QPaintEvent * /*event*/)
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::black); painter.setPen(Qt::black);
painter.setBrush(Qt::black); painter.setBrush(Qt::black);
painter.drawRect(QRectF(woffset, hoffset, m_map->columns()*sectorSize, m_map->rows()*sectorSize)); painter.drawRect(QRectF(woffset, hoffset, m_map->columns() * sectorSize, m_map->rows() * sectorSize));
// Draw selection // Draw selection
if (hasSelection()) { if (hasSelection()) {
if(m_selection.x() >= 0 && m_selection.x() < m_map->columns() && painter.setBrush(Qt::cyan);
m_selection.y() >= 0 && m_selection.y() < m_map->rows()) { painter.drawRect(QRectF(
painter.setBrush(Qt::cyan); woffset + m_selection.x() * sectorSize,
painter.drawRect(QRectF(woffset + m_selection.x() * sectorSize, hoffset + m_selection.y() * sectorSize,
hoffset + m_selection.y() * sectorSize, sectorSize,
sectorSize, sectorSize)); sectorSize
} ));
} }
// Now draw the planets... // Now draw the planets...
......
...@@ -39,6 +39,11 @@ public: ...@@ -39,6 +39,11 @@ public:
void setMap( Map *newMap ); void setMap( Map *newMap );
/**
* @note Always use hasSelection() first to make sure that the returned
* selection is valid.
*/
Coordinate selection() const { return m_selection; } Coordinate selection() const { return m_selection; }
bool hasSelection() const { return (m_selection.x() >= 0) && (m_selection.x() < m_map->columns()) && (m_selection.y() >= 0) && (m_selection.y() < m_map->rows()); } bool hasSelection() const { return (m_selection.x() >= 0) && (m_selection.x() < m_map->columns()) && (m_selection.y() >= 0) && (m_selection.y() < m_map->rows()); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment