Fix crash when sorting one table in the Browse Tab and changing to another

Fix a crash when sorting the n-th column of a table in the Browse Tab
and then changing to a table with less than n columns.
This commit is contained in:
Martin Kleusberg
2014-07-03 22:40:03 +02:00
parent e1ea78fdda
commit 88a4caedba
2 changed files with 13 additions and 9 deletions

View File

@@ -10,11 +10,18 @@ SqliteTableModel::SqliteTableModel(QObject* parent, DBBrowserDB* db, size_t chun
: QAbstractTableModel(parent)
, m_db(db)
, m_rowCount(0)
, m_iSortColumn(0)
, m_sSortOrder("ASC")
, m_chunkSize(chunkSize)
, m_valid(false)
{
reset();
}
void SqliteTableModel::reset()
{
m_iSortColumn = 0;
m_sSortOrder = "ASC";
m_headers.clear();
m_mWhere.clear();
}
void SqliteTableModel::setChunkSize(size_t chunksize)
@@ -24,17 +31,16 @@ void SqliteTableModel::setChunkSize(size_t chunksize)
void SqliteTableModel::setTable(const QString& table)
{
reset();
m_sTable = table;
m_headers.clear();
QString rowid = "rowid";
if(m_db->getObjectByName(table).gettype() == "table")
rowid = sqlb::Table::parseSQL(m_db->getObjectByName(table).getsql()).rowidColumn();
m_headers.push_back(rowid);
m_headers.append(m_db->getTableFields(table));
m_mWhere.clear();
buildQuery();
}
@@ -84,10 +90,7 @@ void SqliteTableModel::setQuery(const QString& sQuery, bool dontClearHeaders)
{
// clear
if(!dontClearHeaders)
{
m_mWhere.clear();
m_headers.clear();
}
reset();
if(!m_db->isOpen())
return;

View File

@@ -11,6 +11,7 @@ class SqliteTableModel : public QAbstractTableModel
Q_OBJECT
public:
explicit SqliteTableModel(QObject *parent = 0, DBBrowserDB* db = 0, size_t chunkSize = 50000);
void reset();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int totalRowCount() const;