diff --git a/src/AddRecordDialog.cpp b/src/AddRecordDialog.cpp index f6784ee1..190d1c55 100644 --- a/src/AddRecordDialog.cpp +++ b/src/AddRecordDialog.cpp @@ -112,12 +112,12 @@ public: } }; -AddRecordDialog::AddRecordDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, QWidget* parent, const std::vector& pseudo_pk) +AddRecordDialog::AddRecordDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier& tableName, QWidget* parent, const std::vector& _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); diff --git a/src/CondFormat.cpp b/src/CondFormat.cpp index 3b76bf80..1f963576 100644 --- a/src/CondFormat.cpp +++ b/src/CondFormat.cpp @@ -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) { diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index e1279276..973d0e98 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -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); } diff --git a/src/EditDialog.h b/src/EditDialog.h index b814d048..9b54a240 100644 --- a/src/EditDialog.h +++ b/src/EditDialog.h @@ -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); }; diff --git a/src/EditIndexDialog.cpp b/src/EditIndexDialog.cpp index 467888f6..da041486 100644 --- a/src/EditIndexDialog.cpp +++ b/src/EditIndexDialog.cpp @@ -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(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(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(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(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(currentRow)], index.fields[static_cast(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(std::distance(index.fields.begin(), field_it)); if(field_it == index.fields.end()) { // There is no empty expression column yet, so add one. diff --git a/src/EditTableDialog.cpp b/src/EditTableDialog.cpp index 607cdae5..60e6ce96 100644 --- a/src/EditTableDialog.cpp +++ b/src/EditTableDialog.cpp @@ -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(m_table.fields.size())) + size_t index = static_cast(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(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(newRow)], m_table.fields[static_cast(currentRow)]); // Update the SQL preview updateSqlText(); diff --git a/src/ExportDataDialog.cpp b/src/ExportDataDialog.cpp index c8dd5fb5..2ac0f66a 100644 --- a/src/ExportDataDialog.cpp +++ b/src/ExportDataDialog.cpp @@ -225,7 +225,7 @@ bool ExportDataDialog::exportQueryJson(const QString& sQuery, const QString& sFi for(int i=0;i(i)]; switch (type) { case SQLITE_INTEGER: { diff --git a/src/ExtendedScintilla.cpp b/src/ExtendedScintilla.cpp index a928185a..99ba8e86 100644 --- a/src/ExtendedScintilla.cpp +++ b/src/ExtendedScintilla.cpp @@ -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(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(SendScintilla(QsciScintillaBase::SCI_GETCOLUMN, position)); + int line = static_cast(SendScintilla(QsciScintillaBase::SCI_LINEFROMPOSITION, position)); fillIndicatorRange(line, column, line+1, 0, errorIndicatorNumber); } diff --git a/src/ExtendedTableWidget.cpp b/src/ExtendedTableWidget.cpp index 62042592..9d62cf11 100644 --- a/src/ExtendedTableWidget.cpp +++ b/src/ExtendedTableWidget.cpp @@ -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(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(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& 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(model()); if(sqlite_model == nullptr) - model()->sort(columns.front().column, columns.front().direction == sqlb::Ascending ? Qt::AscendingOrder : Qt::DescendingOrder); + model()->sort(static_cast(columns.front().column), columns.front().direction == sqlb::Ascending ? Qt::AscendingOrder : Qt::DescendingOrder); else sqlite_model->sort(columns); } diff --git a/src/FilterTableHeader.cpp b/src/FilterTableHeader.cpp index 06592315..9e4d4bac 100644 --- a/src/FilterTableHeader.cpp +++ b/src/FilterTableHeader.cpp @@ -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 diff --git a/src/FilterTableHeader.h b/src/FilterTableHeader.h index 6dedcfbe..7b933099 100644 --- a/src/FilterTableHeader.h +++ b/src/FilterTableHeader.h @@ -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); diff --git a/src/ImportCsvDialog.cpp b/src/ImportCsvDialog.cpp index be56eea6..e859a0d0 100644 --- a/src/ImportCsvDialog.cpp +++ b/src/ImportCsvDialog.cpp @@ -4,6 +4,7 @@ #include "csvparser.h" #include "sqlite.h" #include "Settings.h" +#include "Data.h" #include #include @@ -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((static_cast(pos) / static_cast(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(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(rowNum), + static_cast(i), + new QTableWidgetItem(QString::fromUtf8(data.fields[i].data, static_cast(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(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(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(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(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(i)+1, data.fields[i].data, static_cast(data.fields[i].data_length), SQLITE_STATIC); } } diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index ad50c184..65f76063 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -809,7 +809,7 @@ void MainWindow::populateTable() const sqlb::FieldInfoList& tablefields = db.getObjectByName(tablename)->fieldInformation(); for(size_t i=0; i(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(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(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(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(current_table)->fields.at(field_number-1).name()); + field_name = QString::fromStdString(db.getObjectByName(current_table)->fields.at(static_cast(field_number)-1).name()); else - field_name = QString::fromStdString(db.getObjectByName(current_table)->fieldNames().at(field_number-1)); + field_name = QString::fromStdString(db.getObjectByName(current_table)->fieldNames().at(static_cast(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(ui->dataTable->horizontalHeader())->generateFilters(m_browseTableModel->columnCount(), show); + qobject_cast(ui->dataTable->horizontalHeader())->generateFilters(static_cast(m_browseTableModel->columnCount()), show); // Re-enable signals ui->dataTable->horizontalHeader()->blockSignals(false); diff --git a/src/PlotDock.cpp b/src/PlotDock.cpp index 7878436e..9ca338e9 100644 --- a/src/PlotDock.cpp +++ b/src/PlotDock.cpp @@ -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(d.toMSecsSinceEpoch()) / 1000.0; break; } case QVariant::Time: { diff --git a/src/RemoteDatabase.cpp b/src/RemoteDatabase.cpp index 63c2818e..74b75588 100644 --- a/src/RemoteDatabase.cpp +++ b/src/RemoteDatabase.cpp @@ -256,15 +256,7 @@ void RemoteDatabase::gotReply(QNetworkReply* reply) void RemoteDatabase::gotError(QNetworkReply* reply, const QList& 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) diff --git a/src/RemoteModel.cpp b/src/RemoteModel.cpp index 1e7ac605..4a851f08 100644 --- a/src/RemoteModel.cpp +++ b/src/RemoteModel.cpp @@ -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); diff --git a/src/RowLoader.cpp b/src/RowLoader.cpp index ecfec6eb..4f9cb61e 100644 --- a/src/RowLoader.cpp +++ b/src/RowLoader.cpp @@ -59,7 +59,7 @@ void RowLoader::triggerRowCountDetermination(int token) if(nrows >= 0) emit rowCountComplete(token, nrows); - std::lock_guard lk(m); + std::lock_guard lk2(m); nosync_taskDone(); }); } diff --git a/src/RunSql.cpp b/src/RunSql.cpp index 1b848a37..a5a91210 100644 --- a/src/RunSql.cpp +++ b/src/RunSql.cpp @@ -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(tail - qbegin)); int tail_length_before = tail_length; - tail_length -= (tail - qbegin); + tail_length -= static_cast(tail - qbegin); int end_of_current_statement_position = execute_current_position + tail_length_before - tail_length; // Save remaining statements diff --git a/src/csvparser.cpp b/src/csvparser.cpp index 019a4ef2..82b54ca2 100644 --- a/src/csvparser.cpp +++ b/src/csvparser.cpp @@ -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(); diff --git a/src/csvparser.h b/src/csvparser.h index 3547b2e7..38d3a44b 100644 --- a/src/csvparser.h +++ b/src/csvparser.h @@ -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 diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 410c3cab..a3c39012 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -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(str1), size1 / sizeof(QChar)); - const QString string2 = QString::fromRawData(reinterpret_cast(str2), size2 / sizeof(QChar)); + const QString string1 = QString::fromRawData(reinterpret_cast(str1), static_cast(static_cast(size1) / sizeof(QChar))); + const QString string2 = QString::fromRawData(reinterpret_cast(str2), static_cast(static_cast(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(str1), size1 / sizeof(QChar)); - const QString string2 = QString::fromRawData(reinterpret_cast(str2), size2 / sizeof(QChar)); + const QString string1 = QString::fromRawData(reinterpret_cast(str1), static_cast(static_cast(size1) / sizeof(QChar))); + const QString string2 = QString::fromRawData(reinterpret_cast(str2), static_cast(static_cast(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(output.length()), [](void* ptr) { char* cptr = static_cast(ptr); delete cptr; }); diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index 50f2b0f3..f4a3cb4b 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -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(old_row_count), static_cast(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(fetched_row_begin), 0), createIndex(static_cast(fetched_row_end) - 1, static_cast(num_columns) - 1)); } if(m_rowCountAvailable != RowCount::Complete) m_rowCountAvailable = RowCount::Partial; - emit finishedFetch(fetched_row_begin, fetched_row_end); + emit finishedFetch(static_cast(fetched_row_begin), static_cast(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(num_rows), static_cast(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(index.row()); + const size_t column = static_cast(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(column)).name()}, sqlb::Constraint::ForeignKeyConstraintType); if(ptr) return *(std::dynamic_pointer_cast(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(index.row())); + const size_t column = static_cast(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(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(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(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(row+i))) { + rowids.append(m_cache.at(static_cast(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(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(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(col + 1)), Qt::EditRole); + setData(index(new_row, static_cast(col + 1)), value); } } - return index(new_row, firstEditedColumn); + return index(new_row, static_cast(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(column)); else - m_query.where()[column] = whereClause.toStdString(); + m_query.where()[static_cast(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(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(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(index.column())), m_encoding, true); } QByteArray SqliteTableModel::encode(const QByteArray& str) const