mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Add helper function to make the code more self-explanatory
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user