refactor: class attributes have m_ prefix

master
Denes Matetelki 14 years ago
parent e4510d57af
commit e2ed4ce25a

@ -4,14 +4,14 @@
AboutDialog::AboutDialog(QWidget *parent) : AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::AboutDialog) m_ui(new Ui::AboutDialog)
{ {
ui->setupUi(this); m_ui->setupUi(this);
connect(this, SIGNAL(finished(int)), parent, connect(this, SIGNAL(finished(int)), parent,
SLOT(aboutDestroyed())); SLOT(aboutDestroyed()));
} }
AboutDialog::~AboutDialog() AboutDialog::~AboutDialog()
{ {
delete ui; delete m_ui;
} }

@ -16,7 +16,7 @@ public:
~AboutDialog(); ~AboutDialog();
private: private:
Ui::AboutDialog *ui; Ui::AboutDialog *m_ui;
}; };
#endif // ABOUTDIALOG_H #endif // ABOUTDIALOG_H

@ -11,25 +11,25 @@ static const double Pi = 3.14159265358979323846264338327950288419717;
static double TwoPi = 2.0 * Pi; static double TwoPi = 2.0 * Pi;
Edge::Edge(Node *sourceNode, Node *destNode) Edge::Edge(Node *sourceNode, Node *destNode)
: arrowSize(10) : m_arrowSize(7)
{ {
setAcceptedMouseButtons(0); setAcceptedMouseButtons(0);
source = sourceNode; m_sourceNode = sourceNode;
dest = destNode; m_destNode = destNode;
source->addEdge(this); m_sourceNode->addEdge(this);
dest->addEdge(this); m_destNode->addEdge(this);
adjust(); adjust();
// setZValue(1); // setZValue(1);
} }
Node *Edge::sourceNode() const Node *Edge::sourceNode() const
{ {
return source; return m_sourceNode;
} }
Node *Edge::destNode() const Node *Edge::destNode() const
{ {
return dest; return m_destNode;
} }
/// @note This is brute force. Isn't there a simple fv for this? /// @note This is brute force. Isn't there a simple fv for this?
@ -58,14 +58,14 @@ QPointF firstNotContainedPoint(const QLineF &line,
void Edge::adjust() void Edge::adjust()
{ {
if (!source || !dest) if (!m_sourceNode || !m_destNode)
return; return;
prepareGeometryChange(); prepareGeometryChange();
QLineF line(mapFromItem(source, 0, 0) + source->boundingRect().center(), QLineF line(mapFromItem(m_sourceNode, 0, 0) + m_sourceNode->boundingRect().center(),
mapFromItem(dest, 0, 0) + dest->boundingRect().center()); mapFromItem(m_destNode, 0, 0) + m_destNode->boundingRect().center());
qreal length = line.length(); qreal length = line.length();
@ -73,45 +73,41 @@ void Edge::adjust()
if (length > qreal(20.)) { if (length > qreal(20.)) {
QPointF sourceOffset(firstNotContainedPoint(line, QPointF sourceOffset(firstNotContainedPoint(line,
source->pos(), m_sourceNode->pos(),
source->boundingRect() m_sourceNode->boundingRect()
)); ));
QPointF destOffset(firstNotContainedPoint(line, QPointF destOffset(firstNotContainedPoint(line,
dest->pos(), m_destNode->pos(),
dest->boundingRect() m_destNode->boundingRect()
,true)); ,true));
sourcePoint = sourceOffset; m_sourcePoint = sourceOffset;
destPoint = destOffset; m_destPoint = destOffset;
} else { } else {
sourcePoint = destPoint = line.p1(); m_sourcePoint = m_destPoint = line.p1();
} }
} }
QRectF Edge::boundingRect() const QRectF Edge::boundingRect() const
{ {
if (!source || !dest) if (!m_sourceNode || !m_destNode)
return QRectF(); return QRectF();
qreal penWidth = 1; qreal penWidth = 1;
qreal extra = (penWidth + arrowSize) / 2.0; qreal extra = (penWidth + m_arrowSize) / 2.0;
return QRectF(sourcePoint, QSizeF(destPoint.x() - sourcePoint.x(), return QRectF(m_sourcePoint, QSizeF(m_destPoint.x() - m_sourcePoint.x(),
destPoint.y() - sourcePoint.y())) m_destPoint.y() - m_sourcePoint.y()))
.normalized() .normalized()
.adjusted(-extra, -extra, extra, extra); .adjusted(-extra, -extra, extra, extra);
} }
void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{ {
if (!source || !dest) if (!m_sourceNode || !m_destNode)
return; return;
QLineF line(sourcePoint, destPoint); QLineF line(m_sourcePoint, m_destPoint);
/// @bug this test does not filter out when the nodes intersect
// if (qFuzzyCompare(line.length(), qreal(0.)))
// return;
if (sourceNode()->collidesWithItem(destNode())) if (sourceNode()->collidesWithItem(destNode()))
return; return;
@ -120,7 +116,7 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter->drawLine(line); painter->drawLine(line);
if (line.length() < qreal(10.)) if (line.length() < m_arrowSize)
return; return;
// Draw the arrows // Draw the arrows
@ -128,16 +124,11 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
if (line.dy() >= 0) if (line.dy() >= 0)
angle = TwoPi - angle; angle = TwoPi - angle;
// QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + Pi / 3) * arrowSize, QPointF destArrowP1 = m_destPoint + QPointF(sin(angle - Pi / 3) * m_arrowSize,
// cos(angle + Pi / 3) * arrowSize); cos(angle - Pi / 3) * m_arrowSize);
// QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, QPointF destArrowP2 = m_destPoint + QPointF(sin(angle - Pi + Pi / 3) * m_arrowSize,
// cos(angle + Pi - Pi / 3) * arrowSize); cos(angle - Pi + Pi / 3) * m_arrowSize);
QPointF destArrowP1 = destPoint + QPointF(sin(angle - Pi / 3) * arrowSize,
cos(angle - Pi / 3) * arrowSize);
QPointF destArrowP2 = destPoint + QPointF(sin(angle - Pi + Pi / 3) * arrowSize,
cos(angle - Pi + Pi / 3) * arrowSize);
painter->setBrush(Qt::black); painter->setBrush(Qt::black);
// painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2);
painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2); painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2);
} }

