Salome HOME
Porting on Qt5
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 16 Dec 2016 16:05:58 +0000 (19:05 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 16 Dec 2016 16:05:58 +0000 (19:05 +0300)
src/XGUI/XGUI_DataModel.cpp
src/XGUI/XGUI_ObjectsBrowser.cpp
src/XGUI/XGUI_ObjectsBrowser.h

index 06dc948949f04930480947533fdf55602f57dc4f..0353bf0b394c2e1da1346eb628994e9a47a4dbd8 100644 (file)
@@ -119,7 +119,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
           } else {
             int aFolderId = myXMLReader->rootFolderId(aObjType);
             if (aFolderId != -1) {
-              insertRow(aRow, createIndex(aFolderId, 0, -1));
+              insertRow(aRow, createIndex(aFolderId, 0, Q_NULLPTR));
             }
           }
         }
@@ -190,7 +190,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
           // Process root sub-folder
           int aFolderId = myXMLReader->rootFolderId(aGroup);
           if (aFolderId != -1) {
-            QModelIndex aFolderIndex = createIndex(aFolderId, 0, -1);
+            QModelIndex aFolderIndex = createIndex(aFolderId, 0, Q_NULLPTR);
             removeRow(aRow, aFolderIndex);
             //rebuildBranch(0, aRow);
           }
@@ -274,7 +274,7 @@ void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMess
         if (aGroup == myXMLReader->rootType()) // Update objects under root
           aStartId = foldersCount();
         else // Update objects in folder under root
