조성현

Node highlighting example. click file menu->node highlighting

......@@ -246,15 +246,6 @@ void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
if (!graph)
return;
//debug
//-> x, y, w, h
//현재 Graph의 bounding rect 출력
/*QPen oldPen = painter->pen();
QPen pen = oldPen;
pen.setColor(Qt::red);
painter->setPen(pen);
painter->drawRect(QRectF(-SCREEN_SIZE/2, -SCREEN_SIZE/2, SCREEN_SIZE, SCREEN_SIZE));*/
//print edges
for (auto edge: edgeList) {
edge->paint(painter, option, widget);
......@@ -266,6 +257,17 @@ void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
}
}
void GraphItem::path_highlighting(std::string start, std::string end)
{
//path highlight
//nodeList, edgeList 속성을 수정
for (auto& n: nodeList) {
if (n->getLabel() == QString("Seongsoo Park")) {
n->setColor(QColor(255, 0, 0));
}
}
}
//event handler
void GraphItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
......
#include "MainWindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
//ui.setupUi(this);
graphWidget = new PaperGraphWidget;
setCentralWidget(graphWidget);
/*QVBoxLayout *layout = new QVBoxLayout;
layout->setMargin(5);
graphWidget->setLayout(layout);*/
//create menu
testAct = new QAction(tr("&Test"), this);
testAct->setStatusTip(tr("Test Action"));
connect(testAct, &QAction::triggered, this, &MainWindow::test_func);
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(testAct);
QString message = tr("test message");
statusBar()->showMessage(message);
setMinimumSize(160, 160);
resize(800, 600);
}
MainWindow::~MainWindow()
{
}
void MainWindow::print_graph(std::ifstream& fin)
{
graphWidget->print_graph(fin);
}
void MainWindow::test_func()
{
/*QMessageBox::information(this, "test",
"test: "+QString::number(11));*/
graphWidget->path_highlight();
}
\ No newline at end of file
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtWidgets>
#include <QGridLayout>
#include <QtGui>
#include <iostream>
//#include "ui_MainWindow.h"
#include "PaperGraphWidget.h"
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
void print_graph(std::ifstream& fin);
void test_func();
private:
//Ui::MainWindow ui;
PaperGraphWidget *graphWidget;
QMenu *fileMenu;
QAction *testAct;
};
#endif // MAINWINDOW_H
<UI version="4.0" >
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="objectName" >
<string notr="true">MainWindow</string>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>MainWindow</string>
</property>
<widget class="QMenuBar" name="menuBar" />
<widget class="QToolBar" name="mainToolBar" />
<widget class="QWidget" name="centralWidget" />
<widget class="QStatusBar" name="statusBar" />
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</UI>
......@@ -24,6 +24,10 @@ protected:
public:
NodeItem(double x, double y, QColor color, QString label);
//getter setter
QString getLabel() {return label;}
void setColor(QColor color) {this->color=color;}
QRectF boundingRect() const override;
QPainterPath shape() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
......
......@@ -150,6 +150,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\Debug\moc_MainWindow.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\Debug\moc_PaperGraphWidget.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
......@@ -168,6 +172,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\Release\moc_MainWindow.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="GeneratedFiles\Release\moc_PaperGraphWidget.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
......@@ -175,6 +183,7 @@
<ClCompile Include="GraphicsView.cpp" />
<ClCompile Include="GraphItem.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="MainWindow.cpp" />
<ClCompile Include="NodeItem.cpp" />
<ClCompile Include="PaperGraphWidget.cpp" />
</ItemGroup>
......@@ -220,6 +229,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="EdgeItem.h" />
<ClInclude Include="GeneratedFiles\ui_MainWindow.h" />
<ClInclude Include="GeneratedFiles\ui_PaperGraphWidget.h" />
<CustomBuild Include="GraphicsView.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
......@@ -240,6 +250,24 @@
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_DLL -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtWidgets"</Command>
</CustomBuild>
<ClInclude Include="GraphItem.h" />
<CustomBuild Include="MainWindow.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Moc%27ing MainWindow.h...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_DLL -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtWidgets"</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Moc%27ing MainWindow.h...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_DLL -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtWidgets"</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Moc%27ing MainWindow.h...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_DLL -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtWidgets"</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Moc%27ing MainWindow.h...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_DLL -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtWidgets"</Command>
</CustomBuild>
<ClInclude Include="NodeItem.h" />
</ItemGroup>
<ItemGroup>
......@@ -262,6 +290,26 @@
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(QTDIR)\bin\rcc.exe" -name "%(Filename)" -no-compress "%(FullPath)" -o .\GeneratedFiles\qrc_%(Filename).cpp</Command>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="MainWindow.ui">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\uic.exe;%(AdditionalInputs)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Uic%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\GeneratedFiles\ui_%(Filename).h;%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)"</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(QTDIR)\bin\uic.exe;%(AdditionalInputs)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Uic%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\GeneratedFiles\ui_%(Filename).h;%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)"</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(QTDIR)\bin\uic.exe;%(AdditionalInputs)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Uic%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\GeneratedFiles\ui_%(Filename).h;%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)"</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(QTDIR)\bin\uic.exe;%(AdditionalInputs)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Uic%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\GeneratedFiles\ui_%(Filename).h;%(Outputs)</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)"</Command>
</CustomBuild>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
......
......@@ -68,6 +68,15 @@
<ClCompile Include="EdgeItem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MainWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GeneratedFiles\Debug\moc_MainWindow.cpp">
<Filter>Generated Files\Debug</Filter>
</ClCompile>
<ClCompile Include="GeneratedFiles\Release\moc_MainWindow.cpp">
<Filter>Generated Files\Release</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="PaperGraphWidget.h">
......@@ -82,6 +91,12 @@
<CustomBuild Include="GraphicsView.h">
<Filter>Header Files</Filter>
</CustomBuild>
<CustomBuild Include="MainWindow.h">
<Filter>Header Files</Filter>
</CustomBuild>
<CustomBuild Include="MainWindow.ui">
<Filter>Form Files</Filter>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ClInclude Include="GeneratedFiles\ui_PaperGraphWidget.h">
......@@ -96,5 +111,8 @@
<ClInclude Include="EdgeItem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GeneratedFiles\ui_MainWindow.h">
<Filter>Generated Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......
......@@ -10,7 +10,7 @@
PaperGraphWidget::PaperGraphWidget(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
//ui.setupUi(this);
initscene();
View *view = new View("temp view");
......@@ -33,19 +33,28 @@ PaperGraphWidget::PaperGraphWidget(QWidget *parent)
void PaperGraphWidget::print_graph(ifstream& fin)
{
QGraphicsItem *graph_item = new GraphItem(fin);
graph_item->setPos(0, 0);
scene->addItem(graph_item);
//QGraphicsItem *graph_item = new GraphItem(fin);
if (graphItem)
throw std::exception("already have graph item");
graphItem = new GraphItem(fin);
graphItem->setPos(0, 0);
scene->addItem(graphItem);
}
void PaperGraphWidget::path_highlight()
{
graphItem->path_highlighting(std::string(""), std::string(""));
}
void PaperGraphWidget::handleSelectionChanged(int idx)
{
/*QMessageBox::information(this, "QCombobox",
"idx: "+QString::number(idx));*/
if (idx==0) {
QMessageBox::information(this, "QCombobox",
"idx: "+QString::number(idx));
/*if (idx==0) {
} else if (idx==1) {
} else {
}
}*/
}
void PaperGraphWidget::initscene()
......
......@@ -7,7 +7,7 @@
#include <fstream>
#include "GraphItem.h"
#include "ui_PaperGraphWidget.h"
//#include "ui_PaperGraphWidget.h"
class PaperGraphWidget : public QWidget
......@@ -17,6 +17,7 @@ class PaperGraphWidget : public QWidget
public:
PaperGraphWidget(QWidget *parent = 0);
void print_graph(ifstream& fin);
void path_highlight();
private slots:
void handleSelectionChanged(int idx);
......@@ -24,8 +25,9 @@ private slots:
private:
void initscene();
Ui::PaperGraphWidgetClass ui;
//Ui::PaperGraphWidgetClass ui;
QGraphicsScene *scene;
GraphItem *graphItem;
};
#endif // PAPERGRAPHWIDGET_H
......
#include "PaperGraphWidget.h"
#include "MainWindow.h"
#include <QtWidgets/QApplication>
#include <QDebug>
......@@ -28,18 +30,21 @@ int main(int argc, char *argv[])
{
QApplication app(argc, argv);
PaperGraphWidget w;
//PaperGraphWidget w;
MainWindow m;
try {
ifstream fin(PAPER_FILENAME);
w.print_graph(fin);
//w.print_graph(fin);
m.print_graph(fin);
fin.close();
} catch (const std::exception& e) {
qDebug() << "Error: " << e.what();
return EXIT_FAILURE;
}
w.show();
//w.show();
m.show();
return app.exec();
}
......