Skip to content

Commit d54b820

Browse files
scottfurryMKleusberg
authored andcommitted
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.
1 parent 800a8da commit d54b820

File tree

6 files changed

+70
-70
lines changed

6 files changed

+70
-70
lines changed

src/EditDialog.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ void EditDialog::setCurrentIndex(const QModelIndex& idx)
8787
{
8888
currentIndex = QPersistentModelIndex(idx);
8989

90-
QByteArray data = idx.data(Qt::EditRole).toByteArray();
91-
loadData(data);
92-
updateCellInfoAndMode(data);
90+
QByteArray bArrData = idx.data(Qt::EditRole).toByteArray();
91+
loadData(bArrData);
92+
updateCellInfoAndMode(bArrData);
9393

9494
ui->buttonApply->setDisabled(true);
9595
}
@@ -113,7 +113,7 @@ void EditDialog::reject()
113113
}
114114

115115
// Loads data from a cell into the Edit Cell window
116-
void EditDialog::loadData(const QByteArray& data)
116+
void EditDialog::loadData(const QByteArray& bArrdata)
117117
{
118118
QImage img;
119119
QString textData;
@@ -122,7 +122,7 @@ void EditDialog::loadData(const QByteArray& data)
122122
removedBom.clear();
123123

124124
// Determine the data type, saving that info in the class variable
125-
dataType = checkDataType(data);
125+
dataType = checkDataType(bArrdata);
126126

127127
// Get the current editor mode (eg text, hex, image, json or xml mode)
128128
int editMode = ui->comboMode->currentIndex();
@@ -150,7 +150,7 @@ void EditDialog::loadData(const QByteArray& data)
150150
dataSource = HexBuffer;
151151

152152
// Load the Null into the hex editor
153-
hexEdit->setData(data);
153+
hexEdit->setData(bArrdata);
154154

155155
break;
156156

@@ -162,7 +162,7 @@ void EditDialog::loadData(const QByteArray& data)
162162
ui->editorImage->setPixmap(QPixmap(0,0));
163163

164164
// Load the Null into the hex editor
165-
hexEdit->setData(data);
165+
hexEdit->setData(bArrdata);
166166

167167
break;
168168
}
@@ -177,10 +177,10 @@ void EditDialog::loadData(const QByteArray& data)
177177
case TextEditor:
178178
case JsonEditor:
179179
case XmlEditor:
180-
setDataInBuffer(data, SciBuffer);
180+
setDataInBuffer(bArrdata, SciBuffer);
181181
break;
182182
case HexEditor:
183-
setDataInBuffer(data, HexBuffer);
183+
setDataInBuffer(bArrdata, HexBuffer);
184184
break;
185185
case ImageViewer:
186186
// The image viewer cannot hold data nor display text.
@@ -189,7 +189,7 @@ void EditDialog::loadData(const QByteArray& data)
189189
ui->editorImage->setPixmap(QPixmap(0,0));
190190

191191
// Load the text into the text editor
192-
setDataInBuffer(data, SciBuffer);
192+
setDataInBuffer(bArrdata, SciBuffer);
193193

194194
break;
195195
}
@@ -200,7 +200,7 @@ void EditDialog::loadData(const QByteArray& data)
200200
// stored it in the editorImage widget instead, it would be a pixmap
201201
// and there's no good way to restore that back to the original
202202
// (pristine) image data. eg image metadata would be lost
203-
setDataInBuffer(data, HexBuffer);
203+
setDataInBuffer(bArrdata, HexBuffer);
204204

