{
if (start == 0 || end == 0)
return 0;
+ if (start == end)
+ return 0;
+
Edge *edge = new Edge(start, end);
edge->setWeight(weight);
edge->setColor(color);
edge.cpp \
nodemodel.cpp \
edgemodel.cpp \
- colorlisteditor.cpp
+ colorlisteditor.cpp \
+ pmc.cpp
HEADERS += mainwindow.h \
graph.h \
defines.h \
nodemodel.h \
edgemodel.h \
- colorlisteditor.h
+ colorlisteditor.h \
+ pmc.h
FORMS += mainwindow.ui
#include "mainwindow.h"
#include "ui_mainwindow.h"
+#include <QSortFilterProxyModel>
#include <QItemEditorFactory>
#include <QFile>
#include <QFileDialog>
#include "node.h"
#include "edge.h"
+#include "pmc.h"
+
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
ui->actionEditMode->setChecked(true);
ui->modeToolBar->addActions(modes->actions());
- QItemEditorCreatorBase *colorListCreator = new QStandardItemEditorCreator<ColorListEditor>();
+ setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
+
+// QItemEditorCreatorBase *colorListCreator = new QStandardItemEditorCreator<ColorListEditor>();
// QItemEditorFactory::defaultFactory()->registerEditor(QVariant::Color, colorListCreator);
graph = new Graph(this);
+ pmc = new PMC(graph, this);
connect(modes, SIGNAL(triggered(QAction*)), this, SLOT(modeChanged(QAction*)));
e = graph->addEdge(n1, n2);
e->setColor(QColor(0,0,255));
+ nodeProxy = new QSortFilterProxyModel(this);
+ edgeProxy = new QSortFilterProxyModel(this);
+
+ nodeProxy->setSourceModel(graph->nodeModel());
+ edgeProxy->setSourceModel(graph->edgeModel());
+
ui->graphView->setScene(graph);
- ui->nodeView->setModel(graph->nodeModel());
- ui->edgeView->setModel(graph->edgeModel());
+ ui->nodeView->setModel(nodeProxy);
+ ui->edgeView->setModel(edgeProxy);
+
+ ui->nodeView->setSortingEnabled(true);
+ ui->edgeView->setSortingEnabled(true);
}
MainWindow::~MainWindow()
{
graph->clear();
}
+
+
+
+void MainWindow::on_pmcStep_clicked()
+{
+ if (pmc->step())
+ ui->statusBar->showMessage(tr("Last Step complete"));
+ else
+ ui->statusBar->showMessage(tr("Step complete"));
+}
}
class Graph;
+class QSortFilterProxyModel;
+class PMC;
+
class QActionGroup;
class MainWindow : public QMainWindow
void on_actionGenerateGraph_triggered();
void on_actionClearAll_triggered();
+ void on_pmcStep_clicked();
+
private:
Ui::MainWindow *ui;
+ QSortFilterProxyModel *nodeProxy;
+ QSortFilterProxyModel *edgeProxy;
+
Graph *graph;
+ PMC *pmc;
QActionGroup *modes;
<rect>
<x>0</x>
<y>0</y>
- <width>781</width>
- <height>598</height>
+ <width>865</width>
+ <height>756</height>
</rect>
</property>
<property name="windowTitle">
<string>PMC</string>
</property>
+ <property name="dockNestingEnabled">
+ <bool>true</bool>
+ </property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<rect>
<x>0</x>
<y>0</y>
- <width>781</width>
+ <width>865</width>
<height>21</height>
</rect>
</property>
</layout>
</widget>
</widget>
+ <widget class="QDockWidget" name="dockWidget">
+ <property name="minimumSize">
+ <size>
+ <width>80</width>
+ <height>195</height>
+ </size>
+ </property>
+ <property name="windowTitle">
+ <string>PMC</string>
+ </property>
+ <attribute name="dockWidgetArea">
+ <number>8</number>
+ </attribute>
+ <widget class="QWidget" name="dockWidgetContents_3">
+ <widget class="QPushButton" name="pmcStep">
+ <property name="geometry">
+ <rect>
+ <x>70</x>
+ <y>0</y>
+ <width>75</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Step</string>
+ </property>
+ </widget>
+ </widget>
+ </widget>
<action name="actionEditMode">
<property name="checkable">
<bool>true</bool>
--- /dev/null
+#include "pmc.h"
+
+#include "graph.h"
+#include "node.h"
+#include "edge.h"
+
+PMC::PMC(Graph *g, QObject *parent) :
+ QObject(parent), m_graph(g)
+{
+}
+
+bool PMC::step()
+{
+ Node *next = findHighestDegree();
+
+ if (!next)
+ return true;
+
+
+ Edge *e = next->incomingEdges().first();
+// Node *otherNode = e->startNode();
+ m_graph->removeEdge(e);
+
+ if (next->incomingEdges().count() == m())
+ next->setColor(Qt::green);
+ else
+ next->setColor(Qt::yellow);
+ next->update();
+ return false;
+}
+
+Node *PMC::findHighestDegree() const
+{
+ Node *ret = 0;
+ foreach(Node *n, m_graph->nodes())
+ {
+ if (n->incomingEdges().count() <= m())
+ {
+ if (n->incomingEdges().count() < m())
+ {
+ n->setColor(Qt::red);
+ n->update();
+ }
+ continue;
+ }
+ if (ret == 0)
+ ret = n;
+ if (n->incomingEdges().count() > n->outgoingEdges().count())
+ ret = n;
+ }
+ return ret;
+}
+
+int PMC::m() const
+{
+ return (m_graph->nodes().count() - 1) / 2;
+}
+
+int PMC::p() const
+{
+ return m_graph->nodes().count() - 2 * m();
+}
--- /dev/null
+#ifndef PMC_H
+#define PMC_H
+
+#include <QObject>
+
+class Graph;
+class Node;
+
+class PMC : public QObject
+{
+ Q_OBJECT
+public:
+ explicit PMC(Graph *g, QObject *parent = 0);
+
+signals:
+
+public slots:
+ bool step();
+
+private:
+ Node *findHighestDegree() const;
+ int m() const;
+ int p() const;
+
+ Graph *m_graph;
+};
+
+#endif // PMC_H