X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_ObjectsBrowser.cpp;h=983f4c37ea1d035a2624fd5e982d4a9ca27883a2;hb=00a3c1675ca0ead43040cafa3a99f984e1d8177b;hp=15fba977ca2d02a3318d9a14d981641015534e74;hpb=a8cfbfb436c27ff96edd5c808e9a452c35cef207;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ObjectsBrowser.cpp b/src/XGUI/XGUI_ObjectsBrowser.cpp index 15fba977c..983f4c37e 100644 --- a/src/XGUI/XGUI_ObjectsBrowser.cpp +++ b/src/XGUI/XGUI_ObjectsBrowser.cpp @@ -1,4 +1,22 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// #include "XGUI_ObjectsBrowser.h" #include "XGUI_Tools.h" @@ -11,6 +29,8 @@ #include +#include + #include #include #include @@ -20,14 +40,12 @@ #include #include -#ifdef WIN32 -#ifdef HAVE_SALOME -#include -#endif +#ifdef DEBUG_INDXES +#include #endif - /// Width of second column (minimum acceptable = 27) +#define FIRST_COL_WIDTH 20 #define SECOND_COL_WIDTH 30 @@ -40,7 +58,8 @@ class XGUI_TreeViewItemDelegate: public QStyledItemDelegate 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 @@ -67,23 +86,15 @@ private: XGUI_DataTree::XGUI_DataTree(QWidget* theParent) : QTreeView(theParent) { -#ifdef WIN32 -#ifdef HAVE_SALOME - setStyle(new QWindowsStyle()); -#else - myStyle = new XGUI_TreeViewStyle(); - setStyle(myStyle); -#endif -#endif - setHeaderHidden(true); + setTreePosition(1); setEditTriggers(QAbstractItemView::NoEditTriggers); setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::ExtendedSelection); - setItemDelegateForColumn(0, new XGUI_TreeViewItemDelegate(this)); + setItemDelegateForColumn(1, new XGUI_TreeViewItemDelegate(this)); - connect(this, SIGNAL(doubleClicked(const QModelIndex&)), + connect(this, SIGNAL(doubleClicked(const QModelIndex&)), SLOT(onDoubleClick(const QModelIndex&))); } @@ -105,8 +116,8 @@ void XGUI_DataTree::commitData(QWidget* theEditor) { 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(theEditor); if (aEditor) { @@ -126,7 +137,7 @@ void XGUI_DataTree::commitData(QWidget* theEditor) aEntrance = 0; } -void XGUI_DataTree::clear() +void XGUI_DataTree::clear() { dataModel()->clear(); reset(); @@ -134,18 +145,49 @@ void XGUI_DataTree::clear() void XGUI_DataTree::resizeEvent(QResizeEvent* theEvent) { + QTreeView::resizeEvent(theEvent); QSize aSize = theEvent->size(); if (aSize.isValid()) { - setColumnWidth(0, aSize.width() - SECOND_COL_WIDTH); - setColumnWidth(1, SECOND_COL_WIDTH); + setColumnWidth(0, FIRST_COL_WIDTH); + setColumnWidth(1, aSize.width() - SECOND_COL_WIDTH - FIRST_COL_WIDTH - 10); + setColumnWidth(2, SECOND_COL_WIDTH); } - QTreeView::resizeEvent(theEvent); } -void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex) +#ifdef DEBUG_INDXES +void XGUI_DataTree::mousePressEvent(QMouseEvent* theEvent) +{ + QTreeView::mousePressEvent(theEvent); + if (theEvent->button() != Qt::MidButton) + return; + QModelIndex aInd = indexAt(theEvent->pos()); + QString aTxt = + QString("r=%1 c=%2 p=%3").arg(aInd.row()).arg(aInd.column()).arg((long)aInd.internalPointer()); + + QModelIndex aPar = aInd.parent(); + QString aTxt1 = + QString("r=%1 c=%2 p=%3").arg(aPar.row()).arg(aPar.column()).arg((long)aPar.internalPointer()); + QToolTip::showText(theEvent->globalPos(), aTxt + '\n' + aTxt1); +} +#endif + +void XGUI_DataTree::mouseReleaseEvent(QMouseEvent* theEvent) { - if (theIndex.column() != 1) + QTreeView::mouseReleaseEvent(theEvent); +#ifdef DEBUG_INDXES + if (theEvent->button() != Qt::MidButton) return; + QToolTip::hideText(); +#endif + if (theEvent->button() == Qt::LeftButton) { + QModelIndex aInd = indexAt(theEvent->pos()); + if (aInd.column() == 0) + processEyeClick(aInd); + } +} + +void XGUI_DataTree::processHistoryChange(const QModelIndex& theIndex) +{ SessionPtr aMgr = ModelAPI_Session::get(); // When operation is opened then we can not change history if (aMgr->isOperation()) @@ -156,7 +198,7 @@ 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) @@ -166,10 +208,10 @@ void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex) aMgr->finishOperation(); } else { // Ignore clicks on folders outside current document - if ((theIndex.internalId() == -1) && (aDoc != aMgr->moduleDocument())) + if ((theIndex.internalId() == 0) && (aDoc != aMgr->moduleDocument())) // Clicked folder under root but active document is another return; - if ((theIndex.internalId() != -1) && (aDoc.get() != theIndex.internalPointer())) + if ((theIndex.internalId() != 0) && (aDoc.get() != theIndex.internalPointer())) // Cliced not on active document folder return; @@ -183,49 +225,52 @@ void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex) for (int i = 0; i < aSize; i++) { update(aModel->index(i, 0, aParent)); update(aModel->index(i, 1, aParent)); + update(aModel->index(i, 2, aParent)); } } -#if (!defined HAVE_SALOME) && (defined WIN32) -void XGUI_DataTree::drawRow(QPainter* thePainter, - const QStyleOptionViewItem& theOptions, - const QModelIndex& theIndex) const +void XGUI_DataTree::processEyeClick(const QModelIndex& theIndex) { - QStyleOptionViewItemV4 aOptions = theOptions; - myStyle->setIndex(theIndex); - QTreeView::drawRow(thePainter, aOptions, theIndex); + XGUI_DataModel* aModel = dataModel(); + ObjectPtr aObj = aModel->object(theIndex); + if (aObj.get()) { + ResultPtr aResObj = std::dynamic_pointer_cast(aObj); + XGUI_ObjectsBrowser* aObjBrowser = qobject_cast(parent()); + if (aResObj.get()) { + std::set anObjects; + anObjects.insert(aResObj); + if (aObjBrowser && !aResObj->isDisplayed() && + !aObjBrowser->workshop()->prepareForDisplay(anObjects)) + return; + aResObj->setDisplayed(!aResObj->isDisplayed()); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + update(theIndex); + } + // Update list of selected objects because this event happens after + // selection event in object browser + if (aObjBrowser) { + aObjBrowser->onSelectionChanged(); + } + } } -//******************************************************************** -//******************************************************************** -//******************************************************************** -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(theOption); - if (myIndex.isValid() && ((myIndex.flags() & Qt::ItemIsSelectable) == 0)) { - QStyle::State aState = aOptions->state; - if ((aState & QStyle::State_MouseOver) != 0) - aState &= ~QStyle::State_MouseOver; - QStyleOptionViewItemV4* aOpt = (QStyleOptionViewItemV4*) aOptions; - aOpt->state = aState; - QWindowsVistaStyle::drawPrimitive(theElement, aOpt, thePainter, theWidget); - } +void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex) +{ + switch (theIndex.column()) { + case 2: + processHistoryChange(theIndex); + break; } - QWindowsVistaStyle::drawPrimitive(theElement, theOption, thePainter, theWidget); } -#endif //******************************************************************** //******************************************************************** //******************************************************************** XGUI_ActiveDocLbl::XGUI_ActiveDocLbl(const QString& theText, QWidget* theParent ) - : QLabel(theText, theParent), - myPreSelectionStyle(""), - myNeutralStyle(""), + : QLabel(theText, theParent), + myPreSelectionStyle(""), + myNeutralStyle(""), mySelectionStyle(""), myIsSelected(false) { @@ -241,8 +286,10 @@ void XGUI_ActiveDocLbl::setTreeView(QTreeView* theView) 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 += "border: 1px solid lightblue; border-radius: 2px }"; + myPreSelectionStyle += 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(); myNeutralStyle = "QLabel { border: 1px solid " + aName + " }"; @@ -250,9 +297,11 @@ void XGUI_ActiveDocLbl::setTreeView(QTreeView* theView) #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 += "border: 1px solid rgb(132, 172, 221); border-radius: 2px }"; + mySelectionStyle += "rgb(205, 232, 255); "; + //mySelectionStyle += "qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgb(236, 245, 255)"; + //mySelectionStyle += ", stop:1 rgb(208, 229, 255));"; + //mySelectionStyle += "border: 1px solid rgb(132, 172, 221); border-radius: 2px }"; + mySelectionStyle += "border: 1px solid rgb(153, 209, 255) }"; #else mySelectionStyle = "QLabel {background-color: " + aHighlight.name(); mySelectionStyle += "; color : " + aHighlightText.name() + "}"; @@ -294,7 +343,7 @@ void XGUI_ActiveDocLbl::mouseReleaseEvent( QMouseEvent* e) 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); @@ -313,8 +362,8 @@ void XGUI_ActiveDocLbl::unselect() //******************************************************************** //******************************************************************** //******************************************************************** -XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) - : QWidget(theParent), myDocModel(0) +XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent, XGUI_Workshop* theWorkshop) + : QWidget(theParent), myDocModel(0), myWorkshop(theWorkshop) { QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); @@ -332,7 +381,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent) 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); @@ -373,8 +422,8 @@ XGUI_ObjectsBrowser::~XGUI_ObjectsBrowser() } void XGUI_ObjectsBrowser::setXMLReader(Config_DataModelReader* theReader) -{ - myDocModel->setXMLReader(theReader); +{ + myDocModel->setXMLReader(theReader); myTreeView->setModel(myDocModel); // It has to be done after setting of model @@ -492,17 +541,25 @@ void XGUI_ObjectsBrowser::setObjectsSelected(const QObjectPtrList& theObjects) } //*************************************************** -void XGUI_ObjectsBrowser::clearContent() -{ - myTreeView->clear(); +void XGUI_ObjectsBrowser::clearContent() +{ + myTreeView->clear(); } +//*************************************************** void XGUI_ObjectsBrowser::onSelectionChanged(const QItemSelection& theSelected, const QItemSelection& theDeselected) +{ + onSelectionChanged(); +} + +//*************************************************** +void XGUI_ObjectsBrowser::onSelectionChanged() { emit selectionChanged(); } +//*************************************************** QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) const { QObjectPtrList aList; @@ -510,7 +567,7 @@ QObjectPtrList XGUI_ObjectsBrowser::selectedObjects(QModelIndexList* theIndexes) XGUI_DataModel* aModel = dataModel(); QModelIndexList::const_iterator aIt; for (aIt = aIndexes.constBegin(); aIt != aIndexes.constEnd(); ++aIt) { - if ((*aIt).column() == 0) { + if ((*aIt).column() == 1) { ObjectPtr aObject = aModel->object(*aIt); if (aObject) { aList.append(aObject); @@ -533,3 +590,46 @@ void XGUI_ObjectsBrowser::onAfterModelReset() myTreeView->setExpanded(aIndex, true); } } + +std::list XGUI_ObjectsBrowser::getStateForDoc(DocumentPtr theDoc) const +{ + std::list aStates; + XGUI_DataModel* aModel = dataModel(); + QModelIndex aRootIdx = aModel->documentRootIndex(theDoc); + int aNbChild = aModel->rowCount(aRootIdx); + for (int i = 0; i < aNbChild; i++) { + QModelIndex aIdx = aModel->index(i, 1, aRootIdx); + aStates.push_back(myTreeView->isExpanded(aIdx)); + } + return aStates; +} + +void XGUI_ObjectsBrowser::setStateForDoc(DocumentPtr theDoc, const std::list& theStates) +{ + if (theStates.size() == 0) + return; + XGUI_DataModel* aModel = dataModel(); + QModelIndex aRootIdx = aModel->documentRootIndex(theDoc); + int aNbChild = aModel->rowCount(aRootIdx); + + std::list::const_iterator aIt; + int i = 0; + for (aIt = theStates.cbegin(); aIt != theStates.cend(); aIt++, i++) { + if (i >= aNbChild ) + break; + QModelIndex aIdx = aModel->index(i, 0, aRootIdx); + myTreeView->setExpanded(aIdx, (*aIt)); + } +} + +void XGUI_ObjectsBrowser::updateAllIndexes(int theColumn, const QModelIndex& theParent) +{ + int aNb = myDocModel->rowCount(theParent); + for (int i = 0; i < aNb; i++) { + QModelIndex aIdx = myDocModel->index(i, theColumn, theParent); + if (aIdx.isValid()) { + myTreeView->update(aIdx); + updateAllIndexes(theColumn, aIdx); + } + } +}