#include <ModelAPI_Document.h>
#include <ModelAPI_Object.h>
+#include <ModuleBase_Tools.h>
+
#include <QLayout>
#include <QLabel>
#include <QLineEdit>
#include <QEvent>
#include <QMouseEvent>
#include <QAction>
+#include <QStyledItemDelegate>
+
+/**
+* \ingroup GUI
+* Tree item delegate for definition of data in column items editor
+*/
+class XGUI_TreeViewItemDelegate: public QStyledItemDelegate
+{
+public:
+ /// Constructor
+ /// \param theParent a parent of the delegate
+ XGUI_TreeViewItemDelegate(XGUI_DataTree* theParent):QStyledItemDelegate(theParent), myTreedView(theParent) {}
+
+ /// Set data for item editor (name of the item)
+ /// \param editor a widget of editor
+ /// \param index the tree item index
+ virtual void setEditorData ( QWidget* editor, const QModelIndex& index ) const
+ {
+ QLineEdit* aEditor = dynamic_cast<QLineEdit*>(editor);
+ if (aEditor) {
+ XGUI_DocumentDataModel* aModel = myTreedView->dataModel();
+ ObjectPtr aObj = aModel->object(index);
+ if (aObj.get() != NULL) {
+ aEditor->setText(aObj->data()->name().c_str());
+ return;
+ }
+ }
+ QStyledItemDelegate::setEditorData(editor, index);
+ }
+
+private:
+ XGUI_DataTree* myTreedView;
+};
+
XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
: QTreeView(theParent)
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::ExtendedSelection);
+ setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this));
+
connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
}
QString aRes = aEditor->text();
ObjectPtr aFeature = mySelectedData.first();
SessionPtr aMgr = ModelAPI_Session::get();
- aMgr->startOperation();
+ aMgr->startOperation("Rename");
aFeature->data()->setName(qPrintable(aRes));
aMgr->finishOperation();
}
: QWidget(theParent)
{
QVBoxLayout* aLayout = new QVBoxLayout(this);
- aLayout->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::zeroMargins(aLayout);
aLayout->setSpacing(0);
QFrame* aLabelWgt = new QFrame(this);
aLayout->addWidget(aLabelWgt);
QHBoxLayout* aLabelLay = new QHBoxLayout(aLabelWgt);
- aLabelLay->setContentsMargins(0, 0, 0, 0);
+ ModuleBase_Tools::zeroMargins(aLabelLay);
aLabelLay->setSpacing(0);
QLabel* aLbl = new QLabel(aLabelWgt);