refactor: class attributes have m_ prefix

master
Denes Matetelki 14 years ago
parent e4510d57af
commit e2ed4ce25a

@ -4,14 +4,14 @@
AboutDialog::AboutDialog(QWidget *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,
SLOT(aboutDestroyed()));
}
AboutDialog::~AboutDialog()
{
delete ui;
delete m_ui;
}

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save