205205
// Update the display if in text edit or image viewer mode
206206
switch (editMode) {
@@ -217,7 +217,7 @@ void EditDialog::loadData(const QByteArray& data)
217217

218218
case ImageViewer:
219219
// Load the image into the image viewing widget
220-
if (img.loadFromData(data)) {
220+
if (img.loadFromData(bArrdata)) {
221221
ui->editorImage->setPixmap(QPixmap::fromImage(img));
222222
}
223223
break;
@@ -230,21 +230,21 @@ void EditDialog::loadData(const QByteArray& data)
230230
case JsonEditor:
231231
case XmlEditor:
232232

233-
setDataInBuffer(data, SciBuffer);
233+
setDataInBuffer(bArrdata, SciBuffer);
234234
break;
235235

236236
case HexEditor:
237237

238-
setDataInBuffer(data, HexBuffer);
238+
setDataInBuffer(bArrdata, HexBuffer);
239239
break;
240240

241241
case ImageViewer:
242242
// Set data in the XML (Sci) Buffer and load the SVG Image
243-
setDataInBuffer(data, SciBuffer);
243+
setDataInBuffer(bArrdata, SciBuffer);
244244
sciEdit->setLanguage(DockTextEdit::XML);
245245

246246
// Load the image into the image viewing widget
247-
if (img.loadFromData(data)) {
247+
if (img.loadFromData(bArrdata)) {
248248
ui->editorImage->setPixmap(QPixmap::fromImage(img));
249249
}
250250
break;
@@ -257,7 +257,7 @@ void EditDialog::loadData(const QByteArray& data)
257257
// into the hex widget (the only safe place for it)
258258

259259
// Load the data into the hex buffer
260-
setDataInBuffer(data, HexBuffer);
260+
setDataInBuffer(bArrdata, HexBuffer);
261261

262262
switch (editMode) {
263263
case TextEditor:
@@ -555,7 +555,7 @@ void EditDialog::accept()
555555
}
556556
}
557557

558-
void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
558+
void EditDialog::setDataInBuffer(const QByteArray& bArrdata, DataSources source)
559559
{
560560
dataSource = source;
561561
QString textData;
@@ -569,7 +569,7 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
569569
case DockTextEdit::PlainText:
570570
{
571571
// Load the text into the text editor, remove BOM first if there is one
572-
QByteArray dataWithoutBom = data;
572+
QByteArray dataWithoutBom = bArrdata;
573573
removedBom = removeBom(dataWithoutBom);
574574

575575
textData = QString::fromUtf8(dataWithoutBom.constData(), dataWithoutBom.size());
@@ -588,7 +588,7 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
588588
json jsonDoc;
589589

590590
try {
591-
jsonDoc = json::parse(std::string(data.constData(), static_cast<size_t>(data.size())));
591+
jsonDoc = json::parse(std::string(bArrdata.constData(), static_cast<size_t>(bArrdata.size())));
592592
} catch(json::parse_error& parseError) {
593593
sciEdit->setErrorIndicator(static_cast<int>(parseError.byte - 1));
594594
}
@@ -598,7 +598,7 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
598598
textData = QString::fromStdString(jsonDoc.dump(4));
599599
} else {
600600
// Fallback case. The data is not yet valid JSON or no auto-formatting applied.
601-
textData = QString::fromUtf8(data.constData(), data.size());
601+
textData = QString::fromUtf8(bArrdata.constData(), bArrdata.size());
602602
}
603603

604604
sciEdit->setText(textData);
@@ -612,14 +612,14 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
612612
QString errorMsg;
613613
int errorLine, errorColumn;
614614
QDomDocument xmlDoc;
615-
bool isValid = xmlDoc.setContent(data, true, &errorMsg, &errorLine, &errorColumn);
615+
bool isValid = xmlDoc.setContent(bArrdata, true, &errorMsg, &errorLine, &errorColumn);
616616

617617
if (mustIndentAndCompact && isValid) {
618618
// Load indented XML into the XML editor
619619
textData = xmlDoc.toString(Settings::getValue("editor", "tabsize").toInt());
620620
} else {
621621
// Fallback case. The data is not yet valid JSON or no auto-formatting applied.
622-
textData = QString::fromUtf8(data.constData(), data.size());
622+
textData = QString::fromUtf8(bArrdata.constData(), bArrdata.size());
623623
}
624624
sciEdit->setText(textData);
625625

@@ -634,7 +634,7 @@ void EditDialog::setDataInBuffer(const QByteArray& data, DataSources source)
634634
}
635635
break;
636636
case HexBuffer:
637-
hexEdit->setData(data);
637+
hexEdit->setData(bArrdata);
638638
hexEdit->setEnabled(true);
639639

640640
break;
@@ -669,12 +669,12 @@ void EditDialog::editModeChanged(int newMode)
669669
case ImageViewer:
670670
{
671671
// When SVG format, load the image, else clear it.
672-
QByteArray data = sciEdit->text().toUtf8();
673-
dataType = checkDataType(data);
672+
QByteArray bArrdata = sciEdit->text().toUtf8();
673+
dataType = checkDataType(bArrdata);
674674
if (dataType == SVG) {
675675
QImage img;
676676

677-
if (img.loadFromData(data))
677+
if (img.loadFromData(bArrdata))
678678
ui->editorImage->setPixmap(QPixmap::fromImage(img));
679679
else
680680
// Clear any image from the image viewing widget
@@ -729,9 +729,9 @@ void EditDialog::setMustIndentAndCompact(bool enable)
729729
}
730730

731731
// Determine the type of data in the cell
732-
int EditDialog::checkDataType(const QByteArray& data)
732+
int EditDialog::checkDataType(const QByteArray& bArrdata)
733733
{
734-
QByteArray cellData = data;
734+
QByteArray cellData = bArrdata;
735735

736736
// Check for NULL data type
737737
if (cellData.isNull()) {
@@ -840,9 +840,9 @@ void EditDialog::switchEditorMode(bool autoSwitchForType)
840840

841841
// Update the information labels in the bottom left corner of the dialog
842842
// and switches the editor mode, if required, according to the detected data type.
843-
void EditDialog::updateCellInfoAndMode(const QByteArray& data)
843+
void EditDialog::updateCellInfoAndMode(const QByteArray& bArrdata)
844844
{
845-
QByteArray cellData = data;
845+
QByteArray cellData = bArrdata;
846846

847847
switchEditorMode(ui->buttonAutoSwitchMode->isChecked());
848848

src/EditDialog.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ private slots:
3636
void setNull();
3737
void updateApplyButton();
3838
void accept() override;
39-
void loadData(const QByteArray& data);
39+
void loadData(const QByteArray& bArrdata);
4040
void toggleOverwriteMode();
4141
void editModeChanged(int newMode);
4242
void editTextChanged();
4343
void switchEditorMode(bool autoSwitchForType);
44-
void updateCellInfoAndMode(const QByteArray& data);
44+
void updateCellInfoAndMode(const QByteArray& bArrdata);
4545
void setMustIndentAndCompact(bool enable);
4646
void openPrintDialog();
4747
void openPrintImageDialog();
4848
void copyHexAscii();
4949
void setWordWrapping(bool value);
5050

5151
signals:
52-
void recordTextUpdated(const QPersistentModelIndex& idx, const QByteArray& data, bool isBlob);
52+
void recordTextUpdated(const QPersistentModelIndex& idx, const QByteArray& bArrdata, bool isBlob);
5353

5454
private:
5555
Ui::EditDialog* ui;
@@ -89,10 +89,10 @@ private slots:
8989
XmlEditor = 4
9090
};
9191

92-
int checkDataType(const QByteArray& data);
92+
int checkDataType(const QByteArray& bArrdata);
9393
QString humanReadableSize(double byteCount) const;
9494
bool promptInvalidData(const QString& data_type, const QString& errorString);
95-
void setDataInBuffer(const QByteArray& data, DataSources source);
95+
void setDataInBuffer(const QByteArray& bArrdata, DataSources source);
9696
void setStackCurrentIndex(int editMode);
9797
};
9898

src/ExtendedTableWidget.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ void ExtendedTableWidget::copyMimeData(const QModelIndexList& fromIndices, QMime
421421
// If a single cell is selected which contains an image, copy it to the clipboard
422422
if (!inSQL && !withHeaders && indices.size() == 1) {
423423
QImage img;
424-
QVariant data = m->data(indices.first(), Qt::EditRole);
424+
QVariant varData = m->data(indices.first(), Qt::EditRole);
425425

426-
if (img.loadFromData(data.toByteArray()))
426+
if (img.loadFromData(varData.toByteArray()))
427427
{
428428
// If it's an image, copy the image data to the clipboard
429429
mimeData->setImageData(img);
@@ -516,10 +516,10 @@ void ExtendedTableWidget::copyMimeData(const QModelIndexList& fromIndices, QMime
516516
currentRow = index.row();
517517

518518
QImage img;
519-
QVariant data = index.data(Qt::EditRole);
519+
QVariant bArrdata = index.data(Qt::EditRole);
520520

521521
// Table cell data: image? Store it as an embedded image in HTML
522-
if (!inSQL && img.loadFromData(data.toByteArray()))
522+
if (!inSQL && img.loadFromData(bArrdata.toByteArray()))
523523
{
524524
QByteArray ba;
525525
QBuffer buffer(&ba);
@@ -535,7 +535,7 @@ void ExtendedTableWidget::copyMimeData(const QModelIndexList& fromIndices, QMime
535535
} else {
536536
QByteArray text;
537537
if (!m->isBinary(index)) {
538-
text = data.toByteArray();
538+
text = bArrdata.toByteArray();
539539

540540
// Table cell data: text
541541
if (text.contains('\n') || text.contains('\t'))
@@ -547,7 +547,7 @@ void ExtendedTableWidget::copyMimeData(const QModelIndexList& fromIndices, QMime
547547
sqlResult.append("'" + text.replace("'", "''") + "'");
548548
} else
549549
// Table cell data: binary. Save as BLOB literal in SQL
550-
sqlResult.append( "X'" + data.toByteArray().toHex() + "'" );
550+
sqlResult.append( "X'" + bArrdata.toByteArray().toHex() + "'" );
551551

552552
}
553553
}
@@ -638,11 +638,11 @@ void ExtendedTableWidget::paste()
638638
// Special case: if there is only one cell of data to be pasted, paste it into all selected fields
639639
if(rows == 1 && columns == 1)
640640
{
641-
QByteArray data = source->front().front();
641+
QByteArray bArrdata = source->front().front();
642642
for(int row=firstRow;row<firstRow+selectedRows;row++)
643643
{
644644
for(int column=firstColumn;column<firstColumn+selectedColumns;column++)
645-
m->setData(m->index(row, column), data);
645+
m->setData(m->index(row, column), bArrdata);
646646
}
647647
return;
648648
}
@@ -691,14 +691,14 @@ void ExtendedTableWidget::useAsFilter(const QString& filterOperator, bool binary
691691
if (!index.isValid() || !selectionModel()->hasSelection() || m->isBinary(index))
692692
return;
693693

694-
QVariant data = model()->data(index, Qt::EditRole);
694+
QVariant bArrdata = model()->data(index, Qt::EditRole);
695695
QString value;
696-
if (data.isNull())
696+
if (bArrdata.isNull())
697697
value = "NULL";
698-
else if (data.toString().isEmpty())
698+
else if (bArrdata.toString().isEmpty())
699699
value = "''";
700700
else
701-
value = data.toString();
701+
value = bArrdata.toString();
702702

703703
// When Containing filter is requested (empty operator) and the value starts with
704704
// an operator character, the character is escaped.

0 commit comments

Comments
 (0)