diff --git a/dataeditor.h b/dataeditor.h new file mode 100644 index 0000000..99dfb93 --- /dev/null +++ b/dataeditor.h @@ -0,0 +1,56 @@ +#pragma once +#include + +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(); + } +}; diff --git a/editor.cpp b/editor.cpp index 620474f..a583ab7 100644 --- a/editor.cpp +++ b/editor.cpp @@ -67,11 +67,20 @@ void C_Editor::m_Init() QObject::connect(m_Editor, SIGNAL(S_RequestColorDialog(QList)), this, SLOT(S_OpenColorDialog(QList))); 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); @@ -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); } @@ -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); +} diff --git a/editor.h b/editor.h index 25f7c06..b40245c 100644 --- a/editor.h +++ b/editor.h @@ -2,6 +2,7 @@ #include #include "editor_gl.h" +#include "dataeditor.h" class C_Editor : public QWidget { @@ -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 m_VertsToColor; @@ -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(); diff --git a/pwskoag-modeleditor.pro b/pwskoag-modeleditor.pro index 4711f2d..9a48d12 100644 --- a/pwskoag-modeleditor.pro +++ b/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 @@ -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 \ diff --git a/vertex.cpp b/vertex.cpp index 3005ae4..e2f6477 100644 --- a/vertex.cpp +++ b/vertex.cpp @@ -19,3 +19,13 @@ std::pair 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; +} diff --git a/vertex.h b/vertex.h index f49ba46..08f0830 100644 --- a/vertex.h +++ b/vertex.h @@ -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; @@ -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 M_Pos() const; };