Add helper function to make the code more self-explanatory

This commit is contained in:
Martin Kleusberg
2017-06-28 16:29:28 +02:00
parent 4f676ae206
commit 4de01c1e73
2 changed files with 20 additions and 1 deletions

View File

@@ -315,7 +315,7 @@ sqlb::ForeignKeyClause SqliteTableModel::getForeignKeyClause(int column) const
bool SqliteTableModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
// Don't even try setting any data if we're not browsing a table, i.e. the model data comes from a custom query
if(m_sTable.isEmpty())
if(!isEditable())
return false;
// This function is for in-place editing.
@@ -415,6 +415,9 @@ void SqliteTableModel::sort(int column, Qt::SortOrder order)
bool SqliteTableModel::insertRows(int row, int count, const QModelIndex& parent)
{
if(!isEditable())
return false;
QByteArrayList blank_data;
for(int i=0; i < m_headers.size(); ++i)
blank_data.push_back("");
@@ -453,6 +456,9 @@ bool SqliteTableModel::insertRows(int row, int count, const QModelIndex& parent)
bool SqliteTableModel::removeRows(int row, int count, const QModelIndex& parent)
{
if(!isEditable())
return false;
beginRemoveRows(parent, row, row + count - 1);
bool ok = true;
@@ -475,6 +481,9 @@ bool SqliteTableModel::removeRows(int row, int count, const QModelIndex& parent)
QModelIndex SqliteTableModel::dittoRecord(int old_row)
{
if(!isEditable())
return QModelIndex();
insertRow(rowCount());
int firstEditedColumn = 0;
int new_row = rowCount() - 1;
@@ -790,3 +799,8 @@ void SqliteTableModel::setPseudoPk(const QString& pseudoPk)
buildQuery();
}
bool SqliteTableModel::isEditable() const
{
return !m_sTable.isEmpty();
}

View File

@@ -59,6 +59,11 @@ public:
sqlb::ForeignKeyClause getForeignKeyClause(int column) const;
// This returns true if the model is set up for editing. The model is able to operate in more or less two different modes, table browsing
// and query browsing. We only support editing data for the table browsing mode and not for the query mode. This function returns true if
// the model is currently editable, i.e. it's running in table mode.
bool isEditable() const;
public slots:
void updateFilter(int column, const QString& value);