Skip to content

Commit 613cdf2

Browse files
committed
Const and autofy ignorelisttablewidget
Signed-off-by: Claudio Cambra <[email protected]>
1 parent 9279dab commit 613cdf2

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

src/gui/ignorelisttablewidget.cpp

+32-23
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ IgnoreListTableWidget::IgnoreListTableWidget(QWidget *parent)
2727
"This is useful for meta data."));
2828

2929
ui->removePushButton->setEnabled(false);
30-
connect(ui->tableWidget, &QTableWidget::itemSelectionChanged,
30+
connect(ui->tableWidget, &QTableWidget::itemSelectionChanged,
3131
this, &IgnoreListTableWidget::slotItemSelectionChanged);
32-
connect(ui->removePushButton, &QAbstractButton::clicked,
32+
connect(ui->removePushButton, &QAbstractButton::clicked,
3333
this, &IgnoreListTableWidget::slotRemoveCurrentItem);
34-
connect(ui->addPushButton, &QAbstractButton::clicked,
34+
connect(ui->addPushButton, &QAbstractButton::clicked,
3535
this, &IgnoreListTableWidget::slotAddPattern);
3636
connect(ui->removeAllPushButton, &QAbstractButton::clicked,
3737
this, &IgnoreListTableWidget::slotRemoveAllItems);
@@ -48,13 +48,13 @@ IgnoreListTableWidget::~IgnoreListTableWidget()
4848

4949
void IgnoreListTableWidget::slotItemSelectionChanged()
5050
{
51-
QTableWidgetItem *item = ui->tableWidget->currentItem();
51+
const auto item = ui->tableWidget->currentItem();
5252
if (!item) {
5353
ui->removePushButton->setEnabled(false);
5454
return;
5555
}
5656

57-
bool enable = item->flags() & Qt::ItemIsEnabled;
57+
const auto enable = item->flags() & Qt::ItemIsEnabled;
5858
ui->removePushButton->setEnabled(enable);
5959
}
6060

@@ -70,15 +70,18 @@ void IgnoreListTableWidget::slotRemoveAllItems()
7070
ui->tableWidget->setRowCount(0);
7171
}
7272

73-
void IgnoreListTableWidget::slotWriteIgnoreFile(const QString & file)
73+
void IgnoreListTableWidget::slotWriteIgnoreFile(const QString &file)
7474
{
7575
QFile ignores(file);
76+
7677
if (ignores.open(QIODevice::WriteOnly)) {
7778
// rewrites the whole file since now the user can also remove system patterns
7879
QFile::resize(file, 0);
79-
for (int row = 0; row < ui->tableWidget->rowCount(); ++row) {
80-
QTableWidgetItem *patternItem = ui->tableWidget->item(row, patternCol);
81-
QTableWidgetItem *deletableItem = ui->tableWidget->item(row, deletableCol);
80+
81+
for (auto row = 0; row < ui->tableWidget->rowCount(); ++row) {
82+
const auto patternItem = ui->tableWidget->item(row, patternCol);
83+
const auto deletableItem = ui->tableWidget->item(row, deletableCol);
84+
8285
if (patternItem->flags() & Qt::ItemIsEnabled) {
8386
QByteArray prepend;
8487
if (deletableItem->checkState() == Qt::Checked) {
@@ -90,12 +93,13 @@ void IgnoreListTableWidget::slotWriteIgnoreFile(const QString & file)
9093
}
9194
}
9295
} else {
93-
QMessageBox::warning(this, tr("Could not open file"),
94-
tr("Cannot write changes to \"%1\".").arg(file));
96+
QMessageBox::warning(this,
97+
tr("Could not open file"),
98+
tr("Cannot write changes to \"%1\".").arg(file));
9599
}
96100
ignores.close(); //close the file before reloading stuff.
97101

98-
FolderMan *folderMan = FolderMan::instance();
102+
const auto folderMan = FolderMan::instance();
99103

100104
// We need to force a remote discovery after a change of the ignore list.
101105
// Otherwise we would not download the files/directories that are no longer
@@ -108,10 +112,13 @@ void IgnoreListTableWidget::slotWriteIgnoreFile(const QString & file)
108112

109113
void IgnoreListTableWidget::slotAddPattern()
110114
{
111-
bool okClicked = false;
112-
QString pattern = QInputDialog::getText(this, tr("Add Ignore Pattern"),
113-
tr("Add a new ignore pattern:"),
114-
QLineEdit::Normal, QString(), &okClicked);
115+
auto okClicked = false;
116+
const auto pattern = QInputDialog::getText(this,
117+
tr("Add Ignore Pattern"),
118+
tr("Add a new ignore pattern:"),
119+
QLineEdit::Normal,
120+
{},
121+
&okClicked);
115122

116123
if (!okClicked || pattern.isEmpty())
117124
return;
@@ -120,18 +127,20 @@ void IgnoreListTableWidget::slotAddPattern()
120127
ui->tableWidget->scrollToBottom();
121128
}
122129

123-
void IgnoreListTableWidget::readIgnoreFile(const QString &file, bool readOnly)
130+
void IgnoreListTableWidget::readIgnoreFile(const QString &file, const bool readOnly)
124131
{
125132
QFile ignores(file);
133+
126134
if (ignores.open(QIODevice::ReadOnly)) {
127135
while (!ignores.atEnd()) {
128-
QString line = QString::fromUtf8(ignores.readLine());
136+
auto line = QString::fromUtf8(ignores.readLine());
129137
line.chop(1);
130138
if (line == QStringLiteral("\\#*#")) {
131139
continue;
132140
}
141+
133142
if (!line.isEmpty() && !line.startsWith("#")) {
134-
bool deletable = false;
143+
auto deletable = false;
135144
if (line.startsWith(']')) {
136145
deletable = true;
137146
line = line.mid(1);
@@ -142,16 +151,16 @@ void IgnoreListTableWidget::readIgnoreFile(const QString &file, bool readOnly)
142151
}
143152
}
144153

145-
int IgnoreListTableWidget::addPattern(const QString &pattern, bool deletable, bool readOnly)
154+
int IgnoreListTableWidget::addPattern(const QString &pattern, const bool deletable, const bool readOnly)
146155
{
147-
int newRow = ui->tableWidget->rowCount();
156+
const auto newRow = ui->tableWidget->rowCount();
148157
ui->tableWidget->setRowCount(newRow + 1);
149158

150-
auto *patternItem = new QTableWidgetItem;
159+
const auto patternItem = new QTableWidgetItem;
151160
patternItem->setText(pattern);
152161
ui->tableWidget->setItem(newRow, patternCol, patternItem);
153162

154-
auto *deletableItem = new QTableWidgetItem;
163+
const auto deletableItem = new QTableWidgetItem;
155164
deletableItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
156165
deletableItem->setCheckState(deletable ? Qt::Checked : Qt::Unchecked);
157166
ui->tableWidget->setItem(newRow, deletableCol, deletableItem);

src/gui/ignorelisttablewidget.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class IgnoreListTableWidget : public QWidget
2323

2424
public slots:
2525
void slotRemoveAllItems();
26-
void slotWriteIgnoreFile(const QString & file);
26+
void slotWriteIgnoreFile(const QString &file);
2727

2828
private slots:
2929
void slotItemSelectionChanged();

0 commit comments

Comments
 (0)