What I'm trying to do is use a combobox to change the data in a reimplemented QAbstractTableModel that is shown through a QTableView. I have the data function as follows:
{
TrackInfoObject *m_pTrackInfo = m_pTrackCollection->getTrack(index.row()+1);
if (!index.isValid())
if (index.row() >= m_pTrackCollection->getSize())
if (role == Qt::BackgroundRole)
{
return backgroundColor;
}
//if (role == Qt::ForegroundRole )
//{
//return foregroundColor;
//}
else if (role == Qt::DisplayRole )
{
switch(index.column())
{
case 0: return m_pTrackInfo->getScoreStr();
case 1: return m_pTrackInfo->getTitle();
case 2: return m_pTrackInfo->getArtist();
case 3: return m_pTrackInfo->getType();
case 4: return m_pTrackInfo->getDurationStr();
case 5: return m_pTrackInfo->getBitrateStr();
case 6: return m_pTrackInfo->getBpmStr();
case 7: return m_pTrackInfo->getComment();
}
}
else
}
QVariant WTrackTableModel :: data(const QModelIndex &index, int role) const
{
TrackInfoObject *m_pTrackInfo = m_pTrackCollection->getTrack(index.row()+1);
if (!index.isValid())
return QVariant();
if (index.row() >= m_pTrackCollection->getSize())
return QVariant();
if (role == Qt::BackgroundRole)
{
return backgroundColor;
}
//if (role == Qt::ForegroundRole )
//{
//return foregroundColor;
//}
else if (role == Qt::DisplayRole )
{
switch(index.column())
{
case 0: return m_pTrackInfo->getScoreStr();
case 1: return m_pTrackInfo->getTitle();
case 2: return m_pTrackInfo->getArtist();
case 3: return m_pTrackInfo->getType();
case 4: return m_pTrackInfo->getDurationStr();
case 5: return m_pTrackInfo->getBitrateStr();
case 6: return m_pTrackInfo->getBpmStr();
case 7: return m_pTrackInfo->getComment();
}
}
else
return QVariant();
}
To copy to clipboard, switch view to plain text mode
I know that maybe a setData reimplementation might do this model some good but I don't understand how I would use it. I also know that to change the data in my table I think i would need to emit the dataChanged function....although I dont know where to emit it and when. I have a separate function in another class that handles the combobox change:
connect(m_pView->m_pComboBox, SIGNAL(activated(int)), this, SLOT(slotActivatePlaylist(int)));
void Track::slotActivatePlaylist(int index)
{
if (m_pActivePlaylist)
m_pActivePlaylist->deactivate();
// Insert playlist according to ComboBox index
m_pActivePlaylist = m_qPlaylists.at(index);
m_pActivePlaylist->activate(m_pView->m_pTrackTable);
//m_pTableModel->setTrackCollection(m_pActivePlaylist->getCollection());
}
connect(m_pView->m_pComboBox, SIGNAL(activated(int)), this, SLOT(slotActivatePlaylist(int)));
void Track::slotActivatePlaylist(int index)
{
if (m_pActivePlaylist)
m_pActivePlaylist->deactivate();
// Insert playlist according to ComboBox index
m_pActivePlaylist = m_qPlaylists.at(index);
m_pActivePlaylist->activate(m_pView->m_pTrackTable);
//m_pTableModel->setTrackCollection(m_pActivePlaylist->getCollection());
}
To copy to clipboard, switch view to plain text mode
Although, I can't really figure out what to do for the QTableView or QAbstractTableModel Item data update.
Any suggestions on how I should proceed?
Thanks!
Bookmarks