-          aParent = createIndex(folderId(aGroup), 0, -1);
+          aParent = createIndex(folderId(aGroup), 0, Q_NULLPTR);
       } else {
         // Update a sub-document
         if (aGroup == myXMLReader->subType()) {
@@ -320,7 +320,7 @@ void XGUI_DataModel::rebuildDataTree()
 //******************************************************
 ObjectPtr XGUI_DataModel::object(const QModelIndex& theIndex) const
 {
-  if (theIndex.internalId() < 0) // this is a folder
+  if (theIndex.internalId() == 0) // this is a folder
     return ObjectPtr();
   ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
   if (getSubDocument(aObj)) // the selected index is a folder of sub-document
@@ -393,8 +393,8 @@ QVariant XGUI_DataModel::data(const QModelIndex& theIndex, int theRole) const
   if (theIndex.column() == 1)
     return QVariant();
 
-  int aParentId = theIndex.internalId();
-  if (aParentId == -1) { // root folders
+  quintptr aParentId = theIndex.internalId();
+  if (aParentId == 0) { // root folders
     switch (theRole) {
       case Qt::DisplayRole:
         return QString(myXMLReader->rootFolderName(theIndexRow).c_str()) +
@@ -491,8 +491,8 @@ int XGUI_DataModel::rowCount(const QModelIndex& theParent) const
     return aNbFolders + aNbItems;
   }
 
-  int aId = theParent.internalId();
-  if (aId == -1) {
+  quintptr aId = theParent.internalId();
+  if (aId == 0) {
     // this is a folder under root
     int aParentPos = theParent.row();
     std::string aType = myXMLReader->rootFolderType(aParentPos);
@@ -556,7 +556,7 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex &
 
   if (!theParent.isValid()) {
     if (theRow < aNbFolders) // Return first level folder index
-      return createIndex(theRow, theColumn, -1);
+      return createIndex(theRow, theColumn, Q_NULLPTR);
     else { // return object under root index
       std::string aType = myXMLReader->rootType();
       int aObjId = theRow - aNbFolders;
@@ -566,9 +566,9 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex &
       }
     }
   } else {
-    int aId = theParent.internalId();
+    quintptr aId = theParent.internalId();
     int aParentPos = theParent.row();
-    if (aId == -1) { // return object index inside of first level of folders
+    if (aId == 0) { // return object index inside of first level of folders
       std::string aType = myXMLReader->rootFolderType(aParentPos);
       if (theRow < aRootDoc->size(aType)) {
         ObjectPtr aObj = aRootDoc->object(aType, theRow);
@@ -637,8 +637,8 @@ QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const
   if (theIndex == MYLastDeleted)
     return QModelIndex();
 
-  int aId = theIndex.internalId();
-  if (aId != -1) { // The object is not a root folder
+  quintptr aId = theIndex.internalId();
+  if (aId != 0) { // The object is not a root folder
     ModelAPI_Document* aDoc = getSubDocument(theIndex.internalPointer());
     if (aDoc) {
       // It is a folder of sub-document
@@ -678,7 +678,7 @@ QModelIndex XGUI_DataModel::parent(const QModelIndex& theIndex) const
         // return first level of folder index
         int aFolderId = myXMLReader->rootFolderId(aType);
         // Items in a one row must have the same parent
-        return createIndex(aFolderId, 0, -1);
+        return createIndex(aFolderId, 0, Q_NULLPTR);
       }
     } else {
       if (aType == myXMLReader->subType())
@@ -720,7 +720,7 @@ bool XGUI_DataModel::removeRows(int theRow, int theCount, const QModelIndex& the
 //******************************************************
 Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const
 {
-  qint64 aIt = theIndex.internalId();
+  quintptr aIt = theIndex.internalId();
   ModelAPI_Object* aObj = 0;
   ModelAPI_Document* aDoc = 0;
   SessionPtr aSession = ModelAPI_Session::get();
@@ -731,7 +731,7 @@ Qt::ItemFlags XGUI_DataModel::flags(const QModelIndex& theIndex) const
   Qt::ItemFlags aEditingFlag = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
 
 
-  if (aIt == -1) {
+  if (aIt == 0) {
     // Folders under root
     DocumentPtr aRootDoc = aSession->moduleDocument();
     if (aRootDoc != aActiveDoc)
index 173e4e8fb72c4f7c0f7ed7302bf3e71da1e26d74..5fb0e655b623e63ed9512a24b8f503e18616b252 100644 (file)
@@ -70,14 +70,14 @@ private:
 XGUI_DataTree::XGUI_DataTree(QWidget* theParent)
     : QTreeView(theParent)
 {
-#ifdef WIN32
-#ifdef HAVE_SALOME
-  setStyle(new QCommonStyle());
-#else
-  myStyle = new XGUI_TreeViewStyle();
-  setStyle(myStyle);
-#endif
-#endif
+//#ifdef WIN32
+//#ifdef HAVE_SALOME
+//  setStyle(new QCommonStyle());
+//#else
+//  myStyle = new XGUI_TreeViewStyle();
+//  setStyle(myStyle);
+//#endif
+//#endif
 
   setHeaderHidden(true);
   setEditTriggers(QAbstractItemView::NoEditTriggers);
@@ -169,10 +169,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;
 
@@ -189,38 +189,38 @@ void XGUI_DataTree::onDoubleClick(const QModelIndex& theIndex)
   }
 }
 
-#if (!defined HAVE_SALOME) && (defined WIN32)
-void XGUI_DataTree::drawRow(QPainter* thePainter,
-                            const QStyleOptionViewItem& theOptions,
-                            const QModelIndex& theIndex) const
-{
-  QStyleOptionViewItemV4 aOptions = theOptions;
-  myStyle->setIndex(theIndex);
-  QTreeView::drawRow(thePainter, aOptions, theIndex);
-}
-
-//********************************************************************
-//********************************************************************
-//********************************************************************
-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);
-    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;
-      QCommonStyle/*QWindowsVistaStyle*/::drawPrimitive(theElement, aOpt, thePainter, theWidget);
-    }
-  }
-  QCommonStyle/*QWindowsVistaStyle*/::drawPrimitive(theElement, theOption, thePainter, theWidget);
-}
-#endif
+//#if (!defined HAVE_SALOME) && (defined WIN32)
+//void XGUI_DataTree::drawRow(QPainter* thePainter,
+//                            const QStyleOptionViewItem& theOptions,
+//                            const QModelIndex& theIndex) const
+//{
+//  QStyleOptionViewItemV4 aOptions = theOptions;
+//  myStyle->setIndex(theIndex);
+//  QTreeView::drawRow(thePainter, aOptions, theIndex);
+//}
+//
+////********************************************************************
+////********************************************************************
+////********************************************************************
+//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);
+//    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;
+//      QCommonStyle::drawPrimitive(theElement, aOpt, thePainter, theWidget);
+//    }
+//  }
+//  QCommonStyle::drawPrimitive(theElement, theOption, thePainter, theWidget);
+//}
+//#endif
 
 
 //********************************************************************
@@ -245,9 +245,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 + " }";
@@ -255,9 +256,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() + "}";
index f1c51e964371e39176d20c066836f98e48b04e70..28a01ca2fe3c96c0545311109f80710edc4df3cd 100644 (file)
@@ -62,30 +62,28 @@ private:
 };
 
 
-#if (!defined HAVE_SALOME) && (defined WIN32)
-// PORTING_TO_SALOME_8
-//#include <QWindowsVistaStyle>
-#include <QCommonStyle>
-  /**
-* \ingroup GUI
-* Implementation of XGUI_DataTree custom style
-*/
-class XGUI_TreeViewStyle : public QCommonStyle // PORTING_TO_SALOME_8 QWindowsVistaStyle
-{
-  Q_OBJECT
-public:
-  XGUI_TreeViewStyle() : QCommonStyle/*QWindowsVistaStyle*/() {}
-
-  void drawPrimitive(PrimitiveElement theElement, const QStyleOption* theOption,
-                     QPainter* thePainter, const QWidget* theWidget = 0) const;
-
-  void setIndex(const QModelIndex& theIndex) { myIndex = theIndex; }
-  QModelIndex index() const { return myIndex; }
-
-private:
-  QModelIndex myIndex;
-};
-#endif
+//#if (!defined HAVE_SALOME) && (defined WIN32)
+//#include <QCommonStyle>
+//  /**
+//* \ingroup GUI
+//* Implementation of XGUI_DataTree custom style
+//*/
+//class XGUI_TreeViewStyle : public QCommonStyle // PORTING_TO_SALOME_8 QWindowsVistaStyle
+//{
+//  Q_OBJECT
+//public:
+//  XGUI_TreeViewStyle() : QCommonStyle/*QWindowsVistaStyle*/() {}
+//
+//  void drawPrimitive(PrimitiveElement theElement, const QStyleOption* theOption,
+//                     QPainter* thePainter, const QWidget* theWidget = 0) const;
+//
+//  void setIndex(const QModelIndex& theIndex) { myIndex = theIndex; }
+//  QModelIndex index() const { return myIndex; }
+//
+//private:
+//  QModelIndex myIndex;
+//};
+//#endif
 
 /**
 * \ingroup GUI
@@ -126,13 +124,13 @@ public slots:
    /// Redefinition of virtual method
   virtual void resizeEvent(QResizeEvent* theEvent);
 
-#if (!defined HAVE_SALOME) && (defined WIN32)
-  virtual void drawRow(QPainter* thePainter,
-                        const QStyleOptionViewItem& theOptions,
-                        const QModelIndex& theIndex) const;
-private:
-  XGUI_TreeViewStyle* myStyle;
-#endif
+//#if (!defined HAVE_SALOME) && (defined WIN32)
+//  virtual void drawRow(QPainter* thePainter,
+//                        const QStyleOptionViewItem& theOptions,
+//                        const QModelIndex& theIndex) const;
+//private:
+//  XGUI_TreeViewStyle* myStyle;
+//#endif
 };
 
 /**\class XGUI_ObjectsBrowser