mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
SqliteTableModel: Don't show binary data in table widgets
Don't show BLOBs as binary data in table widgets, instead put a "BLOB" text in that cell. Also make BLOBs not editable unless you use the edit dialog.
This commit is contained in:
@@ -604,7 +604,7 @@ void MainWindow::editWinAway()
|
||||
|
||||
void MainWindow::editText(const QModelIndex& index)
|
||||
{
|
||||
editWin->loadText(index.data().toByteArray(), index.row(), index.column());
|
||||
editWin->loadText(index.data(Qt::EditRole).toByteArray(), index.row(), index.column());
|
||||
editWin->show();
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,10 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
|
||||
while(index.row() >= m_data.size() && canFetchMore())
|
||||
const_cast<SqliteTableModel*>(this)->fetchMore(); // Nothing evil to see here, move along
|
||||
|
||||
return m_data.at(index.row()).at(index.column());
|
||||
if(role == Qt::DisplayRole && isBinary(index))
|
||||
return "(BLOB)";
|
||||
else
|
||||
return m_data.at(index.row()).at(index.column());
|
||||
} else {
|
||||
return QVariant();
|
||||
}
|
||||
@@ -186,7 +189,10 @@ Qt::ItemFlags SqliteTableModel::flags(const QModelIndex& index) const
|
||||
if(!index.isValid())
|
||||
return Qt::ItemIsEnabled;
|
||||
|
||||
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
|
||||
Qt::ItemFlags ret = QAbstractTableModel::flags(index);
|
||||
if(!isBinary(index))
|
||||
ret |= Qt::ItemIsEditable;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SqliteTableModel::sort(int column, Qt::SortOrder order)
|
||||
@@ -338,3 +344,9 @@ void SqliteTableModel::clearCache()
|
||||
m_data.clear();
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
bool SqliteTableModel::isBinary(const QModelIndex& index) const
|
||||
{
|
||||
QByteArray val = m_data.at(index.row()).at(index.column());
|
||||
return val.size() > 1024 || val.contains('\0'); // Cheap BLOB test here...
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ public:
|
||||
|
||||
bool valid() const { return m_valid; }
|
||||
|
||||
bool isBinary(const QModelIndex& index) const;
|
||||
|
||||
typedef QList<QByteArray> QByteArrayList;
|
||||
|
||||
signals:
|
||||
|
||||
Reference in New Issue
Block a user