set selected data type on imported by Edit database cell

Data type isn't decided by column type, but cell's type.
And, 2 bugs is fixed.
1. prevention in-place editing data
2. the lack of tr() on text literal
This commit is contained in:
gimKondo
2015-04-28 00:16:12 +09:00
committed by gim_kondo
parent a7b5c3f182
commit 54cea17f3a
6 changed files with 19 additions and 7 deletions

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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()));
@@ -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()

View File

@@ -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);

View File

@@ -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)
{
@@ -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())

View File

@@ -21,6 +21,7 @@ public:
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);