Silence a couple of warnings

This commit is contained in:
Martin Kleusberg
2019-04-29 19:14:10 +02:00
parent 15c23bb0d3
commit f821fbb1a8
22 changed files with 108 additions and 110 deletions
+2 -2
View File
@@ -112,12 +112,12 @@ public:
}
};
AddRecordDialog::AddRecordDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, QWidget* parent, const std::vector<std::string>& pseudo_pk)
AddRecordDialog::AddRecordDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, QWidget* parent, const std::vector<std::string>& _pseudo_pk)
: QDialog(parent),
ui(new Ui::AddRecordDialog),
pdb(db),
curTable(tableName),
pseudo_pk(pseudo_pk)
pseudo_pk(_pseudo_pk)
{
// Create UI
ui->setupUi(this);
+3 -3
View File
@@ -24,10 +24,10 @@ QString CondFormat::filterToSqlCondition(const QString& value, const QString& en
int sepIdx = value.indexOf('~');
val = value.mid(0, sepIdx);
val2 = value.mid(sepIdx+1);
val.toFloat(&ok);
float valf = val.toFloat(&ok);
if (ok) {
val2.toFloat(&ok);
ok = ok && (val.toFloat() < val2.toFloat());
float val2f = val2.toFloat(&ok);
ok = ok && (valf < val2f);
}
}
if (ok) {
+2 -2
View File
@@ -444,12 +444,12 @@ void EditDialog::updateApplyButton()
ui->buttonApply->setEnabled(true);
}
bool EditDialog::promptInvalidData(const QString& dataType, const QString& errorString)
bool EditDialog::promptInvalidData(const QString& data_type, const QString& errorString)
{
QMessageBox::StandardButton reply = QMessageBox::question(
this,
tr("Invalid data for this mode"),
tr("The cell contains invalid %1 data. Reason: %2. Do you really want to apply it to the cell?").arg(dataType, errorString),
tr("The cell contains invalid %1 data. Reason: %2. Do you really want to apply it to the cell?").arg(data_type, errorString),
QMessageBox::Apply | QMessageBox::Cancel);
return (reply == QMessageBox::Apply);
}
+1 -1
View File
@@ -91,7 +91,7 @@ private:
int checkDataType(const QByteArray& data);
QString humanReadableSize(double byteCount) const;
bool promptInvalidData(const QString& dataType, const QString& errorString);
bool promptInvalidData(const QString& data_type, const QString& errorString);
void setDataInBuffer(const QByteArray& data, DataSources source);
void setStackCurrentIndex(int editMode);
};
+6 -6
View File
@@ -77,7 +77,7 @@ EditIndexDialog::EditIndexDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
connect(ui->tableIndexColumns, &QTableWidget::itemChanged,
[=](QTableWidgetItem* item)
{
index.fields[item->row()].setName(item->text().toStdString());
index.fields[static_cast<size_t>(item->row())].setName(item->text().toStdString());
updateSqlText();
});
@@ -156,7 +156,7 @@ void EditIndexDialog::updateColumnLists()
if(indexFields.at(i).expression())
flags |= Qt::ItemIsEditable;
name->setFlags(flags);
ui->tableIndexColumns->setItem(i, 0, name);
ui->tableIndexColumns->setItem(static_cast<int>(i), 0, name);
// And put a combobox to select the order in which to index the field in the last column
QComboBox* order = new QComboBox(this);
@@ -164,7 +164,7 @@ void EditIndexDialog::updateColumnLists()
order->addItem("ASC");
order->addItem("DESC");
order->setCurrentText(QString::fromStdString(indexFields.at(i).order()).toUpper());
ui->tableIndexColumns->setCellWidget(i, 1, order);
ui->tableIndexColumns->setCellWidget(static_cast<int>(i), 1, order);
connect(order, &QComboBox::currentTextChanged,
[=](QString new_order)
{
@@ -220,7 +220,7 @@ void EditIndexDialog::removeFromIndex(const QModelIndex& idx)
// If this is an expression column and the action was triggered by a double click event instead of a button click,
// we won't remove the expression column because it's too likely that this was only done by accident by the user.
// Instead just open the expression column for editing.
if(index.fields[row].expression() && sender() != ui->buttonFromIndex)
if(index.fields[static_cast<size_t>(row)].expression() && sender() != ui->buttonFromIndex)
{
ui->tableIndexColumns->editItem(ui->tableIndexColumns->item(row, 0));
return;
@@ -313,7 +313,7 @@ void EditIndexDialog::moveCurrentColumn(bool down)
return;
// Swap the columns
std::swap(index.fields[currentRow], index.fields[newRow]);
std::swap(index.fields[static_cast<size_t>(currentRow)], index.fields[static_cast<size_t>(newRow)]);
// Update UI
updateColumnLists();
@@ -326,7 +326,7 @@ void EditIndexDialog::addExpressionColumn()
{
// Check if there already is an empty expression column
auto field_it = sqlb::findField(index, "");
int row = std::distance(index.fields.begin(), field_it);
int row = static_cast<int>(std::distance(index.fields.begin(), field_it));
if(field_it == index.fields.end())
{
// There is no empty expression column yet, so add one.
+4 -4
View File
@@ -331,8 +331,8 @@ bool EditTableDialog::eventFilter(QObject *object, QEvent *event)
void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
{
int index = ui->treeWidget->indexOfTopLevelItem(item);
if(index < static_cast<int>(m_table.fields.size()))
size_t index = static_cast<size_t>(ui->treeWidget->indexOfTopLevelItem(item));
if(index < m_table.fields.size())
{
sqlb::Field& field = m_table.fields.at(index);
QString oldFieldName = QString::fromStdString(field.name());
@@ -348,7 +348,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
// because it's doing a case-independent search and it can't return another field number because SQLite prohibits duplicate field
// names (no matter the case). So when this happens we just allow the renaming because there's no harm to be expected from it.
auto foundField = sqlb::findField(m_table, item->text(column).toStdString());
if(foundField != m_table.fields.end() && foundField-m_table.fields.begin() != index)
if(foundField != m_table.fields.end() && foundField-m_table.fields.begin() != static_cast<int>(index))
{
QMessageBox::warning(this, qApp->applicationName(), tr("There already is a field with that name. Please rename it first or choose a different "
"name for this field."));
@@ -741,7 +741,7 @@ void EditTableDialog::moveCurrentField(bool down)
ui->treeWidget->setCurrentIndex(ui->treeWidget->currentIndex().sibling(newRow, 0));
// Finally update the table SQL
std::swap(m_table.fields[newRow], m_table.fields[currentRow]);
std::swap(m_table.fields[static_cast<size_t>(newRow)], m_table.fields[static_cast<size_t>(currentRow)]);
// Update the SQL preview
updateSqlText();
+1 -1
View File
@@ -225,7 +225,7 @@ bool ExportDataDialog::exportQueryJson(const QString& sQuery, const QString& sFi
for(int i=0;i<columns;++i)
{
int type = sqlite3_column_type(stmt, i);
std::string column_name = column_names[i];
std::string column_name = column_names[static_cast<size_t>(i)];
switch (type) {
case SQLITE_INTEGER: {
+3 -3
View File
@@ -88,7 +88,7 @@ ExtendedScintilla::~ExtendedScintilla()
void ExtendedScintilla::updateLineNumberAreaWidth()
{
// Calculate number of digits of the current number of lines
int digits = std::floor(std::log10(lines())) + 1;
int digits = static_cast<int>(std::log10(lines())) + 1;
// Calculate the width of this number if it was all zeros (this is because a 1 might require less space than a 0 and this could
// cause some flickering depending on the font) and set the new margin width.
@@ -225,8 +225,8 @@ void ExtendedScintilla::setErrorIndicator(int position)
// Set error indicator for the position until end of line, but only if they're enabled
if(showErrorIndicators) {
int column = SendScintilla(QsciScintillaBase::SCI_GETCOLUMN, position);
int line = SendScintilla(QsciScintillaBase::SCI_LINEFROMPOSITION, position);
int column = static_cast<int>(SendScintilla(QsciScintillaBase::SCI_GETCOLUMN, position));
int line = static_cast<int>(SendScintilla(QsciScintillaBase::SCI_LINEFROMPOSITION, position));
fillIndicatorRange(line, column, line+1, 0, errorIndicatorNumber);
}
+5 -4
View File
@@ -149,7 +149,7 @@ QWidget* ExtendedTableWidgetEditorDelegate::createEditor(QWidget* parent, const
// if the current column of the current table does NOT have not-null constraint,
// the NULL is united to the query to get the possible values in the combo-box.
if (!currentTable->fields.at(index.column()-1).notnull())
if (!currentTable->fields.at(static_cast<size_t>(index.column())-1).notnull())
query.append (" UNION SELECT NULL");
SqliteTableModel* fkModel = new SqliteTableModel(m->db(), parent, m->chunkSize(), m->encoding());
@@ -710,10 +710,11 @@ void ExtendedTableWidget::useAsFilter(const QString& filterOperator, bool binary
// If binary operator, the cell data is used as first value and
// the second value must be added by the user.
size_t column = static_cast<size_t>(index.column());
if (binary)
m_tableHeader->setFilter(index.column(), value + filterOperator);
m_tableHeader->setFilter(column, value + filterOperator);
else
m_tableHeader->setFilter(index.column(), filterOperator + value + operatorSuffix);
m_tableHeader->setFilter(column, filterOperator + value + operatorSuffix);
}
void ExtendedTableWidget::duplicateUpperCell()
@@ -995,7 +996,7 @@ void ExtendedTableWidget::sortByColumns(const std::vector<sqlb::SortedColumn>& c
// Are we using a SqliteTableModel as a model? These support multiple sort columns. Other models might not; for those we just use the first sort column
SqliteTableModel* sqlite_model = dynamic_cast<SqliteTableModel*>(model());
if(sqlite_model == nullptr)
model()->sort(columns.front().column, columns.front().direction == sqlb::Ascending ? Qt::AscendingOrder : Qt::DescendingOrder);
model()->sort(static_cast<int>(columns.front().column), columns.front().direction == sqlb::Ascending ? Qt::AscendingOrder : Qt::DescendingOrder);
else
sqlite_model->sort(columns);
}
+2 -2
View File
@@ -22,14 +22,14 @@ FilterTableHeader::FilterTableHeader(QTableView* parent) :
setContextMenuPolicy(Qt::CustomContextMenu);
}
void FilterTableHeader::generateFilters(int number, bool showFirst)
void FilterTableHeader::generateFilters(size_t number, bool showFirst)
{
// Delete all the current filter widgets
qDeleteAll(filterWidgets);
filterWidgets.clear();
// And generate a bunch of new ones
for(int i=0;i < number; ++i)
for(size_t i=0;i < number; ++i)
{
FilterLineEdit* l = new FilterLineEdit(this, &filterWidgets, i);
if(!showFirst && i == 0) // This hides the first input widget which belongs to the hidden rowid column
+1 -1
View File
@@ -18,7 +18,7 @@ public:
bool hasFilters() const {return (filterWidgets.size() > 0);}
public slots:
void generateFilters(int number, bool showFirst = false);
void generateFilters(size_t number, bool showFirst = false);
void adjustPositions();
void clearFilters();
void setFilter(size_t column, const QString& value);
+18 -17
View File
@@ -4,6 +4,7 @@
#include "csvparser.h"
#include "sqlite.h"
#include "Settings.h"
#include "Data.h"
#include <QMessageBox>
#include <QProgressDialog>
@@ -42,10 +43,7 @@ ImportCsvDialog::ImportCsvDialog(const QStringList &filenames, DBBrowserDB* db,
ui->editName->setText(file.baseName());
// Create a list of all available encodings and create an auto completion list from them
QStringList encodingList;
for(const QByteArray& enc : QTextCodec::availableCodecs())
encodingList.push_back(enc);
encodingCompleter = new QCompleter(encodingList, this);
encodingCompleter = new QCompleter(toStringList(QTextCodec::availableCodecs()), this);
encodingCompleter->setCaseSensitivity(Qt::CaseInsensitive);
ui->editCustomEncoding->setCompleter(encodingCompleter);
@@ -125,7 +123,7 @@ void rollback(
class CSVImportProgress : public CSVProgress
{
public:
explicit CSVImportProgress(unsigned long long filesize)
explicit CSVImportProgress(int64_t filesize)
: totalFileSize(filesize)
{
m_pProgressDlg = new QProgressDialog(
@@ -136,6 +134,9 @@ public:
m_pProgressDlg->setWindowModality(Qt::ApplicationModal);
}
CSVImportProgress(const CSVImportProgress&) = delete;
bool operator=(const CSVImportProgress&) = delete;
~CSVImportProgress() override
{
delete m_pProgressDlg;
@@ -146,7 +147,7 @@ public:
m_pProgressDlg->show();
}
bool update(unsigned long long pos) override
bool update(int64_t pos) override
{
m_pProgressDlg->setValue(static_cast<int>((static_cast<float>(pos) / static_cast<float>(totalFileSize)) * 10000.0f));
qApp->processEvents();
@@ -162,7 +163,7 @@ public:
private:
QProgressDialog* m_pProgressDlg;
unsigned long long totalFileSize;
int64_t totalFileSize;
};
void ImportCsvDialog::accept()
@@ -265,17 +266,17 @@ void ImportCsvDialog::updatePreview()
{
// Generate vertical header items
if(i == 0)
ui->tablePreview->setVerticalHeaderItem(rowNum, new QTableWidgetItem(QString::number(rowNum + 1)));
ui->tablePreview->setVerticalHeaderItem(static_cast<int>(rowNum), new QTableWidgetItem(QString::number(rowNum + 1)));
// Add table item. Limit data length to a maximum character count to avoid a sluggish UI. And it's very unlikely that this
// many characters are going to be needed anyway for a preview.
int data_length = data.fields[i].data_length;
uint64_t data_length = data.fields[i].data_length;
if(data_length > 1024)
data_length = 1024;
ui->tablePreview->setItem(
rowNum,
i,
new QTableWidgetItem(QString::fromUtf8(data.fields[i].data, data_length)));
static_cast<int>(rowNum),
static_cast<int>(i),
new QTableWidgetItem(QString::fromUtf8(data.fields[i].data, static_cast<int>(data_length))));
}
return true;
@@ -401,7 +402,7 @@ sqlb::FieldVector ImportCsvDialog::generateFieldList(const QString& filename)
if(rowNum == 0 && ui->checkboxHeader->isChecked())
{
// Take field name from CSV and remove invalid characters
fieldname = QString::fromUtf8(data.fields[i].data, data.fields[i].data_length);
fieldname = QString::fromUtf8(data.fields[i].data, static_cast<int>(data.fields[i].data_length));
fieldname.replace("`", "");
fieldname.replace(" ", "");
fieldname.replace('"', "");
@@ -429,7 +430,7 @@ sqlb::FieldVector ImportCsvDialog::generateFieldList(const QString& filename)
std::string old_type = fieldList.at(i).type();
if(old_type != "TEXT")
{
QString content = QString::fromUtf8(data.fields[i].data, data.fields[i].data_length);
QString content = QString::fromUtf8(data.fields[i].data, static_cast<int>(data.fields[i].data_length));
// Check if the content can be converted to an integer or to float
bool convert_to_int, convert_to_float;
@@ -635,7 +636,7 @@ bool ImportCsvDialog::importCsv(const QString& fileName, const QString& name)
{
// Empty values need special treatment
// When importing into an existing table where we could find out something about its table definition
if(importToExistingTable && data.fields[i].data_length == 0 && static_cast<size_t>(nullValues.size()) > i)
if(importToExistingTable && data.fields[i].data_length == 0 && nullValues.size() > i)
{
// Do we want to fail when trying to import an empty value into this field? Then exit with an error.
if(failOnMissingFieldList.at(i))
@@ -644,13 +645,13 @@ bool ImportCsvDialog::importCsv(const QString& fileName, const QString& name)
// This is an empty value. We'll need to look up how to handle it depending on the field to be inserted into.
const QByteArray& val = nullValues.at(i);
if(!val.isNull()) // No need to bind NULL values here as that is the default bound value in SQLite
sqlite3_bind_text(stmt, i+1, val, val.size(), SQLITE_STATIC);
sqlite3_bind_text(stmt, static_cast<int>(i)+1, val, val.size(), SQLITE_STATIC);
// When importing into a new table, use the missing values setting directly
} else if(!importToExistingTable && data.fields[i].data_length == 0) {
// No need to bind NULL values here as that is the default bound value in SQLite
} else {
// This is a non-empty value, or we want to insert the empty string. Just add it to the statement
sqlite3_bind_text(stmt, i+1, data.fields[i].data, data.fields[i].data_length, SQLITE_STATIC);
sqlite3_bind_text(stmt, static_cast<int>(i)+1, data.fields[i].data, static_cast<int>(data.fields[i].data_length), SQLITE_STATIC);
}
}
+6 -6
View File
@@ -809,7 +809,7 @@ void MainWindow::populateTable()
const sqlb::FieldInfoList& tablefields = db.getObjectByName(tablename)->fieldInformation();
for(size_t i=0; i<tablefields.size(); ++i)
{
QString format = storedData.displayFormats[i+1];
QString format = storedData.displayFormats[static_cast<int>(i)+1];
if(format.size())
{
query.selectedColumns().emplace_back(tablefields.at(i).name, format.toStdString());
@@ -884,7 +884,7 @@ void MainWindow::applyBrowseTableSettings(BrowseDataTableSettings storedData, bo
FilterTableHeader* filterHeader = qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader());
bool oldState = filterHeader->blockSignals(true);
for(auto filterIt=storedData.filterValues.constBegin();filterIt!=storedData.filterValues.constEnd();++filterIt)
filterHeader->setFilter(filterIt.key(), filterIt.value());
filterHeader->setFilter(static_cast<size_t>(filterIt.key()), filterIt.value());
// Conditional formats
for(auto formatIt=storedData.condFormats.constBegin(); formatIt!=storedData.condFormats.constEnd(); ++formatIt)
@@ -3388,7 +3388,7 @@ void MainWindow::jumpToRow(const sqlb::ObjectIdentifier& table, QString column,
populateTable();
// Set filter
ui->dataTable->filterHeader()->setFilter(column_index-obj->fields.begin()+1, QString("=") + value);
ui->dataTable->filterHeader()->setFilter(static_cast<size_t>(column_index-obj->fields.begin()+1), QString("=") + value);
}
void MainWindow::showDataColumnPopupMenu(const QPoint& pos)
@@ -3460,9 +3460,9 @@ void MainWindow::editDataColumnDisplayFormat()
int field_number = sender()->property("clicked_column").toInt();
QString field_name;
if (db.getObjectByName(current_table)->type() == sqlb::Object::Table)
field_name = QString::fromStdString(db.getObjectByName<sqlb::Table>(current_table)->fields.at(field_number-1).name());
field_name = QString::fromStdString(db.getObjectByName<sqlb::Table>(current_table)->fields.at(static_cast<size_t>(field_number)-1).name());
else
field_name = QString::fromStdString(db.getObjectByName<sqlb::View>(current_table)->fieldNames().at(field_number-1));
field_name = QString::fromStdString(db.getObjectByName<sqlb::View>(current_table)->fieldNames().at(static_cast<size_t>(field_number)-1));
// Get the current display format of the field
QString current_displayformat = browseTableSettings[current_table].displayFormats[field_number];
@@ -3512,7 +3512,7 @@ void MainWindow::showRowidColumn(bool show, bool skipFilters)
// Update the filter row
if(!skipFilters)
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->generateFilters(m_browseTableModel->columnCount(), show);
qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader())->generateFilters(static_cast<size_t>(m_browseTableModel->columnCount()), show);
// Re-enable signals
ui->dataTable->horizontalHeader()->blockSignals(false);
+1 -1
View File
@@ -318,7 +318,7 @@ void PlotDock::updatePlot(SqliteTableModel* model, BrowseDataTableSettings* sett
case QVariant::Date: {
QString s = model->data(model->index(j, x)).toString();
QDateTime d = QDateTime::fromString(s, Qt::ISODate);
xdata[j] = d.toMSecsSinceEpoch() / 1000.0;
xdata[j] = static_cast<double>(d.toMSecsSinceEpoch()) / 1000.0;
break;
}
case QVariant::Time: {
+1 -9
View File
@@ -256,15 +256,7 @@ void RemoteDatabase::gotReply(QNetworkReply* reply)
void RemoteDatabase::gotError(QNetworkReply* reply, const QList<QSslError>& errors)
{
// Are there any errors in here that aren't about self-signed certificates and non-matching hostnames?
bool serious_errors = false;
for(const QSslError& error : errors)
{
if(error.error() != QSslError::SelfSignedCertificate)
{
serious_errors = true;
break;
}
}
bool serious_errors = std::any_of(errors.begin(), errors.end(), [](const QSslError& error) { return error.error() != QSslError::SelfSignedCertificate; });
// Just stop the error checking here and accept the reply if there were no 'serious' errors
if(!serious_errors)
+1 -1
View File
@@ -233,7 +233,7 @@ QVariant RemoteModel::data(const QModelIndex& index, int role) const
return QVariant();
// Convert size to human readable format
float size = item->value(RemoteModelColumnSize).toLongLong();
float size = item->value(RemoteModelColumnSize).toFloat();
QStringList list;
list << "KiB" << "MiB" << "GiB" << "TiB";
QStringListIterator it(list);
+1 -1
View File
@@ -59,7 +59,7 @@ void RowLoader::triggerRowCountDetermination(int token)
if(nrows >= 0)
emit rowCountComplete(token, nrows);
std::lock_guard<std::mutex> lk(m);
std::lock_guard<std::mutex> lk2(m);
nosync_taskDone();
});
}
+1 -1
View File
@@ -149,7 +149,7 @@ bool RunSql::executeNextStatement()
int sql3status = sqlite3_prepare_v2(pDb.get(), tail, tail_length, &vm, &tail);
QString queryPart = QString::fromUtf8(qbegin, static_cast<int>(tail - qbegin));
int tail_length_before = tail_length;
tail_length -= (tail - qbegin);
tail_length -= static_cast<int>(tail - qbegin);
int end_of_current_statement_position = execute_current_position + tail_length_before - tail_length;
// Save remaining statements
+1 -1
View File
@@ -140,7 +140,7 @@ CSVParser::ParserResult CSVParser::parse(csvRowFunction insertFunction, QTextStr
};
FieldBufferDealloc dealloc(record);
qint64 bufferPos = 0;
int64_t bufferPos = 0;
while(!stream.atEnd())
{
sBuffer = stream.read(m_nBufferSize).toUtf8();
+2 -2
View File
@@ -18,7 +18,7 @@ public:
virtual ~CSVProgress() { }
virtual void start() = 0;
virtual bool update(unsigned long long pos) = 0;
virtual bool update(int64_t pos) = 0;
virtual void end() = 0;
};
@@ -88,7 +88,7 @@ private:
char m_cQuoteChar;
CSVProgress* m_pCSVProgress;
unsigned long m_nBufferSize; //! internal buffer read size
int64_t m_nBufferSize; //! internal buffer read size
};
#endif
+5 -5
View File
@@ -57,16 +57,16 @@ int collCompare(void* /*pArg*/, int sizeA, const void* sA, int sizeB, const void
static int sqlite_compare_utf16( void* /*arg*/,int size1, const void *str1, int size2, const void* str2)
{
const QString string1 = QString::fromRawData(reinterpret_cast<const QChar*>(str1), size1 / sizeof(QChar));
const QString string2 = QString::fromRawData(reinterpret_cast<const QChar*>(str2), size2 / sizeof(QChar));
const QString string1 = QString::fromRawData(reinterpret_cast<const QChar*>(str1), static_cast<int>(static_cast<size_t>(size1) / sizeof(QChar)));
const QString string2 = QString::fromRawData(reinterpret_cast<const QChar*>(str2), static_cast<int>(static_cast<size_t>(size2) / sizeof(QChar)));
return QString::compare(string1, string2, Qt::CaseSensitive);
}
static int sqlite_compare_utf16ci( void* /*arg*/,int size1, const void *str1, int size2, const void* str2)
{
const QString string1 = QString::fromRawData(reinterpret_cast<const QChar*>(str1), size1 / sizeof(QChar));
const QString string2 = QString::fromRawData(reinterpret_cast<const QChar*>(str2), size2 / sizeof(QChar));
const QString string1 = QString::fromRawData(reinterpret_cast<const QChar*>(str1), static_cast<int>(static_cast<size_t>(size1) / sizeof(QChar)));
const QString string2 = QString::fromRawData(reinterpret_cast<const QChar*>(str2), static_cast<int>(static_cast<size_t>(size2) / sizeof(QChar)));
return QString::compare(string1, string2, Qt::CaseInsensitive);
}
@@ -81,7 +81,7 @@ static void sqlite_make_single_value(sqlite3_context* ctx, int num_arguments, sq
char* output_str = new char[output.size()+1];
std::strcpy(output_str, output.c_str());
sqlite3_result_text(ctx, output_str, output.length(), [](void* ptr) {
sqlite3_result_text(ctx, output_str, static_cast<int>(output.length()), [](void* ptr) {
char* cptr = static_cast<char*>(ptr);
delete cptr;
});
+41 -37
View File
@@ -66,7 +66,7 @@ void SqliteTableModel::handleFinishedFetch (int life_id, unsigned int fetched_ro
if(new_row_count != old_row_count)
{
beginInsertRows(QModelIndex(), old_row_count, new_row_count - 1);
beginInsertRows(QModelIndex(), static_cast<int>(old_row_count), static_cast<int>(new_row_count - 1));
m_currentRowCount = new_row_count;
endInsertRows();
}
@@ -75,13 +75,13 @@ void SqliteTableModel::handleFinishedFetch (int life_id, unsigned int fetched_ro
{
// TODO optimize
size_t num_columns = m_headers.size();
emit dataChanged(createIndex(fetched_row_begin, 0), createIndex(fetched_row_end - 1, num_columns - 1));
emit dataChanged(createIndex(static_cast<int>(fetched_row_begin), 0), createIndex(static_cast<int>(fetched_row_end) - 1, static_cast<int>(num_columns) - 1));
}
if(m_rowCountAvailable != RowCount::Complete)
m_rowCountAvailable = RowCount::Partial;
emit finishedFetch(fetched_row_begin, fetched_row_end);
emit finishedFetch(static_cast<int>(fetched_row_begin), static_cast<int>(fetched_row_end));
}
void SqliteTableModel::handleRowCountComplete (int life_id, int num_rows)
@@ -90,7 +90,7 @@ void SqliteTableModel::handleRowCountComplete (int life_id, int num_rows)
return;
m_rowCountAvailable = RowCount::Complete;
handleFinishedFetch(life_id, num_rows, num_rows);
handleFinishedFetch(life_id, static_cast<unsigned int>(num_rows), static_cast<unsigned int>(num_rows));
emit finishedRowCount();
}
@@ -299,9 +299,11 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
bool row_available;
const Row * cached_row;
if(m_cache.count(index.row()))
const size_t row = static_cast<size_t>(index.row());
const size_t column = static_cast<size_t>(index.column());
if(m_cache.count(row))
{
cached_row = &m_cache.at(index.row());
cached_row = &m_cache.at(row);
row_available = true;
} else {
blank_data = makeDefaultCacheEntry();
@@ -313,14 +315,14 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
{
if(!row_available)
return tr("loading...");
if(role == Qt::DisplayRole && cached_row->at(index.column()).isNull())
if(role == Qt::DisplayRole && cached_row->at(column).isNull())
{
return Settings::getValue("databrowser", "null_text").toString();
} else if(role == Qt::DisplayRole && nosync_isBinary(index)) {
return Settings::getValue("databrowser", "blob_text").toString();
} else if(role == Qt::DisplayRole) {
int limit = Settings::getValue("databrowser", "symbol_limit").toInt();
QByteArray displayText = cached_row->at(index.column());
QByteArray displayText = cached_row->at(column);
if (displayText.length() > limit) {
// Add "..." to the end of truncated strings
return decode(displayText.left(limit).append(" ..."));
@@ -328,22 +330,22 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
return decode(displayText);
}
} else {
return decode(cached_row->at(index.column()));
return decode(cached_row->at(column));
}
} else if(role == Qt::FontRole) {
QFont font;
if(!row_available || cached_row->at(index.column()).isNull() || nosync_isBinary(index))
if(!row_available || cached_row->at(column).isNull() || nosync_isBinary(index))
font.setItalic(true);
return font;
} else if(role == Qt::ForegroundRole) {
if(!row_available)
return QColor(100, 100, 100);
if(cached_row->at(index.column()).isNull())
if(cached_row->at(column).isNull())
return QColor(Settings::getValue("databrowser", "null_fg_colour").toString());
else if (nosync_isBinary(index))
return QColor(Settings::getValue("databrowser", "bin_fg_colour").toString());
else if (m_mCondFormats.contains(index.column())) {
QString value = cached_row->at(index.column());
QString value = cached_row->at(column);
// Unlock before querying from DB
lock.unlock();
QColor condFormatColor = getMatchingCondFormatColor(index.column(), value, role);
@@ -355,12 +357,12 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
} else if (role == Qt::BackgroundRole) {
if(!row_available)
return QColor(255, 200, 200);
if(cached_row->at(index.column()).isNull())
if(cached_row->at(column).isNull())
return QColor(Settings::getValue("databrowser", "null_bg_colour").toString());
else if (nosync_isBinary(index))
return QColor(Settings::getValue("databrowser", "bin_bg_colour").toString());
else if (m_mCondFormats.contains(index.column())) {
QString value = cached_row->at(index.column());
QString value = cached_row->at(column);
// Unlock before querying from DB
lock.unlock();
QColor condFormatColor = getMatchingCondFormatColor(index.column(), value, role);
@@ -406,7 +408,7 @@ sqlb::ForeignKeyClause SqliteTableModel::getForeignKeyClause(int column) const
// Note that the rowid column has number -1 here, it can safely be excluded since there will never be a
// foreign key on that column.
sqlb::ConstraintPtr ptr = tbl->constraint({tbl->fields.at(column).name()}, sqlb::Constraint::ForeignKeyConstraintType);
sqlb::ConstraintPtr ptr = tbl->constraint({tbl->fields.at(static_cast<size_t>(column)).name()}, sqlb::Constraint::ForeignKeyConstraintType);
if(ptr)
return *(std::dynamic_pointer_cast<sqlb::ForeignKeyClause>(ptr));
}
@@ -436,10 +438,11 @@ bool SqliteTableModel::setTypedData(const QModelIndex& index, bool isBlob, const
{
QMutexLocker lock(&m_mutexDataCache);
auto & cached_row = m_cache.at(index.row());
auto & cached_row = m_cache.at(static_cast<size_t>(index.row()));
const size_t column = static_cast<size_t>(index.column());
QByteArray newValue = encode(value.toByteArray());
QByteArray oldValue = cached_row.at(index.column());
QByteArray oldValue = cached_row.at(column);
// Special handling for integer columns: instead of setting an integer column to an empty string, set it to '0' when it is also
// used in a primary key. Otherwise SQLite will always output an 'datatype mismatch' error.
@@ -448,7 +451,7 @@ bool SqliteTableModel::setTypedData(const QModelIndex& index, bool isBlob, const
sqlb::TablePtr table = m_db.getObjectByName<sqlb::Table>(m_query.table());
if(table)
{
auto field = sqlb::findField(table, m_headers.at(index.column()));
auto field = sqlb::findField(table, m_headers.at(column));
if(contains(table->primaryKey(), field->name()) && field->isInteger())
newValue = "0";
}
@@ -459,10 +462,10 @@ bool SqliteTableModel::setTypedData(const QModelIndex& index, bool isBlob, const
if(oldValue == newValue && oldValue.isNull() == newValue.isNull())
return true;
if(m_db.updateRecord(m_query.table(), m_headers.at(index.column()), cached_row.at(0), newValue, isBlob, m_query.rowIdColumns()))
if(m_db.updateRecord(m_query.table(), m_headers.at(column), cached_row.at(0), newValue, isBlob, m_query.rowIdColumns()))
{
cached_row[index.column()] = newValue;
if(m_headers.at(index.column()) == sqlb::joinStringVector(m_query.rowIdColumns(), ",")) {
cached_row[column] = newValue;
if(m_headers.at(column) == sqlb::joinStringVector(m_query.rowIdColumns(), ",")) {
cached_row[0] = newValue;
const QModelIndex& rowidIndex = index.sibling(index.row(), 0);
lock.unlock();
@@ -494,7 +497,7 @@ Qt::ItemFlags SqliteTableModel::flags(const QModelIndex& index) const
if(m_query.selectedColumns().size())
{
if(index.column() > 0)
custom_display_format = QString::fromStdString(m_query.selectedColumns().at(index.column()-1).selector) != sqlb::escapeIdentifier(headerData(index.column(), Qt::Horizontal).toString());
custom_display_format = QString::fromStdString(m_query.selectedColumns().at(static_cast<size_t>(index.column())-1).selector) != sqlb::escapeIdentifier(headerData(index.column(), Qt::Horizontal).toString());
}
if(!isBinary(index) && !custom_display_format)
@@ -574,9 +577,9 @@ bool SqliteTableModel::insertRows(int row, int count, const QModelIndex& parent)
}
beginInsertRows(parent, row, row + count - 1);
for(unsigned int i = 0; i < tempList.size(); ++i)
for(size_t i = 0; i < tempList.size(); ++i)
{
m_cache.insert(i + row, std::move(tempList.at(i)));
m_cache.insert(i + static_cast<size_t>(row), std::move(tempList.at(i)));
m_currentRowCount++;
}
endInsertRows();
@@ -597,8 +600,8 @@ bool SqliteTableModel::removeRows(int row, int count, const QModelIndex& parent)
QStringList rowids;
for(int i=count-1;i>=0;i--)
{
if(m_cache.count(row+i)) {
rowids.append(m_cache.at(row + i).at(0));
if(m_cache.count(static_cast<size_t>(row+i))) {
rowids.append(m_cache.at(static_cast<size_t>(row + i)).at(0));
}
}
@@ -609,7 +612,7 @@ bool SqliteTableModel::removeRows(int row, int count, const QModelIndex& parent)
for(int i=count-1;i>=0;i--)
{
m_cache.erase(row + i);
m_cache.erase(static_cast<size_t>(row + i));
m_currentRowCount--;
}
@@ -626,7 +629,7 @@ QModelIndex SqliteTableModel::dittoRecord(int old_row)
if (!insertRow(rowCount()))
return QModelIndex();
int firstEditedColumn = 0;
size_t firstEditedColumn = 0;
int new_row = rowCount() - 1;
sqlb::TablePtr t = m_db.getObjectByName<sqlb::Table>(m_query.table());
@@ -637,12 +640,12 @@ QModelIndex SqliteTableModel::dittoRecord(int old_row)
if (!firstEditedColumn)
firstEditedColumn = col + 1;
QVariant value = data(index(old_row, col + 1), Qt::EditRole);
setData(index(new_row, col + 1), value);
QVariant value = data(index(old_row, static_cast<int>(col + 1)), Qt::EditRole);
setData(index(new_row, static_cast<int>(col + 1)), value);
}
}
return index(new_row, firstEditedColumn);
return index(new_row, static_cast<int>(firstEditedColumn));
}
void SqliteTableModel::buildQuery()
@@ -756,9 +759,9 @@ void SqliteTableModel::updateFilter(int column, const QString& value)
// If the value was set to an empty string remove any filter for this column. Otherwise insert a new filter rule or replace the old one if there is already one
if(whereClause.isEmpty())
m_query.where().erase(column);
m_query.where().erase(static_cast<size_t>(column));
else
m_query.where()[column] = whereClause.toStdString();
m_query.where()[static_cast<size_t>(column)] = whereClause.toStdString();
// Build the new query
buildQuery();
@@ -775,7 +778,7 @@ void SqliteTableModel::clearCache()
if(m_currentRowCount > 0)
{
beginRemoveRows(QModelIndex(), 0, m_currentRowCount - 1);
beginRemoveRows(QModelIndex(), 0, static_cast<int>(m_currentRowCount - 1));
endRemoveRows();
}
@@ -792,12 +795,13 @@ bool SqliteTableModel::isBinary(const QModelIndex& index) const
bool SqliteTableModel::nosync_isBinary(const QModelIndex& index) const
{
if(!m_cache.count(index.row()))
const size_t row = static_cast<size_t>(index.row());
if(!m_cache.count(row))
return false;
const auto & cached_row = m_cache.at(index.row());
const auto & cached_row = m_cache.at(row);
return !isTextOnly(cached_row.at(index.column()), m_encoding, true);
return !isTextOnly(cached_row.at(static_cast<size_t>(index.column())), m_encoding, true);
}
QByteArray SqliteTableModel::encode(const QByteArray& str) const