Skip to content
Snippets Groups Projects
Commit 39c2d538 authored by marco's avatar marco
Browse files

fix AddWidgetToPool and rename WrappedWidget to Widget

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2666 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 161f0f19
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@ panels=gui.GostyApp.Instance().perspective.panels
tetris=Board(panels.qobject)
#Wrap widget to Qt Widget
wid=gui.WrappedWidget(tetris)
wid=gui.Widget(tetris)
#Add Widget to widget pool
panels.AddWidgetToPool("Break Widget",wid)
......
......@@ -35,22 +35,22 @@ struct WrappedWidget : public Widget
{
WrappedWidget(PyObject *p, object py_object):
Widget(NULL,NULL){
if(QWidget* widget = get_cpp_qobject<QWidget>(py_object)){
if (QWidget* widget=get_cpp_qobject<QWidget>(py_object)) {
this->SetInternalWidget(widget);
}
}
virtual bool Restore(const QString& prefix){return true;}
virtual bool Save(const QString& prefix){return true;}
virtual ~WrappedWidget(){ }
private:
QString unique_id_;
};
void export_Widget()
{
class_<Widget, WrappedWidget, boost::noncopyable>("WrappedWidget",init<object>())
class_<Widget, WrappedWidget, boost::noncopyable>("Widget", init<object>())
.def("Save", &WrappedWidget::Save)
.def("Restore", &WrappedWidget::Restore)
.def("SetDestroyOnClose", &WrappedWidget::SetDestroyOnClose)
......
......@@ -69,7 +69,7 @@ void PanelBar::AddWidget(Widget* widget, bool is_hidden)
{
int index = this->GetIndex(widget);
if (index == -1) {
QString class_name = widget->metaObject()->className();
QString class_name = widget->GetUniqueID();
WidgetState ws = WidgetState(widget, !is_hidden, class_name);
widget_states_.append(ws);
if(current_view_mode_){
......@@ -221,7 +221,7 @@ void PanelBar::InsertWidget(Widget * widget, int index, bool is_hidden)
current_view_mode_->WidgetMoved(widget, index);
}
} else {
QString class_name = widget->metaObject()->className();
QString class_name = widget->GetUniqueID();
WidgetState ws = WidgetState(widget, !is_hidden, class_name);
widget_states_.insert(index, ws);
if(current_view_mode_){
......
......@@ -86,7 +86,7 @@ void PanelBarWidgetHolder::SetupToolBar()
icon_path.cd("gui");
icon_path.cd("icons");
QString class_name=widget_->metaObject()->className();
QString class_name=widget_->GetUniqueID();
WidgetRegistry* wf=WidgetRegistry::Instance();
toolbar_->setAttribute(Qt::WA_MacSmallSize);
QAction* label_ = toolbar_->addAction(wf->GetFullName(class_name));
......@@ -123,7 +123,7 @@ void PanelBarWidgetHolder::SetWidget(Widget* widget)
assert(l);
l->removeWidget(widget_);
l->addWidget(widget, 1);
QString class_name=widget->metaObject()->className();
QString class_name=widget->GetUniqueID();
WidgetRegistry* wf=WidgetRegistry::Instance();
label_->setText(wf->GetFullName(class_name));
widget_=widget;
......@@ -135,7 +135,7 @@ void PanelBarWidgetHolder::LabelClick(bool checked)
QMenu* m = panels->GetAvailableWidgetsMenu();
if (QAction* a=m->exec(toolbar_->mapToGlobal(QPoint(0, 0)))) {
QString new_class_name=a->data().toString();
if (new_class_name!=widget_->metaObject()->className()) {
if (new_class_name!=widget_->GetUniqueID()) {
panels->ReplaceWidget(widget_,new_class_name);
}
}
......
......@@ -101,20 +101,19 @@ void PanelManager::AddWidgetToPool(const QString& class_name, int limit){
pool_->Add(class_name, limit);
}
void PanelManager::AddWidgetToPool(const QString& name, Widget* widget){
QString id = widget->metaObject()->className();
widget->setParent(this);
id.replace(".", "::");
ExternalWidgetFactory* ewf = new ExternalWidgetFactory(id,name,widget);
void PanelManager::AddWidgetToPool(const QString& name, Widget* widget) {
//widget->setParent(this);
widget->SetUniqueID(name);
ExternalWidgetFactory* ewf = new ExternalWidgetFactory(name, name, widget);
WidgetRegistry::Instance()->RegisterWidgetFactory(ewf);
pool_->Add(id, 1);
pool_->Add(name, 1);
}
void PanelManager::AddWidget(PanelPosition pos, Widget* widget, bool is_hidden){
if(panels_.contains(pos) && this->GetParentPanel(widget) == NONE){
if(pool_->IsAvailable(widget->metaObject()->className())){
if(pool_->IsAvailable(widget->GetUniqueID())){
panels_[pos]->AddWidget(widget,is_hidden);
pool_->Take(widget->metaObject()->className());
pool_->Take(widget->GetUniqueID());
}
}
}
......@@ -243,11 +242,11 @@ void PanelManager::MoveWidget(Widget * widget, PanelPosition pos, int index){
else{
if(panels_.contains(current_position)){
panels_[current_position]->RemoveWidget(widget);
pool_->Give(widget->metaObject()->className());
pool_->Give(widget->GetUniqueID());
}
if(pool_->IsAvailable(widget->metaObject()->className())){
if(pool_->IsAvailable(widget->GetUniqueID())){
panels_[pos]->InsertWidget(widget,index,false);
pool_->Take(widget->metaObject()->className());
pool_->Take(widget->GetUniqueID());
}
}
}
......@@ -261,15 +260,15 @@ void PanelManager::MoveNextTo(Widget* target, Widget* widget){
}
void PanelManager::ReplaceWidget(Widget* w1, Widget* w2){
if(pool_->IsAvailable(w2->metaObject()->className())){
if(pool_->IsAvailable(w2->GetUniqueID())){
PanelPosition pos_w1 = this->GetParentPanel(w1);
PanelPosition pos_w2 = this->GetParentPanel(w2);
if(panels_.contains(pos_w1) && pos_w2 == NONE){
int index = panels_[pos_w1]->GetIndex(w1);
panels_[pos_w1]->RemoveWidget(w1);
pool_->Give(w1->metaObject()->className());
pool_->Give(w1->GetUniqueID());
panels_[pos_w1]->InsertWidget(w2,index,false);
pool_->Take(w2->metaObject()->className());
pool_->Take(w2->GetUniqueID());
}
}
}
......@@ -280,7 +279,7 @@ void PanelManager::ReplaceWidget(Widget* w1, QString& class_name){
if(panels_.contains(pos)){
int index = panels_[pos]->GetIndex(w1);
panels_[pos]->RemoveWidget(w1);
pool_->Give(w1->metaObject()->className());
pool_->Give(w1->GetUniqueID());
WidgetRegistry* wf=WidgetRegistry::Instance();
Widget* widget = wf->Create(class_name,this);
panels_[pos]->InsertWidget(widget,index,false);
......@@ -293,7 +292,7 @@ void PanelManager::RemoveWidget(Widget *widget){
PanelPosition pos = this->GetParentPanel(widget);
if(panels_.contains(pos)){
panels_[pos]->RemoveWidget(widget);
pool_->Give(widget->metaObject()->className());
pool_->Give(widget->GetUniqueID());
}
}
......
......@@ -62,7 +62,7 @@ bool TabbedPanelBar::Restore(const QString& prefix)
}
void TabbedPanelBar::WidgetMoved(Widget* widget, int index){
QString class_name = widget->metaObject()->className();
QString class_name = widget->GetUniqueID();
if(tab_widget_->indexOf(widget)>=0){
tab_widget_->removeTab(tab_widget_->indexOf(widget));
}
......
......@@ -56,11 +56,26 @@ public:
QWidget* GetInternalWidget();
void SetInternalWidget(QWidget* widget);
const QString& GetUniqueID() const
{
if (unique_id_.size()==0) {
unique_id_=this->metaObject()->className();
}
return unique_id_;
}
void SetUniqueID(const QString& id)
{
unique_id_=id;
}
virtual bool Restore(const QString& prefix)=0;
virtual bool Save(const QString& prefix)=0;
private:
mutable QString unique_id_;
QWidget* internal_;
bool destroy_on_close_;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment