@@ -176,12 +176,13 @@ MainWindow::addProject
176176*/
177177void MainWindow::addProject ()
178178{
179- QString newName (" New project" );
180179 QStringList pathList;
181180 fileSelectorModel->getPathList (pathList);
182181
183182 if (pathList.isEmpty ()) return ;
184183
184+ QString newName (" New project" );
185+
185186 for (int i = 2 ; projectNames.contains (newName); i++)
186187 newName = QString (" New project (%1)" ).arg (i);
187188
@@ -192,6 +193,7 @@ void MainWindow::addProject()
192193 stringList.push_back (newName);
193194 projectsListModel->setStringList (stringList);
194195
196+ // Avoids reloading a newly added project as it's already loaded.
195197 ui->projectsList ->selectionModel ()->blockSignals (true );
196198 ui->projectsList ->setCurrentIndex (ui->projectsList ->model ()->index (ui->projectsList ->model ()->rowCount () - 1 , 0 ));
197199 ui->projectsList ->selectionModel ()->blockSignals (false );
@@ -241,12 +243,14 @@ MainWindow::projectClicked
241243*/
242244void MainWindow::projectClicked (const QItemSelection &selected, const QItemSelection &deselected)
243245{
246+ ui->fileSelector ->collapseAll ();
247+
248+ // Resets file selector when a user clicks on an empty area
244249 if (selected.indexes ().isEmpty ())
245250 {
246251 for (int i = 0 ; i < fileSelectorModel->rowCount (); i++)
247252 fileSelectorModel->setData (fileSelectorModel->index (i, 0 , QModelIndex ()), Qt::Unchecked, Qt::CheckStateRole);
248253
249- ui->fileSelector ->collapseAll ();
250254 return ;
251255 }
252256
@@ -259,8 +263,8 @@ void MainWindow::projectClicked(const QItemSelection &selected, const QItemSelec
259263 }
260264
261265 fileSelectorModel->setChecked (projectPathList[ui->projectsList ->currentIndex ().row ()]);
262- ui->fileSelector ->collapseAll ();
263266
267+ // Expands all directories with checked checkboxes
264268 for (auto &path : projectPathList[ui->projectsList ->currentIndex ().row ()])
265269 {
266270 QModelIndex curIndex = fileSelectorModel->index (path).parent ();
@@ -283,12 +287,12 @@ void MainWindow::projectNameChanged(const QModelIndex &index)
283287 QString newName = index.data (Qt::DisplayRole).toString ();
284288 newName.remove (' /' );
285289 newName.remove (' \\ ' );
286- int currentRow = index.row ();
290+ int row = index.row ();
287291
288292 // Sets its name back to original if there's the project name that already exists
289293 if (newName.isEmpty () || projectNames.contains (newName, Qt::CaseInsensitive))
290294 {
291- ui->projectsList ->model ()->setData (index, projectNames[currentRow ], Qt::DisplayRole);
295+ ui->projectsList ->model ()->setData (index, projectNames[row ], Qt::DisplayRole);
292296 return ;
293297 }
294298
@@ -299,12 +303,12 @@ void MainWindow::projectNameChanged(const QModelIndex &index)
299303 {
300304 MetricsData data;
301305
302- data.sourceFiles = metricsData.value (QString (" %1-%2-SourceFiles" ).arg (projectNames[currentRow ]).arg (i), -1 ).toInt ();
303- data.lines = metricsData.value (QString (" %1-%2-Lines" ).arg (projectNames[currentRow ]).arg (i), -1 ).toInt ();
304- data.linesOfCode = metricsData.value (QString (" %1-%2-LinesOfCode" ).arg (projectNames[currentRow ]).arg (i), -1 ).toInt ();
305- data.commentLines = metricsData.value (QString (" %1-%2-CommentLines" ).arg (projectNames[currentRow ]).arg (i), -1 ).toInt ();
306- data.commentWords = metricsData.value (QString (" %1-%2-CommentWords" ).arg (projectNames[currentRow ]).arg (i), -1 ).toInt ();
307- data.blankLines = metricsData.value (QString (" %1-%2-BlankLines" ).arg (projectNames[currentRow ]).arg (i), -1 ).toInt ();
306+ data.sourceFiles = metricsData.value (QString (" %1-%2-SourceFiles" ).arg (projectNames[row ]).arg (i), -1 ).toInt ();
307+ data.lines = metricsData.value (QString (" %1-%2-Lines" ).arg (projectNames[row ]).arg (i), -1 ).toInt ();
308+ data.linesOfCode = metricsData.value (QString (" %1-%2-LinesOfCode" ).arg (projectNames[row ]).arg (i), -1 ).toInt ();
309+ data.commentLines = metricsData.value (QString (" %1-%2-CommentLines" ).arg (projectNames[row ]).arg (i), -1 ).toInt ();
310+ data.commentWords = metricsData.value (QString (" %1-%2-CommentWords" ).arg (projectNames[row ]).arg (i), -1 ).toInt ();
311+ data.blankLines = metricsData.value (QString (" %1-%2-BlankLines" ).arg (projectNames[row ]).arg (i), -1 ).toInt ();
308312
309313 if (data.sourceFiles >= 0 ) metricsData.setValue (QString (" %1-%2-SourceFiles" ).arg (newName).arg (i), data.sourceFiles );
310314 if (data.lines >= 0 ) metricsData.setValue (QString (" %1-%2-Lines" ).arg (newName).arg (i), data.lines );
@@ -313,15 +317,15 @@ void MainWindow::projectNameChanged(const QModelIndex &index)
313317 if (data.commentWords >= 0 ) metricsData.setValue (QString (" %1-%2-CommentWords" ).arg (newName).arg (i), data.commentWords );
314318 if (data.blankLines >= 0 ) metricsData.setValue (QString (" %1-%2-BlankLines" ).arg (newName).arg (i), data.blankLines );
315319
316- metricsData.remove (QString (" %1-%2-SourceFiles" ).arg (projectNames[currentRow ]).arg (i));
317- metricsData.remove (QString (" %1-%2-Lines" ).arg (projectNames[currentRow ]).arg (i));
318- metricsData.remove (QString (" %1-%2-LinesOfCode" ).arg (projectNames[currentRow ]).arg (i));
319- metricsData.remove (QString (" %1-%2-CommentLines" ).arg (projectNames[currentRow ]).arg (i));
320- metricsData.remove (QString (" %1-%2-CommentWords" ).arg (projectNames[currentRow ]).arg (i));
321- metricsData.remove (QString (" %1-%2-BlankLines" ).arg (projectNames[currentRow ]).arg (i));
320+ metricsData.remove (QString (" %1-%2-SourceFiles" ).arg (projectNames[row ]).arg (i));
321+ metricsData.remove (QString (" %1-%2-Lines" ).arg (projectNames[row ]).arg (i));
322+ metricsData.remove (QString (" %1-%2-LinesOfCode" ).arg (projectNames[row ]).arg (i));
323+ metricsData.remove (QString (" %1-%2-CommentLines" ).arg (projectNames[row ]).arg (i));
324+ metricsData.remove (QString (" %1-%2-CommentWords" ).arg (projectNames[row ]).arg (i));
325+ metricsData.remove (QString (" %1-%2-BlankLines" ).arg (projectNames[row ]).arg (i));
322326 }
323327
324- projectNames[index. row () ] = newName;
328+ projectNames[row] = newName;
325329}
326330
327331/*
@@ -702,7 +706,7 @@ void MainWindow::updateMetricsDifference() const
702706{
703707 for (int i = 0 ; i < Language::NONE; i++)
704708 {
705- int row = getMetricsTableIndex (( Language::type_t ) i );
709+ int row = getMetricsTableIndex (static_cast < Language::type_t >(i) );
706710
707711 showDifference (ui->metricsTable ->item (row, 1 ), dataCurrent[i].sourceFiles , dataPrevious[i].sourceFiles );
708712 showDifference (ui->metricsTable ->item (row, 2 ), dataCurrent[i].lines , dataPrevious[i].lines );
@@ -767,7 +771,7 @@ Language::type_t MainWindow::getLanguageType(const QString &ext) const
767771 for (int i = 0 ; i < Language::NONE; i++)
768772 for (int j = 0 ; langList[i].ext [j]; j++)
769773 if (!ext.compare (langList[i].ext [j], Qt::CaseInsensitive))
770- return ( Language::type_t ) i ;
774+ return static_cast < Language::type_t >(i) ;
771775
772776 return Language::NONE;
773777}
0 commit comments