Finally problem solved after reading again n again about MVC and thanks "All" for the support !!
I have configured the model with Combo box delegate with openPersistentEditor in combo box enabled columns (4,5) .
In ComboBoxDelegate.cpp
{
if(index.column() == 3 || index.column() == 4)
{
// Create the combobox and populate it
cb
->addItem
(QString("Please Select"));
connect(cb,
SIGNAL(currentIndexChanged
(QString)),
this,
SLOT(print
(QString)));
return cb;
} else
return QStyledItemDelegate::createEditor(parent, option, index);
}
]QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & option , const QModelIndex &index ) const
{
if(index.column() == 3 || index.column() == 4)
{
// Create the combobox and populate it
QComboBox *cb = new QComboBox(parent);
cb->addItem(QString("Please Select"));
cb->addItem(QString("1"));
cb->addItem(QString("2"));
cb->addItem(QString("3"));
connect(cb, SIGNAL(currentIndexChanged(QString)), this, SLOT(print(QString)));
return cb;
} else
return QStyledItemDelegate::createEditor(parent, option, index);
}
To copy to clipboard, switch view to plain text mode
]
And in my TableModel.cpp Class
]
{
int row = index.row();
int col = index.column();
QMap<QString, QString> qMapPair = listOfItems.at(index.row());
if(index.isValid() && role == Qt::EditRole)
{
switch(col) {
case 3 :
{
qDebug() << "Value From Table Model = " <<value.toString() << "Row" <<row << "xCol"<< col ;
return true;
}
break;
case 4 :
{
qDebug() << "Value From Table Model = " <<value.toString() << "Row" <<row << "xCol"<< col ;
return true;
}
break;
default :
break;}}return false;}
]
bool TableModel::setData(const QModelIndex & index, const QVariant &value, int role)
{
int row = index.row();
int col = index.column();
QMap<QString, QString> qMapPair = listOfItems.at(index.row());
if(index.isValid() && role == Qt::EditRole)
{
switch(col) {
case 3 :
{
qDebug() << "Value From Table Model = " <<value.toString() << "Row" <<row << "xCol"<< col ;
return true;
}
break;
case 4 :
{
qDebug() << "Value From Table Model = " <<value.toString() << "Row" <<row << "xCol"<< col ;
return true;
}
break;
default :
break;}}return false;}
To copy to clipboard, switch view to plain text mode
]
and things are working perfectly , now i am working on a event that when i will select any index value in combo box it will populate a dialog which configure the data on my Map. I will ask later for further question .
Bookmarks