QAbstractTableModel::index
C++ (Qt)class BaseDataTableModel : public QAbstractTableModel{ Q_OBJECT public: explicit BaseDataTableModel(int name, QObject *parent = 0); virtual ~BaseDataTableModel(); Qt::ItemFlags flags(const QModelIndex &index) const; int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; .... virtual void prepareInsertData() = 0; }; class TableModelCP_Device : public BaseDataTableModel{ Q_OBJECT public: explicit TableModelCP_Device(int name, QObject *parent = 0); virtual ~TableModelCP_Device(); ... virtual void prepareInsertData();}; void TableModelCP_Device::prepareInsertData(){ qDebug()<<"TableModelCP_Device::prepareInsertData"; //DEV_CODE int column_code_devices = 0; //номер колонки code в таблице DEVICES QModelIndex prKeyDevices = QAbstractTableModel::index(viewDevices->currentIndex().row(),column_code_devices); qDebug()<<"prKeyDevices = "<<prKeyDevices; QVariant code_devices = ((BaseDataTableModel*)(((DataBaseFilterModel*)(viewDevices->model()))->sourceModel()))->data(prKeyDevices); qDebug()<<"code_devices = "<<code_devices; //CP_CODE int column_code_cp = 0; //номер колонки code в таблице CONTROL_POINTS QModelIndex prKeyControlPoints = QAbstractTableModel::index(viewControlPoints->currentIndex().row(),column_code_cp); qDebug()<<"prKeyControlPoints = "<<prKeyControlPoints; QVariant code_cp = ((BaseDataTableModel*)(((DataBaseFilterModel*)(viewControlPoints->model()))->sourceModel()))->data(prKeyControlPoints); qDebug()<<"code_cp = "<<code_cp; //TO DO как в BaseDataTableModel::prepareInsertData() int row = rowCount(QModelIndex()); int amountColumn = columnCount(QModelIndex()); beginInsertRows(QModelIndex(),row,row); QStringList * dataRecord = new QStringList; for(int i = 0; i < amountColumn; i++){ if(i == 0){//первая колонка в таблице CP_DEVICE dataRecord->append(code_devices.toString()); } else if(i == 1){//вторая колонка в таблице CP_CODE dataRecord->append(code_cp.toString()); } else{ dataRecord->append(""); } } dataRecords.append(dataRecord); insertRecords.append(dataRecord); endInsertRows(); }
qDebug()<<"prKeyDevices = "<<prKeyDevices;
QModelIndex(-1,-1,QObject(0x0))
viewControlPoints->currentIndex()
C++ (Qt)viewDevices->currentIndex()
C++ (Qt)QModelIndex prKeyDevices = QAbstractTableModel::index(viewDevices->currentIndex().row(),column_code_devices);qDebug()<<"prKeyDevices = "<<prKeyDevices;QVariant code_devices = ((BaseDataTableModel*)(((DataBaseFilterModel*)(viewDevices->model()))->sourceModel()))->data(prKeyDevices);
QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &parent) const{ return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();}