21 #include <QWidgetAction> 23 #include "boost/bind.hpp" 33 BaseWidget(parent,
"BrowserWidget",
"Browser"),
37 mOptions =
profile()->getXmlSettings().descend(this->objectName());
41 void BrowserWidget::createGUI()
43 QVBoxLayout* layout =
new QVBoxLayout(
this);
45 layout->setSpacing(0);
57 connect(
mTreeView.data(), &QTreeView::collapsed,
this, &BrowserWidget::onNodeCollapsed);
58 connect(
mTreeView.data(), &QTreeView::expanded,
this, &BrowserWidget::onNodeExpanded);
63 layout->addWidget(mPopupWidget);
64 mPopupWidget->
setPopupVisible(this->getShowToolbarOption().readValue(QString::number(
false)).toInt());
67 mPropertiesWidget->setWidgetDeleteOld(
new QLabel(
"no\nproperties\nselected"));
70 layout->addWidget(mSplitter, 1);
74 this->createButtonWidget(mPopupWidget->
getToolbar());
77 void BrowserWidget::onNodeCollapsed(
const QModelIndex & index)
82 void BrowserWidget::onNodeExpanded(
const QModelIndex & index)
85 if (!mExpanded.contains(uid))
86 mExpanded.push_back(uid);
89 void BrowserWidget::onPopup()
108 void BrowserWidget::updateNodeName()
112 if (mName->actions().empty())
113 mName->addAction(node->getIcon(), QLineEdit::LeadingPosition);
115 mName->actions().front()->setIcon(node->getIcon());
118 mName->setText(node->getName());
121 int height = mName->height();
123 QFontMetrics fm(QFont(
"", 0));
124 mName->setFixedSize(fm.width(mName->text())+height*2, height);
130 void BrowserWidget::createButtonWidget(QWidget* widget)
132 QHBoxLayout* buttonLayout =
new QHBoxLayout(widget);
133 buttonLayout->setMargin(0);
134 buttonLayout->setSpacing(0);
138 visibility->
setIcon(QIcon(
":/icons/open_icon_library/arrange_vertical.png"));
139 buttonLayout->addWidget(visibility);
143 buttonLayout->addSpacing(8);
144 buttonLayout->addWidget(mode);
145 buttonLayout->setStretch(buttonLayout->count()-1, 0);
149 columns->
setIcon(QIcon(
":/icons/open_icon_library/arrange_horizontal.png"));
150 buttonLayout->addWidget(columns);
152 buttonLayout->addSpacing(8);
155 buttonLayout->addStretch(1);
159 buttonLayout->addWidget(mRemoveButton);
161 mName =
new QLineEdit;
162 mName->setReadOnly(
true);
163 buttonLayout->addWidget(mName);
168 buttonLayout->addWidget(button);
172 buttonLayout->addWidget(button);
180 void BrowserWidget::expandDefault(QModelIndex index)
183 if (!node->isDefaultExpanded())
189 for (
int r=0; r<rc; ++r)
192 this->expandDefault(child);
196 void BrowserWidget::expandRestore(QModelIndex index)
199 if (index.isValid() && !mExpanded.contains(node->getUid()))
206 for (
int r=0; r<rc; ++r)
209 this->expandRestore(child);
213 bool BrowserWidget::setCurrentNode(QString uid, QModelIndex index)
218 if (node && (node->getUid()==uid))
227 mTreeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
233 for (
int r=0; r<rc; ++r)
236 if (this->setCurrentNode(uid, child))
246 if (mExpanded.empty())
248 this->expandDefault(QModelIndex());
257 this->expandRestore(QModelIndex());
261 this->setCurrentNode(mActiveNodeUid, QModelIndex());
266 void BrowserWidget::onLoaded()
272 void BrowserWidget::onCurrentItemChanged()
278 if (node->getUid() == mActiveNodeUid)
280 if (node->getUid() ==
mModel->
repo()->getTopNode()->getUid())
283 mRemoveButton->setEnabled(node && node->isRemovable());
284 this->updateNodeName();
288 mActiveNodeUid = node->getUid();
290 boost::shared_ptr<QWidget> widget = node->createPropertiesWidget();
291 mPropertiesWidget->setWidget(widget);
298 void BrowserWidget::eraseCurrentNode()
void currentItemChanged()
boost::shared_ptr< TreeNode > TreeNodePtr
cxResource_EXPORT ProfilePtr profile()
boost::shared_ptr< class VisServices > VisServicesPtr
TreeNodePtr getCurrentItem()
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
void addLeftWidget(QWidget *widget, QString name)
QDomElement getElement()
return the current element
Helper class for storing one string value in an xml document.
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
void writeValue(const QString &val)
void setSelectionModel(QItemSelectionModel *selectionModel)
TreeNodePtr getNodeFromIndex(const QModelIndex &index)
StringListPropertyPtr getShowColumnsProperty()
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
void addRightWidget(QWidget *widget, QString name)
QAction * getMoveLeftAction()
QAction * getMoveRightAction()
XmlOptionFile descend(QString element) const
step one level down in the xml tree
Namespace for all CustusX production code.