Skip to content

Commit

Permalink
Data now added correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Detegr committed Feb 1, 2013
1 parent 296d22b commit 95518c1
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 3 deletions.
56 changes: 56 additions & 0 deletions dataeditor.h
@@ -0,0 +1,56 @@
#pragma once
#include <QtGui/QtGui>

class C_DataEditor : public QDialog
{
Q_OBJECT
private:
QString m_Data;
QPushButton* m_OkButton;
QLineEdit* m_Editor;
QModelIndex m_ModelIndex;

public:

C_DataEditor(QWidget* parent=NULL) : QDialog(parent)
{
setFixedWidth(250);
setFixedHeight(80);
setModal(true);
m_OkButton = new QPushButton(tr("Ok"));
m_OkButton->setDefault(true);
QObject::connect(m_OkButton, SIGNAL(clicked()), this, SLOT(ok()));

m_Editor = new QLineEdit;

QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(m_Editor);
layout->addWidget(m_OkButton);
setLayout(layout);
hide();
}

void setData(const QModelIndex& i, const QString& data)
{
m_ModelIndex=i;
m_Data=data;
m_Editor->setText(m_Data);
}

QString getData() const
{
return m_Data;
}

const QModelIndex& getModelIndex() const
{
return m_ModelIndex;
}

public slots:
void ok()
{
m_Data=m_Editor->displayText();
accept();
}
};
30 changes: 29 additions & 1 deletion editor.cpp
Expand Up @@ -67,11 +67,20 @@ void C_Editor::m_Init()
QObject::connect(m_Editor, SIGNAL(S_RequestColorDialog(QList<C_Vertex*>)), this, SLOT(S_OpenColorDialog(QList<C_Vertex*>)));
QObject::connect(m_ColorDialog, SIGNAL(colorSelected(const QColor&)), this, SLOT(S_ColorChanged(const QColor&)));

m_DataEditor = new C_DataEditor(this);

m_New->setFixedWidth(SIDEBAR_WIDTH);
m_Center->setFixedWidth(SIDEBAR_WIDTH);

m_List = new QTreeView(this);
QObject::connect(m_List, SIGNAL(clicked(const QModelIndex&)), this, SLOT(S_SetActivePoly(const QModelIndex&)));
QObject::connect(
m_List,
SIGNAL(doubleClicked(const QModelIndex&)),
this,
SLOT(S_OpenDataDialog(const QModelIndex&)));
QObject::connect(m_DataEditor, SIGNAL(accepted()), this, SLOT(S_SetData()));

m_Splitter->addWidget(m_List);
m_List->setHeaderHidden(true);
m_List->setModel(m_Model);
Expand Down Expand Up @@ -217,7 +226,7 @@ void C_Editor::S_UpdateList(QStandardItem* i)
{
m_Editor->m_ActivePoly->M_Vertex(i->row()).M_SetPos(newdata, oldp.second);
}
else
else if(i->column()==1)
{
m_Editor->m_ActivePoly->M_Vertex(i->row()).M_SetPos(oldp.first, newdata);
}
Expand Down Expand Up @@ -364,3 +373,22 @@ void C_Editor::S_ReverseActivePolygon()
emit S_SetPos(*it, pos.first, pos.second);
}
}

void C_Editor::S_OpenDataDialog(const QModelIndex& i)
{
if(i.column() == 2) // Data column
{
m_DataEditor->setData(i, m_Editor->m_ActivePoly->M_Vertex(i.row()).M_GetData());
m_DataEditor->setVisible(true);
}
}

void C_Editor::S_SetData()
{
QString data=m_DataEditor->getData();
m_Editor->m_ActivePoly->M_Vertex(m_DataEditor->getModelIndex().row()).M_SetData(data);
QStandardItem* item=m_Model->itemFromIndex(m_DataEditor->getModelIndex());
if(data.length()) item->setText("*");
else item->setText("");
S_UpdateList(item);
}
4 changes: 4 additions & 0 deletions editor.h
Expand Up @@ -2,6 +2,7 @@

#include <QtGui/QtGui>
#include "editor_gl.h"
#include "dataeditor.h"

class C_Editor : public QWidget
{
Expand All @@ -20,6 +21,7 @@ class C_Editor : public QWidget
QPushButton* m_Insert;
QPushButton* m_Edit;
QColorDialog* m_ColorDialog;
C_DataEditor* m_DataEditor;
QSplitter* m_Splitter;
QTreeView* m_List;
QList<C_Vertex*> m_VertsToColor;
Expand Down Expand Up @@ -53,6 +55,8 @@ class C_Editor : public QWidget
m_Save->setVisible(true);
}
void S_ReverseActivePolygon();
void S_OpenDataDialog(const QModelIndex&);
void S_SetData();
signals:
void S_SplitPossible(bool b);
void S_SaveAs();
Expand Down
10 changes: 8 additions & 2 deletions pwskoag-modeleditor.pro
@@ -1,5 +1,5 @@
######################################################################
# Automatically generated by qmake (2.01a) Mon Jul 23 22:56:25 2012
# Automatically generated by qmake (2.01a) Fri Feb 1 18:33:41 2013
######################################################################

TEMPLATE = app
Expand All @@ -8,7 +8,13 @@ DEPENDPATH += .
INCLUDEPATH += .

# Input
HEADERS += editor.h editor_gl.h filereader.h main.h polygon.h vertex.h
HEADERS += dataeditor.h \
editor.h \
editor_gl.h \
filereader.h \
main.h \
polygon.h \
vertex.h
SOURCES += editor.cpp \
editor_gl.cpp \
filereader.cpp \
Expand Down
10 changes: 10 additions & 0 deletions vertex.cpp
Expand Up @@ -19,3 +19,13 @@ std::pair<float, float> C_Vertex::M_Pos() const
{
return std::make_pair(x,y);
}

void C_Vertex::M_SetData(const QString& data)
{
m_Data=data;
}

QString C_Vertex::M_GetData() const
{
return m_Data;
}
3 changes: 3 additions & 0 deletions vertex.h
Expand Up @@ -8,6 +8,7 @@ class C_Vertex
private:
C_Polygon* m_Parent;
float x,y;
QString m_Data;
QColor m_Color;
bool m_Selected;
bool m_Hovering;
Expand All @@ -21,5 +22,7 @@ class C_Vertex
void M_SetHovering(bool h) { m_Hovering=h; }
bool M_Hovering() const { return m_Hovering; }
void M_SetPos(float x, float y);
void M_SetData(const QString& data);
QString M_GetData() const;
std::pair<float, float> M_Pos() const;
};

0 comments on commit 95518c1

Please sign in to comment.