Skip to content

Commit

Permalink
Merge pull request sqlitebrowser#286 from gimKondo/typeof-edit-data
Browse files Browse the repository at this point in the history
set selected data type on Edit database cell dialog
  • Loading branch information
justinclift committed Jan 19, 2016
2 parents a7b5c3f + 54cea17 commit 2242ce8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/EditDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ void EditDialog::accept()
// Don't update if the data hasn't changed
// To differentiate NULL and empty byte arrays, we also compare the NULL flag
if(hexEdit->data() != oldData || hexEdit->data().isNull() != oldData.isNull())
emit updateRecordText(curRow, curCol, hexEdit->data());
{
const QString dataType = ui->comboEditor->currentText();
bool isBlob = dataType == tr("Binary") || !ui->comboEditor->isVisible();
emit updateRecordText(curRow, curCol, isBlob, hexEdit->data());
}
emit goingAway();
}

Expand Down
2 changes: 1 addition & 1 deletion src/EditDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private slots:

signals:
void goingAway();
void updateRecordText(int, int, const QByteArray&);
void updateRecordText(int row, int col, bool isBlob, const QByteArray& data);

private:
Ui::EditDialog* ui;
Expand Down
6 changes: 3 additions & 3 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void MainWindow::init()
connect(ui->dataTable->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(setRecordsetLabel()));
connect(ui->dataTable->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(updateBrowseDataColumnWidth(int,int,int)));
connect(editWin, SIGNAL(goingAway()), this, SLOT(editWinAway()));
connect(editWin, SIGNAL(updateRecordText(int, int, QByteArray)), this, SLOT(updateRecordText(int, int, QByteArray)));
connect(editWin, SIGNAL(updateRecordText(int, int, bool, QByteArray)), this, SLOT(updateRecordText(int, int, bool, QByteArray)));
connect(editDock, SIGNAL(goingAway()), this, SLOT(editWinAway()));
connect(editDock, SIGNAL(updateRecordText(int, int, QByteArray)), this, SLOT(updateRecordText(int, int, QByteArray)));
connect(ui->dbTreeWidget->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(changeTreeSelection()));
Expand Down Expand Up @@ -746,9 +746,9 @@ void MainWindow::helpAbout()
dialog.exec();
}

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

void MainWindow::editWinAway()
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private slots:
void editTable();
void helpWhatsThis();
void helpAbout();
void updateRecordText(int row, int col, const QByteArray& newtext);
void updateRecordText(int row, int col, bool type, const QByteArray& newtext);
void editWinAway();
void dataTableSelectionChanged(const QModelIndex& index);
void doubleClickTable(const QModelIndex& index);
Expand Down
9 changes: 8 additions & 1 deletion src/sqlitetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ sqlb::ForeignKeyClause SqliteTableModel::getForeignKeyClause(int column) const
}

bool SqliteTableModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
// This function is for in-place editing.
// So, BLOB flag is false every times.
return setTypedData(index, false, value, role);
}

bool SqliteTableModel::setTypedData(const QModelIndex& index, bool isBlob, const QVariant& value, int role)
{
if(index.isValid() && role == Qt::EditRole)
{
Expand All @@ -306,7 +313,7 @@ bool SqliteTableModel::setData(const QModelIndex& index, const QVariant& value,
if(oldValue == newValue && oldValue.isNull() == newValue.isNull())
return true;

if(m_db->updateRecord(m_sTable, m_headers.at(index.column()), m_data[index.row()].at(0), newValue, isBinary(index)))
if(m_db->updateRecord(m_sTable, m_headers.at(index.column()), m_data[index.row()].at(0), newValue, isBlob))
{
// Only update the cache if this row has already been read, if not there's no need to do any changes to the cache
if(index.row() < m_data.size())
Expand Down
1 change: 1 addition & 0 deletions src/sqlitetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SqliteTableModel : public QAbstractTableModel
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
bool setTypedData(const QModelIndex& index, bool isBlob, const QVariant& value, int role = Qt::EditRole);
bool canFetchMore(const QModelIndex &parent = QModelIndex()) const;
void fetchMore(const QModelIndex &parent = QModelIndex());
size_t queryMore(size_t offset);
Expand Down

0 comments on commit 2242ce8

Please sign in to comment.