I have a tableview with takes a qsortfilterproxymodel and is filtered by a particular name.
I have subclassed the qsortfilterproxymodel
{
Q_OBJECT
public:
FilterProxyModel
(QObject *parent
= 0);
void moveUp( const int itemIndex);
void moveDown( const int itemIndex);
};
class FilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
FilterProxyModel(QObject *parent = 0);
void moveUp( const int itemIndex);
void moveDown( const int itemIndex);
};
To copy to clipboard, switch view to plain text mode
and here's the implementation
FilterProxyModel
::FilterProxyModel (QObject *parent
) :{
}
void FilterProxyModel ::moveUp(const int itemIndex)
{
if(itemIndex > 0 && itemIndex < rowCount())
{
itemIndex - 1);
endMoveRows();
}
}
void FilterProxyModel ::moveDown(const int itemIndex)
{
if(itemIndex >= 0 && itemIndex < rowCount() - 1)
{
itemIndex + 2);
endMoveRows();
}
}
FilterProxyModel ::FilterProxyModel (QObject *parent) :
QSortFilterProxyModel(parent)
{
}
void FilterProxyModel ::moveUp(const int itemIndex)
{
if(itemIndex > 0 && itemIndex < rowCount())
{
beginMoveRows(QModelIndex(), itemIndex, itemIndex, QModelIndex(),
itemIndex - 1);
moveRow(QModelIndex(), itemIndex, QModelIndex(), itemIndex - 1);
endMoveRows();
}
}
void FilterProxyModel ::moveDown(const int itemIndex)
{
if(itemIndex >= 0 && itemIndex < rowCount() - 1)
{
beginMoveRows(QModelIndex(), itemIndex, itemIndex, QModelIndex(),
itemIndex + 2);
moveRow(QModelIndex(), itemIndex, QModelIndex(), itemIndex + 2);
endMoveRows();
}
}
To copy to clipboard, switch view to plain text mode
Here's how the model implemented
m_Model = new FilterProxyModel(this);
m_Model ->setSourceModel(partiesModel);
m_Model
->setFilterRegExp
(QRegExp("party", Qt
::CaseInsensitive,
QRegExp::FixedString));
m_Model ->setFilterKeyColumn(PartyModel::Action);
m_Model = new FilterProxyModel(this);
m_Model ->setSourceModel(partiesModel);
m_Model ->setFilterRegExp(QRegExp("party", Qt::CaseInsensitive, QRegExp::FixedString));
m_Model ->setFilterKeyColumn(PartyModel::Action);
To copy to clipboard, switch view to plain text mode
I want to move the items using a push button, when i call the function the move doesn't happen. Could you tell me what I'm missing?
Bookmarks