f71019e20ffbfa2a0d491aa06a1be1cb63e10426
[occt.git] / samples / tools / TInspectorEXE / src / TInspectorEXE_OpenFileViewModel.hxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #ifndef TInspectorEXE_OpenFileViewModel_H
17 #define TInspectorEXE_OpenFileViewModel_H
18
19 #include <Standard_Macro.hxx>
20
21 #ifdef _MSC_VER
22 #pragma warning(disable : 4127) // conditional expression is constant
23 #endif
24 #include <QAbstractTableModel>
25 #include <QStringList>
26 #include <QItemDelegate>
27
28 class QObject;
29 class QPainter;
30
31 //! \class TInspectorEXE_OpenFileItemDelegate
32 //! Draws large(40x40) icons in cell. The icon background in colored in highlight when mouse is over button
33 class TInspectorEXE_OpenFileItemDelegate : public QItemDelegate
34 {
35
36 public:
37
38   //! Constructor
39   TInspectorEXE_OpenFileItemDelegate (QObject* theParent, const QColor& theHighlightColor)
40   : QItemDelegate (theParent), myColor(theHighlightColor) {}
41
42   //! Destructor
43   virtual ~TInspectorEXE_OpenFileItemDelegate() {}
44
45   //! Draw an icon in the cell
46   //! \param thePainter a painter
47   //! \param theOption a paint options
48   //! \param theIndex a view index
49   virtual void paint (QPainter* thePainter, const QStyleOptionViewItem& theOption,
50                       const QModelIndex& theIndex) const Standard_OVERRIDE;
51
52 private:
53
54   QColor myColor; //!< highlight color
55 };
56
57 //! \class TInspectorEXE_OpenFileViewModel
58 //! Table model that visualizes container of string values (file names)
59 //! Table orientation is horizontal, it has 1 row, number of columns equals to number of values
60 class TInspectorEXE_OpenFileViewModel : public QAbstractTableModel
61 {
62
63 public:
64
65   //! Constructor
66   TInspectorEXE_OpenFileViewModel (QObject* theParent = 0) : QAbstractTableModel (theParent) {}
67
68   //! Destructor
69   virtual ~TInspectorEXE_OpenFileViewModel() {}
70
71   //! Store values
72   //! \param theValues a container of values to fill model
73   void Init (const QStringList& theValues);
74
75   //! Returns content of the model index for the given role, it is obtained from internal container of values
76   //! It returns value only for DisplayRole.
77   //! \param theIndex a model index
78   //! \param theRole a view role
79   //! \return value intepreted depending on the given role
80   virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
81
82   //! Returns number of rows
83   //! \param theParent an index of the parent item
84   //! \return an integer value
85   virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
86   { (void)theParent; return 1; }
87
88   //! Returns number of columns
89   //! \param theParent an index of the parent item
90   //! \return an integer value
91   virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
92   { (void)theParent; return myValues.size(); }
93
94 private:
95
96   QStringList myValues; //!< file names
97 };
98
99 #endif