@ -7,8 +7,6 @@ class Node;
class Edge : public QGraphicsItem class Edge : public QGraphicsItem
{ {
// Q_OBJECT
public: public:
Edge(Node *sourceNode, Node *destNode); Edge(Node *sourceNode, Node *destNode);
@ -25,11 +23,12 @@ protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private: private:
Node *source, *dest; Node *m_sourceNode;
Node *m_destNode;
QPointF sourcePoint; QPointF m_sourcePoint;
QPointF destPoint; QPointF m_destPoint;
qreal arrowSize; qreal m_arrowSize;
}; };
#endif #endif

@ -6,14 +6,15 @@
#include "edge.h" #include "edge.h"
#include "math.h" #include "math.h"
GraphWidget::GraphWidget(QWidget *parent) GraphWidget::GraphWidget(QWidget *parent) :
QGraphicsView(parent)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
scene = new QGraphicsScene(this); m_scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::NoIndex); m_scene->setItemIndexMethod(QGraphicsScene::NoIndex);
scene->setSceneRect(-400, -400, 800, 800); m_scene->setSceneRect(-400, -400, 800, 800);
setScene(scene); setScene(m_scene);
setCacheMode(CacheBackground); setCacheMode(CacheBackground);
setViewportUpdateMode(BoundingRectViewportUpdate); setViewportUpdateMode(BoundingRectViewportUpdate);
setRenderHint(QPainter::Antialiasing); setRenderHint(QPainter::Antialiasing);
@ -22,47 +23,47 @@ GraphWidget::GraphWidget(QWidget *parent)
Node *node1 = new Node(); Node *node1 = new Node();
node1->setHtml(QString("me")); node1->setHtml(QString("me"));
scene->addItem(node1); m_scene->addItem(node1);
node1->setPos(-10, -10); node1->setPos(-10, -10);
Node *node2 = new Node(); Node *node2 = new Node();
node2->setHtml(QString("work")); node2->setHtml(QString("work"));
scene->addItem(node2); m_scene->addItem(node2);
node2->setPos(60, -10); node2->setPos(60, -10);
Node *node3 = new Node(); Node *node3 = new Node();
node3->setHtml(QString("read")); node3->setHtml(QString("read"));
scene->addItem(node3); m_scene->addItem(node3);
node3->setPos(-70, -10); node3->setPos(-70, -10);
Node *node4 = new Node(); Node *node4 = new Node();
node4->setHtml(QString("pragmatic programmer")); node4->setHtml(QString("pragmatic programmer"));
scene->addItem(node4); m_scene->addItem(node4);
node4->setPos(-120, -80); node4->setPos(-120, -80);
Node *node5 = new Node(); Node *node5 = new Node();
node5->setHtml(QString("joy")); node5->setHtml(QString("joy"));
scene->addItem(node5); m_scene->addItem(node5);
node5->setPos(-10, 50); node5->setPos(-10, 50);
Node *node6 = new Node(); Node *node6 = new Node();
node6->setHtml(QString("rape goats")); node6->setHtml(QString("rape goats"));
scene->addItem(node6); m_scene->addItem(node6);
node6->setPos(-10, 100); node6->setPos(-10, 100);
scene->addItem(new Edge(node1, node2)); m_scene->addItem(new Edge(node1, node2));
scene->addItem(new Edge(node1, node3)); m_scene->addItem(new Edge(node1, node3));
scene->addItem(new Edge(node3, node4)); m_scene->addItem(new Edge(node3, node4));
scene->addItem(new Edge(node1, node5)); m_scene->addItem(new Edge(node1, node5));
scene->addItem(new Edge(node5, node6)); m_scene->addItem(new Edge(node5, node6));
activeNode = node1; m_activeNode = node1;
activeNode->setFocus(); m_activeNode->setFocus();
} }
QGraphicsScene *GraphWidget::getScene() QGraphicsScene *GraphWidget::getScene()
{ {
return scene; return m_scene;
} }
void GraphWidget::keyPressEvent(QKeyEvent *event) void GraphWidget::keyPressEvent(QKeyEvent *event)

