Skip to content

Commit 2242ce8

Browse files
committed
Merge pull request sqlitebrowser#286 from gimKondo/typeof-edit-data
set selected data type on Edit database cell dialog
2 parents a7b5c3f + 54cea17 commit 2242ce8

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

src/EditDialog.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ void EditDialog::accept()
163163
// Don't update if the data hasn't changed
164164
// To differentiate NULL and empty byte arrays, we also compare the NULL flag
165165
if(hexEdit->data() != oldData || hexEdit->data().isNull() != oldData.isNull())
166-
emit updateRecordText(curRow, curCol, hexEdit->data());
166+
{
167+
const QString dataType = ui->comboEditor->currentText();
168+
bool isBlob = dataType == tr("Binary") || !ui->comboEditor->isVisible();
169+
emit updateRecordText(curRow, curCol, isBlob, hexEdit->data());
170+
}
167171
emit goingAway();
168172
}
169173

src/EditDialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private slots:
4343

4444
signals:
4545
void goingAway();
46-
void updateRecordText(int, int, const QByteArray&);
46+
void updateRecordText(int row, int col, bool isBlob, const QByteArray& data);
4747

4848
private:
4949
Ui::EditDialog* ui;

src/MainWindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void MainWindow::init()
182182
connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel()));
183183
connect(ui->dataTable->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(updateBrowseDataColumnWidth(int,int,int)));
184184
connect(editWin, SIGNAL(goingAway()), this, SLOT(editWinAway()));
185-
connect(editWin, SIGNAL(updateRecordText(int, int, QByteArray)), this, SLOT(updateRecordText(int, int, QByteArray)));
185+
connect(editWin, SIGNAL(updateRecordText(int, int, bool, QByteArray)), this, SLOT(updateRecordText(int, int, bool, QByteArray)));
186186
connect(editDock, SIGNAL(goingAway()), this, SLOT(editWinAway()));
187187
connect(editDock, SIGNAL(updateRecordText(int, int, QByteArray)), this, SLOT(updateRecordText(int, int, QByteArray)));
188188
connect(ui->dbTreeWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(changeTreeSelection()));
@@ -746,9 +746,9 @@ void MainWindow::helpAbout()
746746
dialog.exec();
747747
}
748748

749-
void MainWindow::updateRecordText(int row, int col, const QByteArray& newtext)
749+
void MainWindow::updateRecordText(int row, int col, bool isBlob, const QByteArray& newtext)
750750
{
751-
m_browseTableModel->setData(m_browseTableModel->index(row, col), newtext);
751+
m_browseTableModel->setTypedData(m_browseTableModel->index(row, col), isBlob, newtext);
752752
}
753753

754754
void MainWindow::editWinAway()

src/MainWindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private slots:
176176
void editTable();
177177
void helpWhatsThis();
178178
void helpAbout();
179-
void updateRecordText(int row, int col, const QByteArray& newtext);
179+
void updateRecordText(int row, int col, bool type, const QByteArray& newtext);
180180
void editWinAway();
181181
void dataTableSelectionChanged(const QModelIndex& index);
182182
void doubleClickTable(const QModelIndex& index);

src/sqlitetablemodel.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ sqlb::ForeignKeyClause SqliteTableModel::getForeignKeyClause(int column) const
295295
}
296296

297297
bool SqliteTableModel::setData(const QModelIndex& index, const QVariant& value, int role)
298+
{
299+
// This function is for in-place editing.
300+
// So, BLOB flag is false every times.
301+
return setTypedData(index, false, value, role);
302+
}
303+
304+
bool SqliteTableModel::setTypedData(const QModelIndex& index, bool isBlob, const QVariant& value, int role)
298305
{
299306
if(index.isValid() && role == Qt::EditRole)
300307
{
@@ -306,7 +313,7 @@ bool SqliteTableModel::setData(const QModelIndex& index, const QVariant& value,
306313
if(oldValue == newValue && oldValue.isNull() == newValue.isNull())
307314
return true;
308315

309-
if(m_db->updateRecord(m_sTable, m_headers.at(index.column()), m_data[index.row()].at(0), newValue, isBinary(index)))
316+
if(m_db->updateRecord(m_sTable, m_headers.at(index.column()), m_data[index.row()].at(0), newValue, isBlob))
310317
{
311318
// Only update the cache if this row has already been read, if not there's no need to do any changes to the cache
312319
if(index.row() < m_data.size())

src/sqlitetablemodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class SqliteTableModel : public QAbstractTableModel
2121
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
2222
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
2323
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
24+
bool setTypedData(const QModelIndex& index, bool isBlob, const QVariant& value, int role = Qt::EditRole);
2425
bool canFetchMore(const QModelIndex &parent = QModelIndex()) const;
2526
void fetchMore(const QModelIndex &parent = QModelIndex());
2627
size_t queryMore(size_t offset);

0 commit comments

Comments
 (0)