#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Tools.h>
-#include <Events_Error.h>
#include <ModuleBase_Tools.h>
public:
/// Constructor
/// \param theParent a parent of the delegate
- XGUI_TreeViewItemDelegate(XGUI_DataTree* theParent):QStyledItemDelegate(theParent), myTreedView(theParent) {}
+ XGUI_TreeViewItemDelegate(XGUI_DataTree* theParent):QStyledItemDelegate(theParent),
+ myTreedView(theParent) {}
/// Set data for item editor (name of the item)
/// \param editor a widget of editor
setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this));
- connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
+ connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
SLOT(onDoubleClick(const QModelIndex&)));
}
{
static int aEntrance = 0;
if (aEntrance == 0) {
- // We have to check number of enter and exit of this function because it can be called recursively by Qt
- // in order to avoid double modifying of a data
+ // We have to check number of enter and exit of this function because it can be called
+ // recursively by Qt in order to avoid double modifying of a data
aEntrance = 1;
QLineEdit* aEditor = dynamic_cast<QLineEdit*>(theEditor);
if (aEditor) {
aEntrance = 0;
}
-void XGUI_DataTree::clear()
+void XGUI_DataTree::clear()
{
dataModel()->clear();
reset();
void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent)
{
+ QTreeView::resizeEvent(theEvent);
QSize aSize = theEvent->size();
if (aSize.isValid()) {
- setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH);
+ setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH - 6);
setColumnWidth(1, SECOND_COL_WIDTH);
}
- QTreeView::resizeEvent(theEvent);
}
void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
ObjectPtr aObj = aModel->object(theIndex);
DocumentPtr aDoc = aMgr->activeDocument();
-
+
std::string aOpName = tr("History change").toStdString();
if (aObj.get()) {
if (aObj->document() != aDoc)
//********************************************************************
//********************************************************************
//********************************************************************
-void XGUI_TreeViewStyle::drawPrimitive(PrimitiveElement theElement,
+void XGUI_TreeViewStyle::drawPrimitive(PrimitiveElement theElement,
const QStyleOption* theOption,
QPainter* thePainter, const QWidget* theWidget) const
{
if ((theElement == QStyle::PE_PanelItemViewRow) || (theElement == QStyle::PE_PanelItemViewItem)) {
- const QStyleOptionViewItemV4* aOptions = qstyleoption_cast<const QStyleOptionViewItemV4 *>(theOption);
+ const QStyleOptionViewItemV4* aOptions =
+ qstyleoption_cast<const QStyleOptionViewItemV4 *>(theOption);
if (myIndex.isValid() && ((myIndex.flags() & Qt::ItemIsSelectable) == 0)) {
QStyle::State aState = aOptions->state;
if ((aState & QStyle::State_MouseOver) != 0)
//********************************************************************
//********************************************************************
XGUI_ActiveDocLbl::XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent )
- : QLabel(theText, theParent),
- myPreSelectionStyle(""),
- myNeutralStyle(""),
+ : QLabel(theText, theParent),
+ myPreSelectionStyle(""),
+ myNeutralStyle(""),
mySelectionStyle(""),
myIsSelected(false)
{
QColor aHighlightText = aPalet.highlightedText().color();
myPreSelectionStyle = "QLabel {background-color: ";
- myPreSelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 white, stop:1 " + aHighlight.lighter(170).name() + ");";
+ myPreSelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 white, stop:1 " +
+ aHighlight.lighter(170).name() + ");";
myPreSelectionStyle += "border: 1px solid lightblue; border-radius: 2px }";
QString aName = aPalet.color(QPalette::Base).name();
#if (!defined HAVE_SALOME) && (defined WIN32)
mySelectionStyle = "QLabel {background-color: ";
mySelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(236, 245, 255)";
- mySelectionStyle += ", stop:1 rgb(208, 229, 255));";
+ mySelectionStyle += ", stop:1 rgb(208, 229, 255));";
mySelectionStyle += "border: 1px solid rgb(132, 172, 221); border-radius: 2px }";
#else
mySelectionStyle = "QLabel {background-color: " + aHighlight.name();
MYClearing = true;
myIsSelected = true;
setStyleSheet(mySelectionStyle);
- // We can not block signals because on
+ // We can not block signals because on
// clear selection the View state will not be updated
myTreeView->clearSelection();
QLabel::mouseReleaseEvent(e);
aLbl->setPixmap(QPixmap(":pictures/assembly.png"));
aLbl->setMargin(2);
// Do not paint background of the label (in order to show icon)
- aLbl->setAutoFillBackground(false);
+ aLbl->setAutoFillBackground(false);
aLabelLay->addWidget(aLbl);
aLabelWgt->setPalette(aPalet);
myDocModel = new XGUI_DataModel(this);
- myTreeView->setModel(myDocModel);
-
- // It has to be done after setting of model
- myActiveDocLbl->setTreeView(myTreeView);
-
- QItemSelectionModel* aSelMod = myTreeView->selectionModel();
- connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
- this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+ connect(myDocModel, SIGNAL(modelAboutToBeReset()), SLOT(onBeforeReset()));
+ connect(myDocModel, SIGNAL(treeRebuilt()), SLOT(onAfterModelReset()));
connect(myTreeView, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
SLOT(onContextMenuRequested(QContextMenuEvent*)));
{
}
+void XGUI_ObjectsBrowser::setXMLReader(Config_DataModelReader* theReader)
+{
+ myDocModel->setXMLReader(theReader);
+ myTreeView->setModel(myDocModel);
+
+ // It has to be done after setting of model
+ myActiveDocLbl->setTreeView(myTreeView);
+
+ QItemSelectionModel* aSelMod = myTreeView->selectionModel();
+ connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+ this, SLOT(onSelectionChanged(const QItemSelection&, const QItemSelection&)));
+}
//***************************************************
void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
{
QObjectPtrList aSelectedData = selectedObjects();
if (aSelectedData.size() > 0) {
- ObjectPtr aFeature = aSelectedData.first();
- if (aFeature) { // Selection happens in TreeView
- QObjectPtrList aList;
- aList.append(aFeature);
- // check whether the object can be deleted. There should not be parts which are not loaded
- if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aList))
+ ObjectPtr anObject = aSelectedData.first();
+ if (anObject.get()) { // Selection happens in TreeView
+ // check whether the object can be renamed. There should not be parts which are not loaded
+ std::set<FeaturePtr> aFeatures;
+ aFeatures.insert(ModelAPI_Feature::feature(anObject));
+ if (!XGUI_Tools::canRemoveOrRename((QWidget*)parent(), aFeatures))
return;
// Find index which corresponds the feature
QModelIndex aIndex;
foreach(QModelIndex aIdx, selectedIndexes()) {
ObjectPtr aFea = dataModel()->object(aIdx);
- if (dataModel()->object(aIdx)->isSame(aFeature)) {
+ if (dataModel()->object(aIdx)->isSame(anObject)) {
aIndex = aIdx;
break;
}
{
QModelIndexList aIndexes;
QModelIndex aIndex;
- for (int i = 0; i < myDocModel->rowCount(); i++) {
+ for (int i = 0; i < myDocModel->rowCount(theParent); i++) {
aIndex = myDocModel->index(i, 0, theParent);
if (myDocModel->hasChildren(aIndex)) {
if (myTreeView->isExpanded(aIndex)) {
//***************************************************
void XGUI_ObjectsBrowser::rebuildDataTree()
{
- QModelIndexList aIndexList = expandedItems();
myDocModel->rebuildDataTree();
- foreach(QModelIndex aIndex, aIndexList) {
- myTreeView->setExpanded(aIndex, true);
- }
update();
}
}
//***************************************************
-void XGUI_ObjectsBrowser::clearContent()
-{
- myTreeView->clear();
+void XGUI_ObjectsBrowser::clearContent()
+{
+ myTreeView->clear();
}
void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected,
}
}
return aList;
-}
\ No newline at end of file
+}
+
+void XGUI_ObjectsBrowser::onBeforeReset()
+{
+ myExpandedItems = expandedItems();
+}
+
+void XGUI_ObjectsBrowser::onAfterModelReset()
+{
+ foreach(QModelIndex aIndex, myExpandedItems) {
+ myTreeView->setExpanded(aIndex, true);
+ }
+}