22 #include <QStringList>
23 #include <QMessageBox>
30 :QAbstractTableModel(parent)
41 context->UngetService( m_PythonServiceRef );
48 if (action == Qt::IgnoreAction)
52 bool returnValue =
false;
56 MITK_DEBUG(
"QmitkPythonVariableStackTableModel") <<
"dropped MITK DataNode";
62 foreach(node, dataNodeList)
65 MITK_DEBUG(
"QmitkPythonVariableStackTableModel") <<
"mitkImage is not null " << (mitkImage != 0?
"true":
"false");
68 QString varName(node->
GetName().c_str());
70 varName = varName.replace(QRegExp(
"[.\\+\\-*\\s\\/\\n\\t\\r]"),QString(
"_"));
74 if ( varName.isEmpty() )
76 if ( rx.indexIn(varName) == 0)
80 varName = QString(
"%1%2").arg(varName).arg(i);
81 MITK_DEBUG(
"QmitkPythonVariableStackTableModel") <<
"varName" << varName.toStdString();
87 int ret = QMessageBox::question(NULL,
"Export option",
88 "2D image detected. Export as OpenCV image to Python instead of an SimpleITK image?",
89 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
90 exportAsCvImage = ret == QMessageBox::Yes;
97 if( !exportAsCvImage )
106 MITK_ERROR <<
"SimpleITK Python wrapping not available. Skipping export for image " << node->
GetName();
113 MITK_DEBUG(
"QmitkPythonVariableStackTableModel") <<
"found surface";
117 if (varName.isEmpty() )
119 if ( rx.indexIn(varName) == 0)
122 MITK_DEBUG(
"QmitkPythonVariableStackTableModel") <<
"varName" << varName;
130 MITK_ERROR <<
"VTK Python wrapping not available. Skipping export for surface " << node->
GetName();
145 if ( role == Qt::DisplayRole )
147 if( orientation == Qt::Horizontal )
151 headerData =
"Attribute";
152 else if(section == 1)
154 else if(section == 2)
155 headerData =
"Value";
164 Qt::ItemFlags
flags = QAbstractItemModel::flags(index);
167 return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | flags;
169 return Qt::ItemIsDropEnabled |
flags;
174 return m_VariableStack.size();
184 if (index.isValid() && !m_VariableStack.empty())
186 if(role == Qt::DisplayRole)
189 if(index.column() == 0)
190 return QString::fromStdString(item.
m_Name);
191 if(index.column() == 1)
192 return QString::fromStdString(item.
m_Type);
193 if(index.column() == 2)
194 return QString::fromStdString(item.
m_Value);
202 return QAbstractTableModel::mimeTypes();
204 types <<
"application/x-mitk-datanodes";
205 types <<
"application/x-qabstractitemmodeldatalist";
211 return Qt::CopyAction | Qt::MoveAction;
216 MITK_DEBUG(
"QmitkPythonVariableStackTableModel") <<
"command was executed " << pythonCommand;
218 QAbstractTableModel::beginResetModel();
219 QAbstractTableModel::endResetModel();
224 return m_VariableStack;
virtual bool CopyToPythonAsSimpleItkImage(mitk::Image *image, const std::string &varName)=0
Class for storing surfaces (vtkPolyData).
virtual void AddPythonCommandObserver(PythonCommandObserver *observer)=0
adds a command observer which is informed after a command was issued with "Execute" ...
bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &)
static const QString MITK_IMAGE_VAR_NAME
std::vector< mitk::PythonVariable > GetVariableStack() const
QStringList mimeTypes() const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
bool GetName(std::string &nodeName, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="name") const
Convenience access method for accessing the name of an object (instance of StringProperty with proper...
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
static QList< mitk::DataNode * > ToDataNodePtrList(const QByteArray &ba)
virtual bool IsVtkPythonWrappingAvailable()=0
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
void CommandExecuted(const std::string &pythonCommand)
static const QString DataNodePtrs
int columnCount(const QModelIndex &parent=QModelIndex()) const
virtual bool IsOpenCvPythonWrappingAvailable()=0
virtual void RemovePythonCommandObserver(PythonCommandObserver *observer)=0
removes a specific command observer
int rowCount(const QModelIndex &parent=QModelIndex()) const
Qt::DropActions supportedDropActions() const
Image class for storing images.
virtual std::vector< PythonVariable > GetVariableStack() const =0
virtual bool IsSimpleItkPythonWrappingAvailable()=0
static const QString MITK_SURFACE_VAR_NAME
QmitkPythonVariableStackTableModel(QObject *parent=0)
virtual ~QmitkPythonVariableStackTableModel()
unsigned int GetDimension() const
Get dimension of the image.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
Class for nodes of the DataTree.
virtual bool CopyToPythonAsCvImage(mitk::Image *image, const std::string &varName)=0
virtual bool CopyToPythonAsVtkPolyData(mitk::Surface *surface, const std::string &varName)=0
Qt::ItemFlags flags(const QModelIndex &index) const