@ -24,8 +24,8 @@ protected:
void drawBackground(QPainter *painter, const QRectF &rect); void drawBackground(QPainter *painter, const QRectF &rect);
private: private:
Node *activeNode; Node *m_activeNode;
QGraphicsScene *scene; QGraphicsScene *m_scene;
}; };

@ -32,23 +32,23 @@ extern void exportScaneToPng(QGraphicsScene *scene,
MainWindow::MainWindow(bool isSystemtray, QWidget *parent) : MainWindow::MainWindow(bool isSystemtray, QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow), m_ui(new Ui::MainWindow),
aboutDialog(0) m_aboutDialog(0)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
ui->setupUi(this); m_ui->setupUi(this);
connect(ui->actionNew, SIGNAL(activated()), this, SLOT(klakk())); connect(m_ui->actionNew, SIGNAL(activated()), this, SLOT(klakk()));
connect(ui->actionOpen, SIGNAL(activated()), this, SLOT(klakk())); connect(m_ui->actionOpen, SIGNAL(activated()), this, SLOT(klakk()));
connect(ui->actionSave, SIGNAL(activated()), this, SLOT(klakk())); connect(m_ui->actionSave, SIGNAL(activated()), this, SLOT(klakk()));
connect(ui->actionClose, SIGNAL(activated()), this, SLOT(klakk())); connect(m_ui->actionClose, SIGNAL(activated()), this, SLOT(klakk()));
connect(ui->actionExport, SIGNAL(activated()), this, SLOT(exportScene())); connect(m_ui->actionExport, SIGNAL(activated()), this, SLOT(exportScene()));
connect(ui->actionQuit, SIGNAL(activated()), QApplication::instance(), connect(m_ui->actionQuit, SIGNAL(activated()), QApplication::instance(),
SLOT(quit())); SLOT(quit()));
connect(ui->actionAbout_QtMindMap, SIGNAL(activated()), this, connect(m_ui->actionAbout_QtMindMap, SIGNAL(activated()), this,
SLOT(about())); SLOT(about()));
graphicsView = new GraphWidget(ui->centralWidget); m_graphicsView = new GraphWidget(m_ui->centralWidget);
setCentralWidget(graphicsView); setCentralWidget(m_graphicsView);
if (isSystemtray) setupSystemTray(); if (isSystemtray) setupSystemTray();
} }
@ -56,8 +56,8 @@ MainWindow::MainWindow(bool isSystemtray, QWidget *parent) :
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
delete ui; delete m_ui;
if (aboutDialog) delete aboutDialog; if (m_aboutDialog) delete m_aboutDialog;
} }
void MainWindow::klakk() void MainWindow::klakk()
@ -87,18 +87,18 @@ void MainWindow::exportScene()
// fileNames.first(), // fileNames.first(),
// ui); // ui);
QImage img(graphicsView->getScene()->sceneRect().width(), QImage img(m_graphicsView->getScene()->sceneRect().width(),
graphicsView->getScene()->sceneRect().height(), m_graphicsView->getScene()->sceneRect().height(),
QImage::Format_ARGB32_Premultiplied); QImage::Format_ARGB32_Premultiplied);
QPainter painter(&img); QPainter painter(&img);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
/// @bug scene background is not rendered /// @bug scene background is not rendered
graphicsView->getScene()->render(&painter); m_graphicsView->getScene()->render(&painter);
painter.end(); painter.end();
img.save(fileNames.first()); img.save(fileNames.first());
ui->statusBar->showMessage(tr("MindMap exported as ") + fileNames.first(), m_ui->statusBar->showMessage(tr("MindMap exported as ") + fileNames.first(),
5000); // millisec 5000); // millisec
} }
@ -106,31 +106,31 @@ void MainWindow::exportScene()
void MainWindow::setupSystemTray() void MainWindow::setupSystemTray()
{ {
systemTrayIcon = new QSystemTrayIcon(0); m_systemTrayIcon = new QSystemTrayIcon(0);
minimizeAction = new QAction(tr("Mi&nimize"), systemTrayIcon); m_minimizeAction = new QAction(tr("Mi&nimize"), m_systemTrayIcon);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide())); connect(m_minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
maximizeAction = new QAction(tr("Ma&ximize"), systemTrayIcon); m_maximizeAction = new QAction(tr("Ma&ximize"), m_systemTrayIcon);
connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized())); connect(m_maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));
restoreAction = new QAction(tr("&Restore"), systemTrayIcon); m_restoreAction = new QAction(tr("&Restore"), m_systemTrayIcon);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(m_restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction(tr("&Quit"), systemTrayIcon); m_quitAction = new QAction(tr("&Quit"), m_systemTrayIcon);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(m_quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
trayIconMenu = new QMenu(this); m_trayIconMenu = new QMenu(this);
trayIconMenu->addAction(minimizeAction); m_trayIconMenu->addAction(m_minimizeAction);
trayIconMenu->addAction(maximizeAction); m_trayIconMenu->addAction(m_maximizeAction);
trayIconMenu->addAction(restoreAction); m_trayIconMenu->addAction(m_restoreAction);
trayIconMenu->addSeparator(); m_trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction); m_trayIconMenu->addAction(m_quitAction);
systemTrayIcon->setContextMenu(trayIconMenu); m_systemTrayIcon->setContextMenu(m_trayIconMenu);
icon = new QIcon(":/heart.svg"); m_icon = new QIcon(":/heart.svg");
systemTrayIcon->setIcon(QIcon(":/heart.svg")); m_systemTrayIcon->setIcon(QIcon(":/heart.svg"));
} }
void MainWindow::about() void MainWindow::about()
@ -138,21 +138,21 @@ void MainWindow::about()
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
setDisabled(true); setDisabled(true);
if (aboutDialog == 0) aboutDialog = new AboutDialog(this); if (m_aboutDialog == 0) m_aboutDialog = new AboutDialog(this);
aboutDialog->setEnabled(true); // children inherits enabled status m_aboutDialog->setEnabled(true); // children inherits enabled status
aboutDialog->show(); m_aboutDialog->show();
// aboutDialog->layout()->setSizeConstraint( QLayout::SetFixedSize ); // aboutDialog->layout()->setSizeConstraint( QLayout::SetFixedSize );
} }
void MainWindow::aboutDestroyed() void MainWindow::aboutDestroyed()
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
qDebug() << aboutDialog; qDebug() << m_aboutDialog;
setEnabled(true); setEnabled(true);
} }
void MainWindow::showSysTray() void MainWindow::showSysTray()
{ {
systemTrayIcon->show(); m_systemTrayIcon->show();
} }

@ -30,18 +30,18 @@ private:
void setupSystemTray(); void setupSystemTray();
Ui::MainWindow *ui; Ui::MainWindow *m_ui;
AboutDialog* aboutDialog; AboutDialog *m_aboutDialog;
GraphWidget *graphicsView; GraphWidget *m_graphicsView;
QSystemTrayIcon *systemTrayIcon; QSystemTrayIcon *m_systemTrayIcon;
MainWindow *mainWindow; MainWindow *m_mainWindow;
QMenu *trayIconMenu; QMenu *m_trayIconMenu;
QAction *minimizeAction; QAction *m_minimizeAction;
QAction *maximizeAction; QAction *m_maximizeAction;
QAction *restoreAction; QAction *m_restoreAction;
QAction *quitAction; QAction *m_quitAction;
QIcon *icon; QIcon *m_icon;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

@ -4,7 +4,7 @@
#include <QStyleOption> #include <QStyleOption>
#include <QDebug> #include <QDebug>
Node::Node(GraphWidget *parent) : graph(parent), active(false) Node::Node(GraphWidget *parent) : m_graph(parent)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
@ -24,7 +24,7 @@ void Node::addEdge(Edge *edge)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
edgeList << edge; m_edgeList << edge;
edge->adjust(); edge->adjust();
} }
@ -36,7 +36,7 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
switch (change) { switch (change) {
case ItemPositionHasChanged: case ItemPositionHasChanged:
foreach (Edge *edge, edgeList) edge->adjust(); foreach (Edge *edge, m_edgeList) edge->adjust();
break; break;
default: default:
break; break;
@ -49,8 +49,6 @@ void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
qDebug() << __PRETTY_FUNCTION__; qDebug() << __PRETTY_FUNCTION__;
// active = true;
// setScale(1.2);
update(); update();
QGraphicsTextItem::mousePressEvent(event); QGraphicsTextItem::mousePressEvent(event);
} }
@ -70,21 +68,8 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
QGraphicsTextItem::paint(painter, option, w); QGraphicsTextItem::paint(painter, option, w);
QPen pen(Qt::blue,1); painter->setPen(QPen(Qt::blue));
// pen.setJoinStyle(Qt::RoundJoin); painter->drawRect(QRect(boundingRect().topLeft().toPoint(),
// pen.setStyle(Qt::MiterJoin); boundingRect().bottomRight().toPoint() -
// pen.setCapStyle(Qt::RoundCap); QPoint(1,1)));
// pen.setMiterLimit(3);
painter->setPen(pen);
// painter->setPen(QPen(Qt::blue
// , 1, Qt::SolidLine,Qt::SquareCap, Qt::RoundJoin
// ));
m_rect = QRect( boundingRect().topLeft().toPoint()
// - QPoint(4,4)
,
boundingRect().bottomRight().toPoint()
- QPoint(1,1)
);
painter->drawRect(m_rect);
} }

@ -8,11 +8,8 @@
class GraphWidget; class GraphWidget;
/// @bug no signal when size change
class Node : public QGraphicsTextItem class Node : public QGraphicsTextItem
{ {
// Q_OBJECT
public: public:
Node(GraphWidget *graphWidget = 0); Node(GraphWidget *graphWidget = 0);
@ -27,11 +24,8 @@ protected:
private: private:
QList<Edge *> edgeList; QList<Edge *> m_edgeList;
GraphWidget *graph; GraphWidget *m_graph;
bool active;
QRectF m_rect;
}; };
#endif // NODE_H #endif // NODE_H

Loading…
Cancel
Save