6060#include < QSettings>
6161#include < QSignalMapper>
6262#include < QStandardItem>
63+ #include < QStandardItemModel>
6364#include < QUrl>
6465#include < QVariant>
6566#include < QVariantMap>
@@ -145,9 +146,10 @@ static QStringList getLabels() {
145146}
146147
147148ResultsTree::ResultsTree (QWidget * parent) :
148- QTreeView(parent)
149+ QTreeView(parent),
150+ mModel(new QStandardItemModel)
149151{
150- setModel (& mModel );
152+ setModel (mModel );
151153 translate (); // Adds columns to grid
152154 clear ();
153155 setExpandsOnDoubleClick (false );
@@ -169,8 +171,8 @@ void ResultsTree::setReportType(ReportType reportType) {
169171
170172 mGuideline = createGuidelineMapping (reportType);
171173
172- for (int i = 0 ; i < mModel . rowCount (); ++i) {
173- const QStandardItem *fileItem = mModel . item (i, COLUMN_FILE);
174+ for (int i = 0 ; i < mModel -> rowCount (); ++i) {
175+ const QStandardItem *fileItem = mModel -> item (i, COLUMN_FILE);
174176 if (!fileItem)
175177 continue ;
176178 for (int j = 0 ; j < fileItem->rowCount (); ++j) {
@@ -473,20 +475,20 @@ QStandardItem *ResultsTree::findFileItem(const QString &name) const
473475 // The first column contains the file name. In Windows we can get filenames
474476 // "header.h" and "Header.h" and must compare them as identical.
475477
476- for (int i = 0 ; i < mModel . rowCount (); i++) {
478+ for (int i = 0 ; i < mModel -> rowCount (); i++) {
477479#ifdef _WIN32
478- if (QString::compare (mModel . item (i, COLUMN_FILE)->text (), name, Qt::CaseInsensitive) == 0 )
480+ if (QString::compare (mModel -> item (i, COLUMN_FILE)->text (), name, Qt::CaseInsensitive) == 0 )
479481#else
480- if (mModel . item (i, COLUMN_FILE)->text () == name)
482+ if (mModel -> item (i, COLUMN_FILE)->text () == name)
481483#endif
482- return mModel . item (i, COLUMN_FILE);
484+ return mModel -> item (i, COLUMN_FILE);
483485 }
484486 return nullptr ;
485487}
486488
487489void ResultsTree::clear ()
488490{
489- mModel . removeRows (0 , mModel . rowCount ());
491+ mModel -> removeRows (0 , mModel -> rowCount ());
490492
491493 if (const ProjectFile *activeProject = ProjectFile::getActiveProject ()) {
492494 hideColumn (COLUMN_SINCE_DATE);
@@ -504,24 +506,24 @@ void ResultsTree::clear(const QString &filename)
504506{
505507 const QString stripped = stripPath (filename, false );
506508
507- for (int i = 0 ; i < mModel . rowCount (); ++i) {
508- const QStandardItem *fileItem = mModel . item (i, COLUMN_FILE);
509+ for (int i = 0 ; i < mModel -> rowCount (); ++i) {
510+ const QStandardItem *fileItem = mModel -> item (i, COLUMN_FILE);
509511 if (!fileItem)
510512 continue ;
511513
512514 QVariantMap fitemdata = fileItem->data ().toMap ();
513515 if (stripped == fitemdata[FILENAME].toString () ||
514516 filename == fitemdata[FILE0].toString ()) {
515- mModel . removeRow (i);
517+ mModel -> removeRow (i);
516518 break ;
517519 }
518520 }
519521}
520522
521523void ResultsTree::clearRecheckFile (const QString &filename)
522524{
523- for (int i = 0 ; i < mModel . rowCount (); ++i) {
524- const QStandardItem *fileItem = mModel . item (i, COLUMN_FILE);
525+ for (int i = 0 ; i < mModel -> rowCount (); ++i) {
526+ const QStandardItem *fileItem = mModel -> item (i, COLUMN_FILE);
525527 if (!fileItem)
526528 continue ;
527529
@@ -530,7 +532,7 @@ void ResultsTree::clearRecheckFile(const QString &filename)
530532 QString storedfile = fitemdata[FILENAME].toString ();
531533 storedfile = ((!mCheckPath .isEmpty () && storedfile.startsWith (mCheckPath )) ? storedfile.mid (mCheckPath .length () + 1 ) : storedfile);
532534 if (actualfile == storedfile) {
533- mModel . removeRow (i);
535+ mModel -> removeRow (i);
534536 break ;
535537 }
536538 }
@@ -539,9 +541,9 @@ void ResultsTree::clearRecheckFile(const QString &filename)
539541
540542void ResultsTree::loadSettings ()
541543{
542- for (int i = 0 ; i < mModel . columnCount (); i++) {
544+ for (int i = 0 ; i < mModel -> columnCount (); i++) {
543545 QString temp = QString (SETTINGS_RESULT_COLUMN_WIDTH).arg (i);
544- setColumnWidth (i, qMax (20 , mSettings ->value (temp, 800 / mModel . columnCount ()).toInt ()));
546+ setColumnWidth (i, qMax (20 , mSettings ->value (temp, 800 / mModel -> columnCount ()).toInt ()));
545547 }
546548
547549 mSaveFullPath = mSettings ->value (SETTINGS_SAVE_FULL_PATH, false ).toBool ();
@@ -554,7 +556,7 @@ void ResultsTree::loadSettings()
554556
555557void ResultsTree::saveSettings () const
556558{
557- for (int i = 0 ; i < mModel . columnCount (); i++) {
559+ for (int i = 0 ; i < mModel -> columnCount (); i++) {
558560 QString temp = QString (SETTINGS_RESULT_COLUMN_WIDTH).arg (i);
559561 mSettings ->setValue (temp, columnWidth (i));
560562 }
@@ -599,11 +601,11 @@ void ResultsTree::refreshTree()
599601{
600602 mVisibleErrors = false ;
601603 // Get the amount of files in the tree
602- const int filecount = mModel . rowCount ();
604+ const int filecount = mModel -> rowCount ();
603605
604606 for (int i = 0 ; i < filecount; i++) {
605607 // Get file i
606- QStandardItem *fileItem = mModel . item (i, 0 );
608+ QStandardItem *fileItem = mModel -> item (i, 0 );
607609 if (!fileItem) {
608610 continue ;
609611 }
@@ -693,7 +695,7 @@ QStandardItem *ResultsTree::ensureFileItem(const QString &fullpath, const QStrin
693695 itemdata[FILENAME] = fullpath;
694696 itemdata[FILE0] = file0;
695697 item->setData (QVariant (itemdata));
696- mModel . appendRow (item);
698+ mModel -> appendRow (item);
697699
698700 setRowHidden (item->row (), QModelIndex (), hide);
699701
@@ -710,7 +712,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
710712 if (mSelectionModel ->selectedRows ().count () > 1 )
711713 multipleSelection = true ;
712714
713- mContextItem = mModel . itemFromIndex (index);
715+ mContextItem = mModel -> itemFromIndex (index);
714716
715717 // Create a new context menu
716718 QMenu menu (this );
@@ -751,7 +753,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
751753 int selectedResults = 0 ;
752754
753755 for (auto row : mSelectionModel ->selectedRows ()) {
754- auto *item = mModel . itemFromIndex (row);
756+ auto *item = mModel -> itemFromIndex (row);
755757 if (!item->parent ())
756758 selectedFiles++;
757759 else if (!item->parent ()->parent ())
@@ -830,7 +832,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
830832 menu.exec (e->globalPos ());
831833 index = indexAt (e->pos ());
832834 if (index.isValid ()) {
833- mContextItem = mModel . itemFromIndex (index);
835+ mContextItem = mModel -> itemFromIndex (index);
834836 }
835837 }
836838}
@@ -996,7 +998,7 @@ void ResultsTree::copy()
996998
997999 QString text;
9981000 for (const QModelIndex& index : mSelectionModel ->selectedRows ()) {
999- const QStandardItem *item = mModel . itemFromIndex (index);
1001+ const QStandardItem *item = mModel -> itemFromIndex (index);
10001002 if (!item->parent ()) {
10011003 text += item->text () + ' \n ' ;
10021004 continue ;
@@ -1027,7 +1029,7 @@ void ResultsTree::hideResult()
10271029 return ;
10281030
10291031 for (QModelIndex index : mSelectionModel ->selectedRows ()) {
1030- QStandardItem *item = mModel . itemFromIndex (index);
1032+ QStandardItem *item = mModel -> itemFromIndex (index);
10311033 // Set the "hide" flag for this item
10321034 QVariantMap itemdata = item->data ().toMap ();
10331035 itemdata[HIDE] = true ;
@@ -1045,7 +1047,7 @@ void ResultsTree::recheckSelectedFiles()
10451047
10461048 QStringList selectedItems;
10471049 for (QModelIndex index : mSelectionModel ->selectedRows ()) {
1048- QStandardItem *item = mModel . itemFromIndex (index);
1050+ QStandardItem *item = mModel -> itemFromIndex (index);
10491051 while (item->parent ())
10501052 item = item->parent ();
10511053 QVariantMap itemdata = item->data ().toMap ();
@@ -1100,7 +1102,7 @@ void ResultsTree::suppressSelectedIds()
11001102
11011103 QSet<QString> selectedIds;
11021104 for (QModelIndex index : mSelectionModel ->selectedRows ()) {
1103- QStandardItem *item = mModel . itemFromIndex (index);
1105+ QStandardItem *item = mModel -> itemFromIndex (index);
11041106 if (!item->parent ())
11051107 continue ;
11061108 if (item->parent ()->parent ())
@@ -1112,8 +1114,8 @@ void ResultsTree::suppressSelectedIds()
11121114 }
11131115
11141116 // delete all errors with selected message Ids
1115- for (int i = 0 ; i < mModel . rowCount (); i++) {
1116- QStandardItem * const file = mModel . item (i, 0 );
1117+ for (int i = 0 ; i < mModel -> rowCount (); i++) {
1118+ QStandardItem * const file = mModel -> item (i, 0 );
11171119 for (int j = 0 ; j < file->rowCount ();) {
11181120 QStandardItem *errorItem = file->child (j, 0 );
11191121 QVariantMap userdata = errorItem->data ().toMap ();
@@ -1124,7 +1126,7 @@ void ResultsTree::suppressSelectedIds()
11241126 }
11251127 }
11261128 if (file->rowCount () == 0 )
1127- mModel . removeRow (file->row ());
1129+ mModel -> removeRow (file->row ());
11281130 }
11291131
11301132
@@ -1139,7 +1141,7 @@ void ResultsTree::suppressHash()
11391141 // Extract selected warnings
11401142 QSet<QStandardItem *> selectedWarnings;
11411143 for (QModelIndex index : mSelectionModel ->selectedRows ()) {
1142- QStandardItem *item = mModel . itemFromIndex (index);
1144+ QStandardItem *item = mModel -> itemFromIndex (index);
11431145 if (!item->parent ())
11441146 continue ;
11451147 while (item->parent ()->parent ())
@@ -1163,7 +1165,7 @@ void ResultsTree::suppressHash()
11631165 }
11641166 fileItem->removeRow (item->row ());
11651167 if (fileItem->rowCount () == 0 )
1166- mModel . removeRow (fileItem->row ());
1168+ mModel -> removeRow (fileItem->row ());
11671169 }
11681170
11691171 if (changed)
@@ -1186,7 +1188,7 @@ void ResultsTree::tagSelectedItems(const QString &tag)
11861188 bool isTagged = false ;
11871189 ProjectFile *currentProject = ProjectFile::getActiveProject ();
11881190 for (QModelIndex index : mSelectionModel ->selectedRows ()) {
1189- QStandardItem *item = mModel . itemFromIndex (index);
1191+ QStandardItem *item = mModel -> itemFromIndex (index);
11901192 QVariantMap itemdata = item->data ().toMap ();
11911193 if (itemdata.contains (" tags" )) {
11921194 itemdata[TAGS] = tag;
@@ -1209,7 +1211,7 @@ void ResultsTree::context(int application)
12091211
12101212void ResultsTree::quickStartApplication (const QModelIndex &index)
12111213{
1212- startApplication (mModel . itemFromIndex (index));
1214+ startApplication (mModel -> itemFromIndex (index));
12131215}
12141216
12151217QString ResultsTree::getFilePath (const QStandardItem *target, bool fullPath)
@@ -1259,9 +1261,9 @@ void ResultsTree::saveResults(Report *report) const
12591261{
12601262 report->writeHeader ();
12611263
1262- for (int i = 0 ; i < mModel . rowCount (); i++) {
1264+ for (int i = 0 ; i < mModel -> rowCount (); i++) {
12631265 if (mSaveAllErrors || !isRowHidden (i, QModelIndex ()))
1264- saveErrors (report, mModel . item (i, 0 ));
1266+ saveErrors (report, mModel -> item (i, 0 ));
12651267 }
12661268
12671269 report->writeFooter ();
@@ -1311,8 +1313,8 @@ void ResultsTree::updateFromOldReport(const QString &filename)
13111313 }
13121314
13131315 // Read current results..
1314- for (int i = 0 ; i < mModel . rowCount (); i++) {
1315- QStandardItem *fileItem = mModel . item (i,0 );
1316+ for (int i = 0 ; i < mModel -> rowCount (); i++) {
1317+ QStandardItem *fileItem = mModel -> item (i,0 );
13161318 for (int j = 0 ; j < fileItem->rowCount (); j++) {
13171319 QStandardItem *error = fileItem->child (j,0 );
13181320 ErrorItem errorItem;
@@ -1491,8 +1493,8 @@ void ResultsTree::refreshFilePaths()
14911493 qDebug (" Refreshing file paths" );
14921494
14931495 // Go through all file items (these are parent items that contain the errors)
1494- for (int i = 0 ; i < mModel . rowCount (); i++) {
1495- refreshFilePaths (mModel . item (i, 0 ));
1496+ for (int i = 0 ; i < mModel -> rowCount (); i++) {
1497+ refreshFilePaths (mModel -> item (i, 0 ));
14961498 }
14971499}
14981500
@@ -1503,12 +1505,12 @@ bool ResultsTree::hasVisibleResults() const
15031505
15041506bool ResultsTree::hasResults () const
15051507{
1506- return mModel . rowCount () > 0 ;
1508+ return mModel -> rowCount () > 0 ;
15071509}
15081510
15091511void ResultsTree::translate ()
15101512{
1511- mModel . setHorizontalHeaderLabels (getLabels ());
1513+ mModel -> setHorizontalHeaderLabels (getLabels ());
15121514 // TODO go through all the errors in the tree and translate severity and message
15131515}
15141516
0 commit comments