42 #include <QWidgetAction>
44 #include "boost/bind.hpp"
54 BaseWidget(parent,
"BrowserWidget",
"Browser"),
58 mOptions =
profile()->getXmlSettings().descend(this->objectName());
62 void BrowserWidget::createGUI()
64 QVBoxLayout* layout =
new QVBoxLayout(
this);
66 layout->setSpacing(0);
78 connect(
mTreeView.data(), &QTreeView::collapsed,
this, &BrowserWidget::onNodeCollapsed);
79 connect(
mTreeView.data(), &QTreeView::expanded,
this, &BrowserWidget::onNodeExpanded);
84 layout->addWidget(mPopupWidget);
85 mPopupWidget->
setPopupVisible(this->getShowToolbarOption().readValue(QString::number(
false)).toInt());
88 mPropertiesWidget->setWidget(
new QLabel(
"no\nproperties\nselected"));
91 layout->addWidget(mSplitter, 1);
95 this->createButtonWidget(mPopupWidget->
getToolbar());
98 void BrowserWidget::onNodeCollapsed(
const QModelIndex & index)
103 void BrowserWidget::onNodeExpanded(
const QModelIndex & index)
106 if (!mExpanded.contains(uid))
107 mExpanded.push_back(uid);
110 void BrowserWidget::onPopup()
129 void BrowserWidget::updateNodeName()
133 if (mName->actions().empty())
134 mName->addAction(node->getIcon(), QLineEdit::LeadingPosition);
136 mName->actions().front()->setIcon(node->getIcon());
139 mName->setText(node->getName());
142 int height = mName->height();
144 QFontMetrics fm(QFont(
"", 0));
145 mName->setFixedSize(fm.width(mName->text())+height*2, height);
151 void BrowserWidget::createButtonWidget(QWidget* widget)
153 QHBoxLayout* buttonLayout =
new QHBoxLayout(widget);
154 buttonLayout->setMargin(0);
155 buttonLayout->setSpacing(0);
157 StringListSelectWidget* visibility =
new StringListSelectWidget(
this,
mModel->
repo()->getVisibilityProperty());
158 visibility->showLabel(
false);
159 visibility->setIcon(QIcon(
":/icons/open_icon_library/arrange_vertical.png"));
160 buttonLayout->addWidget(visibility);
162 LabeledComboBoxWidget* mode =
new LabeledComboBoxWidget(
this,
mModel->
repo()->getModeProperty());
163 mode->showLabel(
false);
164 buttonLayout->addSpacing(8);
165 buttonLayout->addWidget(mode);
166 buttonLayout->setStretch(buttonLayout->count()-1, 0);
169 columns->showLabel(
false);
170 columns->setIcon(QIcon(
":/icons/open_icon_library/arrange_horizontal.png"));
171 buttonLayout->addWidget(columns);
173 buttonLayout->addSpacing(8);
176 buttonLayout->addStretch(1);
178 mRemoveButton =
new EraseDataToolButton(
this);
180 buttonLayout->addWidget(mRemoveButton);
182 mName =
new QLineEdit;
183 mName->setReadOnly(
true);
184 buttonLayout->addWidget(mName);
189 buttonLayout->addWidget(button);
193 buttonLayout->addWidget(button);
196 XmlOptionItem BrowserWidget::getShowToolbarOption()
198 return XmlOptionItem(
"show_toolbar", mOptions.
getElement());
201 void BrowserWidget::expandDefault(QModelIndex index)
204 if (!node->isDefaultExpanded())
210 for (
int r=0; r<rc; ++r)
213 this->expandDefault(child);
217 void BrowserWidget::expandRestore(QModelIndex index)
220 if (index.isValid() && !mExpanded.contains(node->getUid()))
227 for (
int r=0; r<rc; ++r)
230 this->expandRestore(child);
234 bool BrowserWidget::setCurrentNode(QString uid, QModelIndex index)
239 if (node && (node->getUid()==uid))
248 mTreeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
254 for (
int r=0; r<rc; ++r)
257 if (this->setCurrentNode(uid, child))
267 if (mExpanded.empty())
269 this->expandDefault(QModelIndex());
278 this->expandRestore(QModelIndex());
282 this->setCurrentNode(mActiveNodeUid, QModelIndex());
287 void BrowserWidget::onLoaded()
293 void BrowserWidget::onCurrentItemChanged()
299 if (node->getUid() == mActiveNodeUid)
301 if (node->getUid() ==
mModel->
repo()->getTopNode()->getUid())
304 mRemoveButton->setEnabled(node && node->isRemovable());
305 this->updateNodeName();
309 mActiveNodeUid = node->getUid();
311 QWidget* widget = node->createPropertiesWidget();
312 mPropertiesWidget->setWidget(widget);
319 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
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