Slicer 4.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLColorModel.h
Go to the documentation of this file.
00001 /*==============================================================================
00002 
00003   Program: 3D Slicer
00004 
00005   Copyright (c) Kitware Inc.
00006 
00007   See COPYRIGHT.txt
00008   or http://www.slicer.org/copyright/copyright.txt for details.
00009 
00010   Unless required by applicable law or agreed to in writing, software
00011   distributed under the License is distributed on an "AS IS" BASIS,
00012   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013   See the License for the specific language governing permissions and
00014   limitations under the License.
00015 
00016   This file was originally developed by Julien Finet, Kitware Inc.
00017   and was partially funded by NIH grant 3P41RR013218-12S1
00018 
00019 ==============================================================================*/
00020 
00021 #ifndef __qMRMLColorModel_h
00022 #define __qMRMLColorModel_h
00023 
00024 // Qt includes
00025 #include <QStandardItemModel>
00026 
00027 // CTK includes
00028 #include <ctkPimpl.h>
00029 #include <ctkVTKObject.h>
00030 
00031 // qMRML includes
00032 #include "qMRMLWidgetsExport.h"
00033 
00034 class vtkMRMLNode;
00035 class vtkMRMLColorNode;
00036 class QAction;
00037 
00038 class qMRMLColorModelPrivate;
00039 
00040 //------------------------------------------------------------------------------
00041 class QMRML_WIDGETS_EXPORT qMRMLColorModel : public QStandardItemModel
00042 {
00043   Q_OBJECT
00044   QVTK_OBJECT
00045   Q_PROPERTY(bool noneEnabled READ noneEnabled WRITE setNoneEnabled)
00046 
00047 public:
00048   typedef QAbstractItemModel Superclass;
00049   qMRMLColorModel(QObject *parent=0);
00050   virtual ~qMRMLColorModel();
00051 
00054   enum ItemDataRole{
00055     ColorEntryRole = Qt::UserRole,
00056     PointerRole,
00057     ColorRole
00058   };
00059 
00063   enum Columns{
00064     ColorColumn = 0,
00065     LabelColumn = 1,
00066     OpacityColumn = 2
00067   };
00068 
00069   void setMRMLColorNode(vtkMRMLColorNode* node);
00070   vtkMRMLColorNode* mrmlColorNode()const;
00071 
00074   void setNoneEnabled(bool enable);
00075   bool noneEnabled()const;
00076 
00078   void setLabelInColorColumn(bool enable);
00079   bool isLabelInColorColumn()const;
00080 
00083   inline int colorFromIndex(const QModelIndex &nodeIndex)const;
00084   int colorFromItem(QStandardItem* nodeItem)const;
00085   
00086   QStandardItem* itemFromColor(int color, int column = 0)const;
00087   QModelIndexList indexes(int color)const;
00088   
00089   inline QColor qcolorFromIndex(const QModelIndex& nodeIndex)const;
00090   inline QColor qcolorFromItem(QStandardItem* nodeItem)const;
00091   QColor qcolorFromColor(int color)const;
00092 
00094   QString nameFromColor(int colorEntry)const;
00095 
00096 protected slots:
00097   void onMRMLColorNodeModified(vtkObject* node);
00098   void onItemChanged(QStandardItem * item);
00099 
00100 protected:
00101 
00102   qMRMLColorModel(qMRMLColorModelPrivate* pimpl, QObject *parent=0);
00103   //virtual void insertColor(int color);
00104   virtual void updateItemFromColor(QStandardItem* item, int color, int column);
00105   virtual void updateColorFromItem(int color, QStandardItem* item);
00106   virtual void updateNode();
00107   //virtual void populateNode();
00108 
00109   static void onMRMLNodeEvent(vtkObject* vtk_obj, unsigned long event,
00110                               void* client_data, void* call_data);
00111 protected:
00112   QScopedPointer<qMRMLColorModelPrivate> d_ptr;
00113 
00114 private:
00115   Q_DECLARE_PRIVATE(qMRMLColorModel);
00116   Q_DISABLE_COPY(qMRMLColorModel);
00117 };
00118 
00119 // -----------------------------------------------------------------------------
00120 int qMRMLColorModel::colorFromIndex(const QModelIndex &nodeIndex)const
00121 {
00122   return this->colorFromItem(this->itemFromIndex(nodeIndex));
00123 }
00124 
00125 // -----------------------------------------------------------------------------
00126 QColor qMRMLColorModel::qcolorFromIndex(const QModelIndex &nodeIndex)const
00127 {
00128   return this->qcolorFromItem(this->itemFromIndex(nodeIndex));
00129 }
00130 
00131 // -----------------------------------------------------------------------------
00132 QColor qMRMLColorModel::qcolorFromItem(QStandardItem* nodeItem)const
00133 {
00134   return this->qcolorFromColor(this->colorFromItem(nodeItem));
00135 }
00136 
00137 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines