Permalink
Browse files

Editor selection now reflects to the list and vice versa

  • Loading branch information...
1 parent a1a010d commit 30aedcff9510044d4f55bda5c9e6204c680efa3a @Detegr committed Feb 9, 2013
Showing with 57 additions and 7 deletions.
  1. +47 −5 editor.cpp
  2. +4 −1 editor.h
  3. +3 −0 editor_gl.cpp
  4. +2 −0 editor_gl.h
  5. +0 −1 main.cpp
  6. +1 −0 polygon.h
View
@@ -61,6 +61,8 @@ void C_Editor::m_Init()
m_Editor = new C_GLEditor(this, root);
QObject::connect(m_Editor, SIGNAL(S_MousePressed(QStandardItem*, float, float, int, const QString&)), this, SLOT(S_AddToList(QStandardItem*, float, float, int, const QString&)));
QObject::connect(m_Editor, SIGNAL(S_SetPos(C_Vertex&, float, float)), this, SLOT(S_SetPos(C_Vertex&, float, float)));
+ QObject::connect(m_Editor, SIGNAL(S_SelectionChanged()), this, SLOT(S_UpdateEditorSelection()));
+ QObject::connect(m_Editor, SIGNAL(S_ClearSelection()), this, SLOT(S_ClearSelection()));
m_ColorDialog = new QColorDialog(this);
m_ColorDialog->hide();
@@ -73,7 +75,8 @@ void C_Editor::m_Init()
m_Center->setFixedWidth(SIDEBAR_WIDTH);
m_List = new QTreeView(this);
- QObject::connect(m_List, SIGNAL(clicked(const QModelIndex&)), this, SLOT(S_SetActivePoly(const QModelIndex&)));
+ m_Selection = new QItemSelectionModel(m_Model);
+ QObject::connect(m_Selection, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(S_SelectionChanged(const QItemSelection&, const QItemSelection&)));
QObject::connect(
m_List,
SIGNAL(doubleClicked(const QModelIndex&)),
@@ -84,6 +87,7 @@ void C_Editor::m_Init()
m_Splitter->addWidget(m_List);
m_List->setHeaderHidden(true);
m_List->setModel(m_Model);
+ m_List->setSelectionModel(m_Selection);
m_List->setFixedWidth(SIDEBAR_WIDTH);
m_List->setIndentation(10);
m_List->setColumnWidth(0, 60);
@@ -200,11 +204,28 @@ QStandardItem* C_Editor::S_NewPolygon(const std::string& name)
return newroot;
}
-void C_Editor::S_SetActivePoly(const QModelIndex& index)
+void C_Editor::S_SelectionChanged(const QItemSelection& s, const QItemSelection& ds)
{
- QStandardItem* i=m_Model->itemFromIndex(index);
- m_SelectedItem=i;
- m_Editor->m_ActivePoly=m_Editor->m_Polygons[i->parent()?i->parent()->row():i->row()];
+ for(int i=0; i<ds.indexes().size(); ++i)
+ {
+ QStandardItem* item=m_Model->itemFromIndex(ds.indexes()[i]);
+ int j=0;
+ for(C_Polygon::iterator it=m_Editor->m_ActivePoly->begin(); it!=m_Editor->m_ActivePoly->end(); ++it, ++j)
+ {
+ if(j==item->row()) it->M_SetSelection(false);
+ }
+ }
+ for(int i=0; i<s.indexes().size(); ++i)
+ {
+ QStandardItem* item=m_Model->itemFromIndex(s.indexes()[i]);
+ m_SelectedItem=item;
+ m_Editor->m_ActivePoly=m_Editor->m_Polygons[item->parent()?item->parent()->row():item->row()]; // TODO: Useless to do every time
+ int j=0;
+ for(C_Polygon::iterator it=m_Editor->m_ActivePoly->begin(); it!=m_Editor->m_ActivePoly->end(); ++it, ++j)
+ {
+ if(j==item->row()) it->M_SetSelection(true);
+ }
+ }
m_Editor->updateGL();
}
@@ -416,3 +437,24 @@ void C_Editor::S_SetData()
else item->setText("");
m_List->setEditTriggers(QAbstractItemView::DoubleClicked);
}
+
+void C_Editor::S_ClearSelection()
+{
+ m_Selection->clearSelection();
+}
+
+void C_Editor::S_UpdateEditorSelection()
+{
+ int i=0;
+ for(C_Polygon::iterator it=m_Editor->m_ActivePoly->begin(); it!=m_Editor->m_ActivePoly->end(); ++it, ++i)
+ {
+ if(it->M_Selected())
+ {
+ m_Selection->select(m_Model->index(i, 0, m_Model->indexFromItem(m_Editor->m_ActivePoly->M_Root())), QItemSelectionModel::Select|QItemSelectionModel::Rows);
+ }
+ else
+ {
+ m_Selection->select(m_Model->index(i, 0, m_Model->indexFromItem(m_Editor->m_ActivePoly->M_Root())), QItemSelectionModel::Deselect|QItemSelectionModel::Rows);
+ }
+ }
+}
View
@@ -24,6 +24,7 @@ class C_Editor : public QWidget
C_DataEditor* m_DataEditor;
QSplitter* m_Splitter;
QTreeView* m_List;
+ QItemSelectionModel* m_Selection;
QList<C_Vertex*> m_VertsToColor;
QShortcut* m_Delete;
bool m_AutoUpdate;
@@ -35,7 +36,7 @@ class C_Editor : public QWidget
void S_DeletePoint();
void S_SetPos(C_Vertex&, float, float);
QStandardItem* S_NewPolygon(const std::string& name="Object");
- void S_SetActivePoly(const QModelIndex&);
+ void S_SelectionChanged(const QItemSelection& s, const QItemSelection& ds);
void S_AddToList(QStandardItem*, float, float, int, const QString&);
void S_UpdateList(QStandardItem* i);
void S_SetInsertMode();
@@ -57,6 +58,8 @@ class C_Editor : public QWidget
void S_ReverseActivePolygon();
void S_OpenDataDialog(const QModelIndex&);
void S_SetData();
+ void S_UpdateEditorSelection();
+ void S_ClearSelection();
signals:
void S_SplitPossible(bool b);
void S_SaveAs();
View
@@ -180,6 +180,7 @@ void C_GLEditor::mousePressEvent(QMouseEvent* e)
}
}
}
+ //emit S_SelectionChanged();
}
m_SplitFirst=m_SplitSecond=NULL;
m_LastClick=std::make_pair(xraw,yraw);
@@ -291,6 +292,7 @@ void C_GLEditor::mouseMoveEvent(QMouseEvent* e)
}
}
}
+ emit S_SelectionChanged();
}
else
{
@@ -345,6 +347,7 @@ void C_GLEditor::mouseReleaseEvent(QMouseEvent* e)
for(unsigned i=0; i<4; ++i) m_DragPoints[i]=0.0f;
updateGL();
}
+ emit S_SelectionChanged();
emit ((C_Editor*)parentWidget())->S_SplitPossible((m_SplitFirst&&m_SplitSecond));
}
View
@@ -52,6 +52,8 @@ class C_GLEditor : public QGLWidget
void S_SetPos(C_Vertex&, float x, float y);
void S_MousePressed(QStandardItem*, float,float,int,const QString&);
void S_RequestColorDialog(QList<C_Vertex*>);
+ void S_SelectionChanged();
+ void S_ClearSelection();
protected:
void initializeGL();
void paintGL();
View
@@ -101,6 +101,5 @@ int main(int argc, char **argv)
}
else w = new C_Main(new C_Editor);
int ret=app.exec();
- delete w;
return ret;
}
View
@@ -31,4 +31,5 @@ class C_Polygon
C_Vertex& M_Last();
std::pair<QStandardItem*, QStandardItem*> M_GetItems(const C_Vertex& v) const;
void M_Reverse();
+ int M_Size() const { return m_Verts.size(); }
};

0 comments on commit 30aedcf

Please sign in to comment.