Skip to content
Snippets Groups Projects
Commit 0a57af1c authored by stefan's avatar stefan
Browse files

Added context menu to views in scene win

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1770 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 3812435e
Branches
Tags
No related merge requests found
Showing
with 504 additions and 150 deletions
......@@ -48,7 +48,7 @@ class InspectorWidget(ToolBarOptionsWidget):
app=gui.GostyApp.Instance()
self.scene_selection_ = gui.SceneSelection.Instance()
scenewin = sip.wrapinstance(app.GetSceneWin().GetSipHandle(),QtGui.QWidget)
QtCore.QObject.connect(scenewin,QtCore.SIGNAL("ActiveNodesChanged(gfx::NodePtrList)"),
QtCore.QObject.connect(scenewin,QtCore.SIGNAL("ActiveNodesChanged(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList)"),
self.EntitySelectionChanged)
self.setMinimumSize(250,215)
......
......@@ -55,7 +55,9 @@ shell_history.hh
)
set(OST_GUI_SCENE_WIN_HEADERS
context_menu.hh
current_selection_node.hh
custom_part_node.hh
entity_node.hh
entity_part_node.hh
gfx_scene_node.hh
......@@ -257,7 +259,9 @@ python_shell/python_syntax_highlighter.cc
python_shell/shell_history.cc
python_shell/string_literal_positions.cc
python_shell/text_logger.cc
scene_win/context_menu.cc
scene_win/current_selection_node.cc
scene_win/custom_part_node.cc
scene_win/scene_node.cc
scene_win/label_node.cc
scene_win/entity_node.cc
......@@ -321,7 +325,9 @@ panel_bar/panel_bar_widget_holder.hh
panel_bar/side_bar.hh
panel_bar/splitter_panel_bar.hh
panel_bar/tabbed_panel_bar.hh
scene_win/context_menu.hh
scene_win/current_selection_node.hh
scene_win/custom_part_node.hh
scene_win/gfx_scene_node.hh
scene_win/label_node.hh
scene_win/entity_node.hh
......
......@@ -21,6 +21,8 @@
#include <ost/geom/vec3.hh>
#include <ost/geom/vecmat3_op.hh>
#include <ost/mol/view_op.hh>
#include <ost/gfx/scene.hh>
#include <ost/gfx/gfx_object.hh>
#include <ost/gfx/entity.hh>
......@@ -35,15 +37,17 @@
namespace ost { namespace gui {
SceneSelection* SceneSelection::scene_selection_ = NULL;
SceneSelection::SceneSelection():nodes_()
SceneSelection::SceneSelection():nodes_(),views_()
{
SceneWin* scene_win = GostyApp::Instance()->GetSceneWin();
QObject::connect(scene_win, SIGNAL(ActiveNodesChanged(gfx::NodePtrList)),
this, SLOT(SetActiveNodes(gfx::NodePtrList)));
QObject::connect(scene_win, SIGNAL(ActiveNodesChanged(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList)),
this, SLOT(SetActiveNodes(gfx::NodePtrList,gfx::EntityP,mol::QueryViewWrapperList)));
}
void SceneSelection::SetActiveNodes(gfx::NodePtrList nodes){
void SceneSelection::SetActiveNodes(gfx::NodePtrList nodes, gfx::EntityP entity, mol::QueryViewWrapperList views){
nodes_ = nodes;
view_entity_ = entity;
views_ = views;
}
gfx::GfxNodeP SceneSelection::GetActiveNode(unsigned int pos){
......@@ -59,6 +63,10 @@ int SceneSelection::GetActiveNodeCount(){
return nodes_.size();
}
int SceneSelection::GetActiveViewCount(){
return views_.size();
}
SceneSelection* SceneSelection::Instance() {
if (!SceneSelection::scene_selection_) {
SceneSelection::scene_selection_=new SceneSelection;
......@@ -176,46 +184,42 @@ void SceneSelection::Hide() {
}
}
void SceneSelection::ShowMenu(const QPoint & p){
QMenu* menu = new QMenu();
bool all_visible = true;
bool all_not_scene = true;
bool all_hidden = true;
bool all_entities = true;
bool all_gfx_objects = true;
for(unsigned int i = 0; i < nodes_.size(); i++){
if(nodes_[i]){
if(nodes_[i]->IsVisible()){all_hidden=false;}
else{all_visible=false;}
if(nodes_[i]->GetType()==0){all_not_scene = false;}
if(!dynamic_cast<gfx::GfxObj*> (nodes_[i].get())){all_gfx_objects = false;}
if(!dynamic_cast<gfx::Entity*> (nodes_[i].get())){all_entities = false;}
mol::EntityView SceneSelection::GetViewUnion() {
mol::EntityView view;
if(views_.size()>0){
view = views_[0].GetEntityView().Copy();
for(unsigned int i = 1; i < views_.size(); i++){
view = mol::Union(view,views_[i].GetEntityView());
}
}
QAction* action;
if(all_gfx_objects){
action = menu->addAction("Center on Object");
connect(action, SIGNAL(triggered()), this, SLOT(CenterOnObjects()));
}
if(all_entities){
action = menu->addAction("Copy");
connect(action, SIGNAL(triggered()), this, SLOT(CopyViews()));
action = menu->addAction("Select");
connect(action, SIGNAL(triggered()), this, SLOT(Select()));
}
if(all_not_scene){
action = menu->addAction("Delete");
connect(action, SIGNAL(triggered()), this, SLOT(Delete()));
}
if(!all_visible){
action = menu->addAction("Show");
connect(action, SIGNAL(triggered()), this, SLOT(Show()));
return view;
}
void SceneSelection::ShowExclusive(){
view_entity_->SetVisible(view_entity_->GetView(),false);
this->MakeVisible();
}
void SceneSelection::HideExclusive(){
view_entity_->SetVisible(view_entity_->GetView(),true);
this->MakeHidden();
}
void SceneSelection::MakeVisible(){
for(unsigned int i= 0; i < views_.size(); i++){
view_entity_->SetVisible(views_[i].GetEntityView(),true);
}
if(!all_hidden){
action = menu->addAction("Hide");
connect(action, SIGNAL(triggered()), this, SLOT(Hide()));
}
void SceneSelection::MakeHidden(){
for(unsigned int i= 0; i < views_.size(); i++){
view_entity_->SetVisible(views_[i].GetEntityView(),false);
}
menu->popup(p);
}
gfx::EntityP SceneSelection::GetViewEntity(){
return view_entity_;
}
}}
......@@ -23,6 +23,9 @@
#include <QMenu>
#include <QPoint>
#include <ost/mol/query_view_wrapper.hh>
#include <ost/gfx/entity.hh>
#include <ost/gfx/gfx_node_fw.hh>
#include <ost/gui/module_config.hh>
......@@ -34,7 +37,8 @@ public:
static SceneSelection* Instance();
gfx::GfxNodeP GetActiveNode(unsigned int pos);
int GetActiveNodeCount();
void ShowMenu(const QPoint & p);
int GetActiveViewCount();
gfx::EntityP GetViewEntity();
public slots:
void CenterOnObjects();
......@@ -43,13 +47,20 @@ public slots:
void Select();
void Show();
void Hide();
void MakeVisible();
void MakeHidden();
void ShowExclusive();
void HideExclusive();
mol::EntityView GetViewUnion();
private slots:
void SetActiveNodes(gfx::NodePtrList nodes);
void SetActiveNodes(gfx::NodePtrList nodes, gfx::EntityP entity, mol::QueryViewWrapperList views);
private:
SceneSelection();
gfx::NodePtrList nodes_;
gfx::EntityP view_entity_;
mol::QueryViewWrapperList views_;
static SceneSelection* scene_selection_;
QMenu* menu_;
};
......
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2010 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
/*
Authors: Stefan Scheuber
*/
#include <QAction>
#include <QMenu>
#include <QItemSelection>
#include <QItemSelectionModel>
#include <ost/gui/scene_selection.hh>
#include "custom_part_node.hh"
#include "entity_node.hh"
#include "entity_part_node.hh"
#include "gfx_scene_node.hh"
#include "context_menu.hh"
namespace ost { namespace gui {
ContextMenu::ContextMenu(QTreeView* view, SceneWinModel* model):
QObject(model),view_(view),model_(model)
{
}
void ContextMenu::ShowMenu(const QPoint& pos)
{
QModelIndexList indexes = view_->selectionModel()->selection().indexes();
bool all_visible = true;
bool all_not_scene = true;
bool all_hidden = true;
bool all_entities = true;
bool all_gfx_objects = true;
bool all_entity_views = true;
bool all_custom_views = true;
if(indexes.size()>0){
for(int i = 0; i < indexes.size(); i++){
if(indexes[i].column()==0){
GfxSceneNode* gfx_scene_node = qobject_cast<GfxSceneNode*>(model_->GetItem(indexes[i]));
if(gfx_scene_node){
gfx::GfxNodeP gfx_node = gfx_scene_node->GetGfxNode();
if(gfx_node->IsVisible()){all_hidden=false;}
else{all_visible=false;}
if(gfx_node->GetType()==0){all_not_scene = false;}
if(!dynamic_cast<gfx::GfxObj*> (gfx_node.get())){all_gfx_objects = false;}
if(!dynamic_cast<gfx::Entity*> (gfx_node.get())){all_entities = false;}
}
else{
all_gfx_objects = false;
all_entities = false;
all_visible = true;
all_hidden = true;
}
EntityPartNode* entity_part_node = qobject_cast<EntityPartNode*>(model_->GetItem(indexes[i]));
if(!entity_part_node){
all_entity_views = false;
all_custom_views = false;
}
else{
CustomPartNode* custom_part_node = qobject_cast<CustomPartNode*>(entity_part_node);
if(!custom_part_node){
all_custom_views = false;
}
}
}
}
QMenu* menu = new QMenu();
QAction* action;
if(all_gfx_objects){
action = menu->addAction("Center on Object");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(CenterOnObjects()));
}
if(all_entities){
action = menu->addAction("Copy");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(CopyViews()));
action = menu->addAction("Select");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Select()));
if(all_not_scene){
action = menu->addAction("Delete");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Delete()));
}
}
if(!all_visible){
action = menu->addAction("Show");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Show()));
}
if(!all_hidden){
action = menu->addAction("Hide");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(Hide()));
}
if((all_gfx_objects || all_custom_views) && indexes.size()==2){
action = menu->addAction("Rename");
connect(action, SIGNAL(triggered()), this, SLOT(Rename()));
}
if(all_entity_views){
action = menu->addAction("Show");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(MakeVisible()));
action = menu->addAction("Hide");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(MakeHidden()));
action = menu->addAction("Show Exclusive");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(ShowExclusive()));
action = menu->addAction("Hide Exclusive");
connect(action, SIGNAL(triggered()), SceneSelection::Instance(), SLOT(HideExclusive()));
action = menu->addAction("Create Custom View");
connect(action, SIGNAL(triggered()), this, SLOT(AddView()));
}
menu->popup(pos);
}
}
void ContextMenu::AddView(){
gfx::EntityP entity = SceneSelection::Instance()->GetViewEntity();
EntityNode* ent_node = qobject_cast<EntityNode*>(model_->FindGfxNode(entity));
if(ent_node)
{
mol::EntityView view = SceneSelection::Instance()->GetViewUnion();
SceneNode* child_node = new CustomPartNode("New View", entity, mol::QueryViewWrapper(view),ent_node->GetCustomViewNode());
model_->AddNode(ent_node->GetCustomViewNode(),child_node);
this->Rename(model_->GetIndexOf(child_node,1));
}
}
void ContextMenu::Rename(QModelIndex index){
if(index.isValid()){
view_->expand(index.parent());
view_->edit(index);
}
}
void ContextMenu::Rename(){
QModelIndexList indexes = view_->selectionModel()->selection().indexes();
if(indexes.size() == 2)
{
this->Rename(indexes[1]);
}
}
}} // ns
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2010 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#ifndef OST_GUI_SCENE_WIN_CONTEXT_MENU_HH
#define OST_GUI_SCENE_WIN_CONTEXT_MENU_HH
/*
Author: Stefan Scheuber
*/
#include <QMap>
#include <QAbstractItemModel>
#include <QTreeView>
#include <ost/gui/module_config.hh>
#include <ost/gui/scene_win/scene_win_model.hh>
namespace ost { namespace gui {
enum ContextMenuType {
GFX_OBJECTS = 1,
ENTITIES,
ENTITY_VIEWS,
MIX
};
class DLLEXPORT_OST_GUI ContextMenu : public QObject {
Q_OBJECT
public:
ContextMenu(QTreeView* view, SceneWinModel* model);
~ContextMenu(){};
void ShowMenu(const QPoint& pos);
void Rename(QModelIndex index);
private slots:
void AddView();
void Rename();
private:
gui::ContextMenuType GetType();
QTreeView* view_;
SceneWinModel* model_;
};
}}
#endif
......@@ -18,6 +18,8 @@
//------------------------------------------------------------------------------
#include <QFont>
#include <ost/mol/query_view_wrapper.hh>
#include <ost/gfx/scene.hh>
#include <ost/gfx/gfx_node.hh>
......@@ -28,61 +30,21 @@
namespace ost { namespace gui {
CurrentSelectionNode::CurrentSelectionNode(gfx::EntityP entity, SceneNode* parent):GfxSceneNode(entity,parent),visible_(true){
//GostyApp::Instance()->GetSceneWin()->GetModel()->AttachSelectionObserver(this);
}
QVariant CurrentSelectionNode::GetData(int column, int role){
if(column<0 || column > 2)return QVariant();
if (role==Qt::CheckStateRole && column==0) {
return QVariant(visible_ ? Qt::Checked : Qt::Unchecked);
} else if(column==1) {
if (role==Qt::DisplayRole) {
return QVariant("Current Selection");
} else if(role==Qt::FontRole) {
QFont f("Helvetica");
return QVariant(f);
}
}
return QVariant();
CurrentSelectionNode::CurrentSelectionNode(gfx::EntityP entity, SceneNode* parent):EntityPartNode("Current Selection",entity,mol::QueryViewWrapper(entity->GetSelection()),parent),wrapper_(mol::QueryViewWrapper(entity->GetSelection())){
}
int CurrentSelectionNode::GetColumnCount() const{
return 2;
void CurrentSelectionNode::SetQueryView(mol::QueryViewWrapper part)
{
//Do Nothing
}
bool CurrentSelectionNode::SetData(int column, const QVariant& value, int role){
if (column==0 && role == Qt::CheckStateRole) {
gfx::EntityP entity =boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode());
if (value.toBool()) {
this->GetParent()->SetData(0,value,Qt::CheckStateRole);
entity->SetVisible(entity->GetSelection(), true);
visible_=true;
} else {
entity->SetVisible(entity->GetSelection(), false);
visible_=false;
}
return true;
mol::QueryViewWrapper CurrentSelectionNode::GetQueryView() const
{
if(this->GetEntity()->GetSelection()!=wrapper_.GetEntityView()){
wrapper_ = mol::QueryViewWrapper(this->GetEntity()->GetSelection());
}
return false;
}
Qt::ItemFlags CurrentSelectionNode::Flags(int column) const{
if(column==0){
return Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled;
}
else if(column==1){
return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
}
return Qt::NoItemFlags;
}
void CurrentSelectionNode::SelectionChanged(){
if(visible_){
gfx::EntityP entity = boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode());
entity->SetVisible(entity->GetSelection(),true);
}
return wrapper_;
}
}}
......
......@@ -28,12 +28,9 @@
#include <ost/gfx/entity.hh>
#include <ost/gfx/entity_fw.hh>
#include <ost/gfx/scene_observer.hh>
#include <ost/gfx/gfx_object.hh>
#include <ost/gfx/gfx_object_fw.hh>
#include <ost/gui/module_config.hh>
#include <ost/gui/scene_win/gfx_scene_node.hh>
#include <ost/gui/scene_win/entity_part_node.hh>
/*
Author: Stefan Scheuber
......@@ -41,21 +38,16 @@
namespace ost { namespace gui {
class DLLEXPORT_OST_GUI CurrentSelectionNode : public GfxSceneNode {
class DLLEXPORT_OST_GUI CurrentSelectionNode : public EntityPartNode {
Q_OBJECT
public:
CurrentSelectionNode(gfx::EntityP entity, SceneNode* node_parent );
virtual QVariant GetData(int column, int role);
virtual bool SetData(int column, const QVariant& value, int role);
virtual Qt::ItemFlags Flags(int column) const;
virtual int GetColumnCount() const;
//Scene Observer interface
virtual void SelectionChanged();
virtual void SetQueryView(mol::QueryViewWrapper part);
virtual mol::QueryViewWrapper GetQueryView() const;
private:
bool visible_;
mutable mol::QueryViewWrapper wrapper_;
};
}}
......
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2009 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#include <QFont>
#include "custom_part_node.hh"
#include "entity_part_node.hh"
#include <ost/gfx/entity.hh>
#include <ost/gfx/gfx_node.hh>
namespace ost { namespace gui {
CustomPartNode::CustomPartNode(QString name, gfx::EntityP entity, mol::QueryViewWrapper part, SceneNode* parent):EntityPartNode(name,entity,part,parent){
}
bool CustomPartNode::SetData(int column, const QVariant& value, int role){
if (column==1 && role == Qt::EditRole) {
this->SetName(value.toString());
return true;
}
return false;
}
Qt::ItemFlags CustomPartNode::Flags(int column) const{
if(column==0){
return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
}
else if(column==1){
return Qt::ItemIsSelectable|Qt::ItemIsEnabled|Qt::ItemIsEditable;
}
return Qt::NoItemFlags;
}
}}
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2009 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#ifndef OST_GUI_SCENE_WIN_CUSTOM_PART_NODE_HH
#define OST_GUI_SCENE_WIN_CUSTOM_PART_NODE_HH
#include <QObject>
#include <QVariant>
#include <QModelIndex>
#include <ost/mol/query_view_wrapper.hh>
#include <ost/gfx/entity_fw.hh>
#include <ost/gui/module_config.hh>
#include <ost/gui/scene_win/scene_node.hh>
#include "entity_part_node.hh"
/*
Author: Stefan Scheuber
*/
namespace ost { namespace gui {
class DLLEXPORT_OST_GUI CustomPartNode : public EntityPartNode {
Q_OBJECT
public:
CustomPartNode(QString name, gfx::EntityP entity, mol::QueryViewWrapper part, SceneNode* node_parent );
virtual bool SetData(int column, const QVariant& value, int role);
virtual Qt::ItemFlags Flags(int column) const;
};
}}
#endif
......@@ -37,7 +37,7 @@
namespace ost { namespace gui {
EntityNode::EntityNode(gfx::EntityP& entity, SceneNode* parent):
GfxSceneNode(entity,parent){
GfxSceneNode(entity,parent),custom_view_(NULL){
SceneWinModel* model = GostyApp::Instance()->GetSceneWin()->GetModel();
model->AddNode(parent, this);
......@@ -51,6 +51,9 @@ EntityNode::EntityNode(gfx::EntityP& entity, SceneNode* parent):
node = new EntityPartNode("Ligands", entity, mol::QueryViewWrapper(entity->GetView().Select("ishetatm=1 and ele=C")), quick_selection);
model->AddNode(quick_selection, node);
custom_view_ = new LabelNode("Custom Views", this);
model->AddNode(this, custom_view_);
node = new EntityPartNode("Full View", entity, mol::QueryViewWrapper(entity->GetView()), this);
model->AddNode(this, node);
......@@ -58,5 +61,9 @@ EntityNode::EntityNode(gfx::EntityP& entity, SceneNode* parent):
model->AddNode(this, node);
}
SceneNode* EntityNode::GetCustomViewNode(){
return custom_view_;
}
}}
......@@ -38,6 +38,11 @@ class DLLEXPORT_OST_GUI EntityNode : public GfxSceneNode {
Q_OBJECT
public:
EntityNode(gfx::EntityP& entity, SceneNode* node_parent);
SceneNode* GetCustomViewNode();
private:
SceneNode* custom_view_;
};
}}
......
......@@ -30,10 +30,7 @@ EntityPartNode::EntityPartNode(QString name, gfx::EntityP entity, mol::QueryView
QVariant EntityPartNode::GetData(int column, int role){
if(column<0 || column > 2)return QVariant();
if (role==Qt::CheckStateRole && column==0) {
return QVariant(visible_ ? Qt::Checked : Qt::Unchecked);
} else if(column==1) {
if(column==1) {
if (role==Qt::DisplayRole) {
return QVariant(name_);
} else if(role==Qt::FontRole) {
......@@ -48,24 +45,9 @@ int EntityPartNode::GetColumnCount() const{
return 2;
}
bool EntityPartNode::SetData(int column, const QVariant& value, int role){
if (column==0 && role == Qt::CheckStateRole) {
if (value.toBool()) {
this->GetParent()->SetData(0,value,Qt::CheckStateRole);
entity_->SetVisible(query_view_.GetEntityView(), true);
visible_=true;
} else {
entity_->SetVisible(query_view_.GetEntityView(), false);
visible_=false;
}
return true;
}
return false;
}
Qt::ItemFlags EntityPartNode::Flags(int column) const{
if(column==0){
return Qt::ItemIsSelectable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled;
return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
}
else if(column==1){
return Qt::ItemIsSelectable|Qt::ItemIsEnabled;
......@@ -81,5 +63,25 @@ mol::QueryViewWrapper EntityPartNode::GetQueryView() const{
return query_view_;
}
void EntityPartNode::SetVisible(bool visible){
visible_ = visible;
}
bool EntityPartNode::GetVisible(){
return visible_;
}
gfx::EntityP EntityPartNode::GetEntity() const{
return entity_;
}
void EntityPartNode::SetName(QString name){
name_ = name;
}
const QString& EntityPartNode::GetName() const{
return name_;
}
}}
......@@ -23,9 +23,10 @@
#include <QVariant>
#include <QModelIndex>
#include <ost/mol/query_view_wrapper.hh>
#include <ost/gfx/entity_fw.hh>
#include <ost/mol/query_view_wrapper.hh>
#include <ost/gui/module_config.hh>
#include <ost/gui/scene_win/scene_node.hh>
......@@ -41,13 +42,21 @@ public:
EntityPartNode(QString name, gfx::EntityP entity, mol::QueryViewWrapper part, SceneNode* node_parent );
virtual QVariant GetData(int column, int role);
virtual bool SetData(int column, const QVariant& value, int role);
virtual Qt::ItemFlags Flags(int column) const;
virtual int GetColumnCount() const;
virtual void SetQueryView(mol::QueryViewWrapper part);
virtual mol::QueryViewWrapper GetQueryView() const;
virtual gfx::EntityP GetEntity() const;
virtual void SetName(QString name);
virtual const QString& GetName() const;
protected:
virtual void SetVisible(bool visible);
virtual bool GetVisible();
private:
QString name_;
gfx::EntityP entity_;
......
......@@ -59,9 +59,6 @@ bool GfxSceneNode::SetData(int column, const QVariant& value, int role){
gfx_node_->Show();
} else {
gfx_node_->Hide();
for(int i = 0; i<this->GetChildCount(); i++){
this->GetChild(i)->SetData(0,value,Qt::CheckStateRole);
}
}
return true;
}
......
......@@ -18,29 +18,25 @@
//------------------------------------------------------------------------------
#include <QFont>
#include <ost/gfx/scene.hh>
#include <ost/gfx/gfx_node.hh>
#include <ost/gui/gosty_app.hh>
#include <ost/gui/scene_win/scene_win.hh>
#include <ost/mol/query_view_wrapper.hh>
#include "render_mode_node.hh"
namespace ost { namespace gui {
RenderModeNode::RenderModeNode(gfx::EntityP entity, gfx::RenderMode::Type render_mode, SceneNode* parent):GfxSceneNode(entity,parent),render_mode_(render_mode){
RenderModeNode::RenderModeNode(gfx::EntityP entity, gfx::RenderMode::Type render_mode, SceneNode* parent):EntityPartNode(entity->GetRenderModeName(render_mode).c_str(),entity,mol::QueryViewWrapper(entity->GetRenderView(render_mode)),parent),
entity_(entity),
render_mode_(render_mode){
}
QVariant RenderModeNode::GetData(int column, int role){
if(column<0 || column > 2)return QVariant();
if (role==Qt::CheckStateRole && column==0) {
gfx::EntityP entity =boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode());
return QVariant(entity->IsRenderModeEnabled(render_mode_) ? Qt::Checked : Qt::Unchecked);
return QVariant(entity_->IsRenderModeEnabled(render_mode_) ? Qt::Checked : Qt::Unchecked);
} else if(column==1) {
if (role==Qt::DisplayRole) {
gfx::EntityP entity =boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode());
String name = entity->GetRenderModeName(render_mode_);
String name = entity_->GetRenderModeName(render_mode_);
return QVariant(name.c_str());
} else if(role==Qt::FontRole) {
QFont f("Helvetica");
......@@ -56,12 +52,11 @@ int RenderModeNode::GetColumnCount() const{
bool RenderModeNode::SetData(int column, const QVariant& value, int role){
if (column==0 && role == Qt::CheckStateRole) {
gfx::EntityP entity =boost::dynamic_pointer_cast<gfx::Entity>(this->GetGfxNode());
if (value.toBool()) {
this->GetParent()->SetData(0,value,Qt::CheckStateRole);
entity->SetEnableRenderMode(render_mode_, true);
entity_->SetEnableRenderMode(render_mode_, true);
} else {
entity->SetEnableRenderMode(render_mode_, false);
entity_->SetEnableRenderMode(render_mode_, false);
}
return true;
}
......@@ -82,5 +77,10 @@ gfx::RenderMode::Type RenderModeNode::GetRenderMode() const {
return render_mode_;
}
void RenderModeNode::SetQueryView(mol::QueryViewWrapper part)
{
//Do Nothing
}
}}
......@@ -34,7 +34,7 @@
#include <ost/gfx/gfx_object_fw.hh>
#include <ost/gui/module_config.hh>
#include <ost/gui/scene_win/gfx_scene_node.hh>
#include <ost/gui/scene_win/entity_part_node.hh>
/*
Author: Stefan Scheuber
......@@ -42,7 +42,7 @@
namespace ost { namespace gui {
class DLLEXPORT_OST_GUI RenderModeNode : public GfxSceneNode {
class DLLEXPORT_OST_GUI RenderModeNode : public EntityPartNode {
Q_OBJECT
public:
RenderModeNode(gfx::EntityP entity, gfx::RenderMode::Type render_mode, SceneNode* node_parent );
......@@ -54,7 +54,10 @@ public:
gfx::RenderMode::Type GetRenderMode() const;
virtual void SetQueryView(mol::QueryViewWrapper part);
private:
gfx::EntityP entity_;
gfx::RenderMode::Type render_mode_;
};
......
......@@ -52,7 +52,6 @@ public:
virtual bool SetData(int column, const QVariant& value, int role);
virtual Qt::ItemFlags Flags(int column) const;
virtual int GetColumnCount() const;
private:
SceneNode* parent_;
SceneNodeList nodes_;
......
......@@ -50,6 +50,7 @@ SceneWin::SceneWin(QWidget* parent) :
layout->setSpacing(0);
model_ = new SceneWinModel(this);
view_ = new QTreeView(this);
context_menu_ = new ContextMenu(view_,model_);
view_->setAttribute(Qt::WA_MacShowFocusRect, false);
view_->header()->hide();
view_->setContextMenuPolicy(Qt::CustomContextMenu);
......@@ -57,6 +58,7 @@ SceneWin::SceneWin(QWidget* parent) :
view_->setSelectionBehavior(QAbstractItemView::SelectRows);
view_->setSelectionMode(QAbstractItemView::ExtendedSelection);
view_->expandAll();
layout->addWidget(view_);
connect(view_->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection&,
......@@ -70,7 +72,7 @@ SceneWin::SceneWin(QWidget* parent) :
void SceneWin::ContextMenuRequested(const QPoint& pos) {
if (view_->indexAt(pos).isValid()) {
SceneSelection::Instance()->ShowMenu(view_->viewport()->mapToGlobal(pos));
context_menu_->ShowMenu(view_->viewport()->mapToGlobal(pos));
}
}
......@@ -79,7 +81,12 @@ void SceneWin::OnSelectionChange(const QItemSelection& sel,
QItemSelectionModel* model = view_->selectionModel();
QModelIndexList indexes = model->selection().indexes();
gfx::NodePtrList selected_nodes = model_->GetGfxNodes(indexes);
emit this->ActiveNodesChanged(selected_nodes);
mol::QueryViewWrapperList selected_views = model_->GetQueryViewsList(indexes);
gfx::EntityP entity = model_->GetEntityOfViews(indexes);
if(entity)
emit this->ActiveNodesChanged(selected_nodes,entity,selected_views);
else
emit this->ActiveNodesChanged(selected_nodes,entity,mol::QueryViewWrapperList());
}
SceneWinModel* SceneWin::GetModel(){
......@@ -100,6 +107,11 @@ void SceneWin::RowsInserted(const QModelIndex & parent, int start, int end){
}
void SceneWin::AddView(gfx::EntityP entity, mol::EntityView view){
}
SceneWin::~SceneWin() {
}
......
......@@ -22,11 +22,14 @@
#include <QTreeView>
#include <QItemSelection>
#include <ost/mol/query_view_wrapper.hh>
#include <ost/gfx/gfx_node_fw.hh>
#include <ost/gui/module_config.hh>
#include <ost/gui/widget.hh>
#include <ost/gui/scene_win/scene_win_model.hh>
#include <ost/gui/scene_win/context_menu.hh>
/*
Authors: Marco Biasini, Ansgar Philippsen, Stefan Scheuber
......@@ -43,12 +46,14 @@ public:
~SceneWin();
signals:
void ActiveNodesChanged(gfx::NodePtrList nodes);
void ActiveNodesChanged(gfx::NodePtrList nodes, gfx::EntityP entity, mol::QueryViewWrapperList views);
public:
virtual bool Save(const QString& prefix) { return true; }
virtual bool Restore(const QString& prefix) { return true; }
void AddView(gfx::EntityP entity, mol::EntityView view);
public slots:
void OnSelectionChange(const QItemSelection& sel, const QItemSelection& desel);
......@@ -64,6 +69,7 @@ private slots:
private:
SceneWinModel* model_;
QTreeView* view_;
ContextMenu* context_menu_;
};
}} // ns
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment