Shadowed Variable Warnings (#1864)

Compile with ALL_WARNINGS using GCC 8.2.1.
Encountered approximately dozen warnings with this pattern:

    [path to sqlitebrowser root]/src/[somesourcefile]:line:cursor: warning: declaration
	of ‘data’ shadows a member of ‘ClassName’ [-Wshadow]
            OtherDataType data = ....line of code at line given above...
                          ^~~~
    In file included from /usr/include/qt5/QtWidgets/qdialog.h:44,
                     from /usr/include/qt5/QtWidgets/QDialog:1,
                     ...other sources in project
    /usr/include/qt5/QtWidgets/qwidget.h:733:18: note: shadowed declaration is here
         QWidgetData *data;
                      ^~~~

It appears there is a variable named 'data' within Qt global scope. Using 'data`
as a variable name, even one limited in scope to small lamda expressions, causes
compiler some grief.

Commit resolves the warnings in affected files. No problems apparent during execution.
Requires CSV stress-testing.
This commit is contained in:
Scott Furry
2019-05-07 14:09:21 -06:00
committed by Martin Kleusberg
parent 800a8daf11
commit d54b820fb2
6 changed files with 70 additions and 70 deletions

View File

@@ -87,9 +87,9 @@ void EditDialog::setCurrentIndex(const QModelIndex& idx)
{
currentIndex = QPersistentModelIndex(idx);
QByteArray data = idx.data(Qt::EditRole).toByteArray();
loadData(data);
updateCellInfoAndMode(data);
QByteArray bArrData = idx.data(Qt::EditRole).toByteArray();
loadData(bArrData);
updateCellInfoAndMode(bArrData);
ui->buttonApply->setDisabled(true);
}
@@ -113,7 +113,7 @@ void EditDialog::reject()
}
// Loads data from a cell into the Edit Cell window
void EditDialog::loadData(const QByteArray& data)
void EditDialog::loadData(const QByteArray& bArrdata)
{
QImage img;
QString textData;
@@ -122,7 +122,7 @@ void EditDialog::loadData(const QByteArray& data)
removedBom.clear();
// Determine the data type, saving that info in the class variable
dataType = checkDataType(data);
dataType = checkDataType(bArrdata);
// Get the current editor mode (eg text, hex, image, json or xml mode)
int editMode = ui->comboMode->currentIndex();
@@ -150,7 +150,7 @@ void EditDialog::loadData(const QByteArray& data)
dataSource = HexBuffer;
// Load the Null into the hex editor
hexEdit->setData(data);
hexEdit->setData(bArrdata);
break;
@@ -162,7 +162,7 @@ void EditDialog::loadData(const QByteArray& data)
ui->editorImage->setPixmap(QPixmap(0,0));
// Load the Null into the hex editor
hexEdit->setData(data);
hexEdit->setData(bArrdata);
break;
}
@@ -177,10 +177,10 @@ void EditDialog::loadData(const QByteArray& data)
case TextEditor:
case JsonEditor:
case XmlEditor:
setDataInBuffer(data, SciBuffer);
setDataInBuffer(bArrdata, SciBuffer);
break;
case HexEditor:
setDataInBuffer(data, HexBuffer);
setDataInBuffer(bArrdata, HexBuffer);
break;
case ImageViewer:
// The image viewer cannot hold data nor display text.
@@ -189,7 +189,7 @@ void EditDialog::loadData(const QByteArray& data)
ui->editorImage->setPixmap(QPixmap(0,0));
// Load the text into the text editor
setDataInBuffer(data, SciBuffer);
setDataInBuffer(bArrdata, SciBuffer);
break;
}
@@ -200,7 +200,7 @@ void EditDialog::loadData(const QByteArray& data)
// stored it in the editorImage widget instead, it would be a pixmap
// and there's no good way to restore that back to the original
// (pristine) image data. eg image metadata would be lost
setDataInBuffer(data, HexBuffer);
setDataInBuffer(bArrdata, HexBuffer);
// Update the display if in text edit or image viewer mode
switch (editMode) {
@@ -217,7 +217,7 @@ void EditDialog::loadData(const QByteArray& data)
case ImageViewer:
// Load the image into the image viewing widget
if (img.loadFromData(data)) {
if (img.loadFromData(bArrdata)) {
ui->editorImage->setPixmap(QPixmap::fromImage(img));
}
break;
@@ -230,21 +230,21 @@ void EditDialog::loadData(const QByteArray& data)
case JsonEditor:
case XmlEditor:
setDataInBuffer(data, SciBuffer);
setDataInBuffer(bArrdata, SciBuffer);
break;
case HexEditor:
setDataInBuffer(data, HexBuffer);
setDataInBuffer(bArrdata, HexBuffer);
break;
case ImageViewer:
// Set data in the XML (Sci) Buffer and load the SVG Image
setDataInBuffer(data, SciBuffer);
setDataInBuffer(bArrdata, SciBuffer);
sciEdit->setLanguage(DockTextEdit::XML);
// Load the image into the image viewing widget
if (img.loadFromData(data)) {
if (img.loadFromData(bArrdata)) {
ui->editorImage->setPixmap(QPixmap::fromImage(img));
}
break;
@@ -257,7 +257,7 @@ void EditDialog::loadData(const QByteArray& data)
// into the hex widget (the only safe place for it)
// Load the data into the hex buffer
setDataInBuffer(data, HexBuffer);
setDataInBuffer(bArrdata, HexBuffer);
switch (editMode) {
case TextEditor:
@@ -555,7 +555,7 @@ void EditDialog::accept()
}
}
void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
void EditDialog::setDataInBuffer(const QByteArray& bArrdata, DataSources source)
{
dataSource = source;
QString textData;
@@ -569,7 +569,7 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
case DockTextEdit::PlainText:
{
// Load the text into the text editor, remove BOM first if there is one
QByteArray dataWithoutBom = data;
QByteArray dataWithoutBom = bArrdata;
removedBom = removeBom(dataWithoutBom);
textData = QString::fromUtf8(dataWithoutBom.constData(), dataWithoutBom.size());
@@ -588,7 +588,7 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
json jsonDoc;
try {
jsonDoc = json::parse(std::string(data.constData(), static_cast<size_t>(data.size())));
jsonDoc = json::parse(std::string(bArrdata.constData(), static_cast<size_t>(bArrdata.size())));
} catch(json::parse_error& parseError) {
sciEdit->setErrorIndicator(static_cast<int>(parseError.byte - 1));
}
@@ -598,7 +598,7 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
textData = QString::fromStdString(jsonDoc.dump(4));
} else {
// Fallback case. The data is not yet valid JSON or no auto-formatting applied.
textData = QString::fromUtf8(data.constData(), data.size());
textData = QString::fromUtf8(bArrdata.constData(), bArrdata.size());
}
sciEdit->setText(textData);
@@ -612,14 +612,14 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
QString errorMsg;
int errorLine, errorColumn;
QDomDocument xmlDoc;
bool isValid = xmlDoc.setContent(data, true, &errorMsg, &errorLine, &errorColumn);
bool isValid = xmlDoc.setContent(bArrdata, true, &errorMsg, &errorLine, &errorColumn);
if (mustIndentAndCompact && isValid) {
// Load indented XML into the XML editor
textData = xmlDoc.toString(Settings::getValue("editor", "tabsize").toInt());
} else {
// Fallback case. The data is not yet valid JSON or no auto-formatting applied.
textData = QString::fromUtf8(data.constData(), data.size());
textData = QString::fromUtf8(bArrdata.constData(), bArrdata.size());
}
sciEdit->setText(textData);
@@ -634,7 +634,7 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
}
break;
case HexBuffer:
hexEdit->setData(data);
hexEdit->setData(bArrdata);
hexEdit->setEnabled(true);
break;
@@ -669,12 +669,12 @@ void EditDialog::editModeChanged(int newMode)
case ImageViewer:
{
// When SVG format, load the image, else clear it.
QByteArray data = sciEdit->text().toUtf8();
dataType = checkDataType(data);
QByteArray bArrdata = sciEdit->text().toUtf8();
dataType = checkDataType(bArrdata);
if (dataType == SVG) {
QImage img;
if (img.loadFromData(data))
if (img.loadFromData(bArrdata))
ui->editorImage->setPixmap(QPixmap::fromImage(img));
else
// Clear any image from the image viewing widget
@@ -729,9 +729,9 @@ void EditDialog::setMustIndentAndCompact(bool enable)
}
// Determine the type of data in the cell
int EditDialog::checkDataType(const QByteArray& data)
int EditDialog::checkDataType(const QByteArray& bArrdata)
{
QByteArray cellData = data;
QByteArray cellData = bArrdata;
// Check for NULL data type
if (cellData.isNull()) {
@@ -840,9 +840,9 @@ void EditDialog::switchEditorMode(bool autoSwitchForType)
// Update the information labels in the bottom left corner of the dialog
// and switches the editor mode, if required, according to the detected data type.
void EditDialog::updateCellInfoAndMode(const QByteArray& data)
void EditDialog::updateCellInfoAndMode(const QByteArray& bArrdata)
{
QByteArray cellData = data;
QByteArray cellData = bArrdata;
switchEditorMode(ui->buttonAutoSwitchMode->isChecked());

View File

@@ -36,12 +36,12 @@ private slots:
void setNull();
void updateApplyButton();
void accept() override;
void loadData(const QByteArray& data);
void loadData(const QByteArray& bArrdata);
void toggleOverwriteMode();
void editModeChanged(int newMode);
void editTextChanged();
void switchEditorMode(bool autoSwitchForType);
void updateCellInfoAndMode(const QByteArray& data);
void updateCellInfoAndMode(const QByteArray& bArrdata);
void setMustIndentAndCompact(bool enable);
void openPrintDialog();
void openPrintImageDialog();
@@ -49,7 +49,7 @@ private slots:
void setWordWrapping(bool value);
signals:
void recordTextUpdated(const QPersistentModelIndex& idx, const QByteArray& data, bool isBlob);
void recordTextUpdated(const QPersistentModelIndex& idx, const QByteArray& bArrdata, bool isBlob);
private:
Ui::EditDialog* ui;
@@ -89,10 +89,10 @@ private:
XmlEditor = 4
};
int checkDataType(const QByteArray& data);
int checkDataType(const QByteArray& bArrdata);
QString humanReadableSize(double byteCount) const;
bool promptInvalidData(const QString& data_type, const QString& errorString);
void setDataInBuffer(const QByteArray& data, DataSources source);
void setDataInBuffer(const QByteArray& bArrdata, DataSources source);
void setStackCurrentIndex(int editMode);
};

View File

@@ -421,9 +421,9 @@ void ExtendedTableWidget::copyMimeData(const QModelIndexList& fromIndices, QMime
// If a single cell is selected which contains an image, copy it to the clipboard
if (!inSQL && !withHeaders && indices.size() == 1) {
QImage img;
QVariant data = m->data(indices.first(), Qt::EditRole);
QVariant varData = m->data(indices.first(), Qt::EditRole);
if (img.loadFromData(data.toByteArray()))
if (img.loadFromData(varData.toByteArray()))
{
// If it's an image, copy the image data to the clipboard
mimeData->setImageData(img);
@@ -516,10 +516,10 @@ void ExtendedTableWidget::copyMimeData(const QModelIndexList& fromIndices, QMime
currentRow = index.row();
QImage img;
QVariant data = index.data(Qt::EditRole);
QVariant bArrdata = index.data(Qt::EditRole);
// Table cell data: image? Store it as an embedded image in HTML
if (!inSQL && img.loadFromData(data.toByteArray()))
if (!inSQL && img.loadFromData(bArrdata.toByteArray()))
{
QByteArray ba;
QBuffer buffer(&ba);
@@ -535,7 +535,7 @@ void ExtendedTableWidget::copyMimeData(const QModelIndexList& fromIndices, QMime
} else {
QByteArray text;
if (!m->isBinary(index)) {
text = data.toByteArray();
text = bArrdata.toByteArray();
// Table cell data: text
if (text.contains('\n') || text.contains('\t'))
@@ -547,7 +547,7 @@ void ExtendedTableWidget::copyMimeData(const QModelIndexList& fromIndices, QMime
sqlResult.append("'" + text.replace("'", "''") + "'");
} else
// Table cell data: binary. Save as BLOB literal in SQL
sqlResult.append( "X'" + data.toByteArray().toHex() + "'" );
sqlResult.append( "X'" + bArrdata.toByteArray().toHex() + "'" );
}
}
@@ -638,11 +638,11 @@ void ExtendedTableWidget::paste()
// Special case: if there is only one cell of data to be pasted, paste it into all selected fields
if(rows == 1 && columns == 1)
{
QByteArray data = source->front().front();
QByteArray bArrdata = source->front().front();
for(int row=firstRow;row<firstRow+selectedRows;row++)
{
for(int column=firstColumn;column<firstColumn+selectedColumns;column++)
m->setData(m->index(row, column), data);
m->setData(m->index(row, column), bArrdata);
}
return;
}
@@ -691,14 +691,14 @@ void ExtendedTableWidget::useAsFilter(const QString& filterOperator, bool binary
if (!index.isValid() || !selectionModel()->hasSelection() || m->isBinary(index))
return;
QVariant data = model()->data(index, Qt::EditRole);
QVariant bArrdata = model()->data(index, Qt::EditRole);
QString value;
if (data.isNull())
if (bArrdata.isNull())
value = "NULL";
else if (data.toString().isEmpty())
else if (bArrdata.toString().isEmpty())
value = "''";
else
value = data.toString();
value = bArrdata.toString();
// When Containing filter is requested (empty operator) and the value starts with
// an operator character, the character is escaped.

View File

@@ -250,7 +250,7 @@ void ImportCsvDialog::updatePreview()
ui->tablePreview->setHorizontalHeaderLabels(horizontalHeader);
// Parse file
parseCSV(selectedFile, [this](size_t rowNum, const CSVRow& data) -> bool {
parseCSV(selectedFile, [this](size_t rowNum, const CSVRow& rowData) -> bool {
// Skip first row if it is to be used as header
if(rowNum == 0 && ui->checkboxHeader->isChecked())
return true;
@@ -262,7 +262,7 @@ void ImportCsvDialog::updatePreview()
// Fill data section
ui->tablePreview->setRowCount(ui->tablePreview->rowCount() + 1);
for(size_t i=0;i<data.num_fields;i++)
for(size_t i=0;i<rowData.num_fields;i++)
{
// Generate vertical header items
if(i == 0)
@@ -270,13 +270,13 @@ void ImportCsvDialog::updatePreview()
// 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.
uint64_t data_length = data.fields[i].data_length;
uint64_t data_length = rowData.fields[i].data_length;
if(data_length > 1024)
data_length = 1024;
ui->tablePreview->setItem(
static_cast<int>(rowNum),
static_cast<int>(i),
new QTableWidgetItem(QString::fromUtf8(data.fields[i].data, static_cast<int>(data_length))));
new QTableWidgetItem(QString::fromUtf8(rowData.fields[i].data, static_cast<int>(data_length))));
}
return true;
@@ -392,9 +392,9 @@ sqlb::FieldVector ImportCsvDialog::generateFieldList(const QString& filename)
sqlb::FieldVector fieldList; // List of fields in the file
// Parse the first couple of records of the CSV file and only analyse them
parseCSV(filename, [this, &fieldList](size_t rowNum, const CSVRow& data) -> bool {
parseCSV(filename, [this, &fieldList](size_t rowNum, const CSVRow& rowData) -> bool {
// Has this row more columns than the previous one? Then add more fields to the field list as necessary.
for(size_t i=fieldList.size();i<data.num_fields;i++)
for(size_t i=fieldList.size();i<rowData.num_fields;i++)
{
QString fieldname;
@@ -402,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, static_cast<int>(data.fields[i].data_length));
fieldname = QString::fromUtf8(rowData.fields[i].data, static_cast<int>(rowData.fields[i].data_length));
fieldname.replace("`", "");
fieldname.replace(" ", "");
fieldname.replace('"', "");
@@ -423,14 +423,14 @@ sqlb::FieldVector ImportCsvDialog::generateFieldList(const QString& filename)
// Try to find out a data type for each column. Skip the header row if there is one.
if(!ui->checkNoTypeDetection->isChecked() && !(rowNum == 0 && ui->checkboxHeader->isChecked()))
{
for(size_t i=0;i<data.num_fields;i++)
for(size_t i=0;i<rowData.num_fields;i++)
{
// If the data type has been set to TEXT, there's no going back because it means we had at least one row with text-only
// content and that means we don't want to set the data type to any number type.
std::string old_type = fieldList.at(i).type();
if(old_type != "TEXT")
{
QString content = QString::fromUtf8(data.fields[i].data, static_cast<int>(data.fields[i].data_length));
QString content = QString::fromUtf8(rowData.fields[i].data, static_cast<int>(rowData.fields[i].data_length));
// Check if the content can be converted to an integer or to float
bool convert_to_int, convert_to_float;
@@ -617,7 +617,7 @@ bool ImportCsvDialog::importCsv(const QString& fileName, const QString& name)
// Parse entire file
size_t lastRowNum = 0;
CSVParser::ParserResult result = parseCSV(fileName, [&](size_t rowNum, const CSVRow& data) -> bool {
CSVParser::ParserResult result = parseCSV(fileName, [&](size_t rowNum, const CSVRow& rowData) -> bool {
// Process the parser results row by row
#ifdef CSV_BENCHMARK
@@ -632,11 +632,11 @@ bool ImportCsvDialog::importCsv(const QString& fileName, const QString& name)
return true;
// Bind all values
for(size_t i=0;i<data.num_fields;i++)
for(size_t i=0;i<rowData.num_fields;i++)
{
// 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 && nullValues.size() > i)
if(importToExistingTable && rowData.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))
@@ -647,11 +647,11 @@ bool ImportCsvDialog::importCsv(const QString& fileName, const QString& name)
if(!val.isNull()) // No need to bind NULL values here as that is the default bound value in SQLite
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) {
} else if(!importToExistingTable && rowData.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, static_cast<int>(i)+1, data.fields[i].data, static_cast<int>(data.fields[i].data_length), SQLITE_STATIC);
sqlite3_bind_text(stmt, static_cast<int>(i)+1, rowData.fields[i].data, static_cast<int>(rowData.fields[i].data_length), SQLITE_STATIC);
}
}

View File

@@ -744,10 +744,10 @@ void MainWindow::populateTable()
double min = first;
double max = first;
for (const QModelIndex& index : sel) {
double data = m_browseTableModel->data(index, Qt::EditRole).toDouble();
sum += data;
min = std::min(min, data);
max = std::max(max, data);
double dblData = m_browseTableModel->data(index, Qt::EditRole).toDouble();
sum += dblData;
min = std::min(min, dblData);
max = std::max(max, dblData);
}
statusMessage += tr(". Sum: %1; Average: %2; Min: %3; Max: %4").arg(sum).arg(sum/sel.count()).arg(min).arg(max);
}
@@ -3906,8 +3906,8 @@ void MainWindow::printDbStructure ()
for (int row = 0; row < rowCount; row++) {
QModelIndex headerIndex = model->index(row, 0, treeView->rootIndex());
QString data = model->data(headerIndex).toString().toHtmlEscaped();
out << QString("<h1>%1</h1>").arg(data);
QString strData = model->data(headerIndex).toString().toHtmlEscaped();
out << QString("<h1>%1</h1>").arg(strData);
// Open a new table for each group of objects
out << "<table border=1 cellspacing=0 cellpadding=2><thead><tr bgcolor=\"#F0F0F0\">";

View File

@@ -687,8 +687,8 @@ QVariant::Type PlotDock::guessDataType(SqliteTableModel* model, int column)
QVariant::Type type = QVariant::Invalid;
for(int i = 0; i < std::min(10, model->rowCount()) && type != QVariant::String; ++i)
{
QVariant data = model->data(model->index(i, column), Qt::EditRole);
if(data.isNull() || data.convert(QVariant::Double))
QVariant varData = model->data(model->index(i, column), Qt::EditRole);
if(varData.isNull() || varData.convert(QVariant::Double))
{
type = QVariant::Double;
} else {