Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gparamdelegate.cpp
Go to the documentation of this file.
1 #include <QtGui>
2 
3 #include "gparamdelegate.h"
4 
5 GParamDelegate::GParamDelegate(StringParameters* p, QMainWindow *mw, QObject *parent) : QItemDelegate(parent), _mw(mw) {
6  _parent = qobject_cast<QTableWidget *>(parent);
7  _p=p;
8 }
9 
10 QWidget *GParamDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex &index) const
11 {
12  QLineEdit *edit = new QLineEdit(parent);
13 
14  if( index.column() == 0 ){
15  edit->setReadOnly(true);
16  }
17  else{
18  connect(edit, SIGNAL(editingFinished()), _mw, SIGNAL(modifiedContent()));
19  }
20 
21  return edit;
22 }
23 
24 void GParamDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
25 {
26  QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
27  edit->setText(index.model()->data(index).toString());
28 }
29 
30 void GParamDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
31 {
32  QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
33  model->setData(index, edit->displayText());
34 
35  //update the parameter's
36  StringVec value;
37  //save the value
38  value.push_back(edit->displayText().toStdString());
39  //erase the old parameter
40  _p->erase( _parent->item( index.row(), 0)->text().toStdString() );
41  //add a new parameter with updated values
42  _p->add( _parent->item( index.row(), 0)->text().toStdString(), value );
43 
44 }
45 
StringParameters * _p
QMainWindow * _mw
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
void add(const std::string &key, const std::vector< std::string > &values)
T push_back(T...args)
GParamDelegate(const GParamDelegate &)=default
void erase(const std::string &key)
QTableWidget * _parent
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Simple parameters class for Marlin.
void setEditorData(QWidget *editor, const QModelIndex &index) const