@@ -177,6 +177,7 @@ QModelIndex myModel::parent(const QModelIndex &index) const
177177// ---------------------------------------------------------------------------------------
178178bool myModel::isDir (const QModelIndex &index)
179179{
180+ if (!index.isValid ()) { return false ; }
180181 myModelItem *item = static_cast <myModelItem*>(index.internalPointer ());
181182 if (item && item != rootItem) { return item->fileInfo ().isDir (); }
182183 return false ;
@@ -185,6 +186,7 @@ bool myModel::isDir(const QModelIndex &index)
185186// ---------------------------------------------------------------------------------------
186187QFileInfo myModel::fileInfo (const QModelIndex &index)
187188{
189+ if (!index.isValid ()) { return QFileInfo (); }
188190 myModelItem *item = static_cast <myModelItem*>(index.internalPointer ());
189191 if (item) { return item->fileInfo (); }
190192 return QFileInfo ();
@@ -193,6 +195,7 @@ QFileInfo myModel::fileInfo(const QModelIndex &index)
193195// ---------------------------------------------------------------------------------------
194196qint64 myModel::size (const QModelIndex &index)
195197{
198+ if (!index.isValid ()) { return 0 ; }
196199 myModelItem *item = static_cast <myModelItem*>(index.internalPointer ());
197200 if (item) { return item->fileInfo ().size (); }
198201 return 0 ;
@@ -201,14 +204,16 @@ qint64 myModel::size(const QModelIndex &index)
201204// ---------------------------------------------------------------------------------------
202205QString myModel::fileName (const QModelIndex &index)
203206{
207+ if (!index.isValid ()) { return QString (); }
204208 myModelItem *item = static_cast <myModelItem*>(index.internalPointer ());
205209 if (item) { return item->fileName (); }
206- return " " ;
210+ return QString () ;
207211}
208212
209213// ---------------------------------------------------------------------------------------
210214QString myModel::filePath (const QModelIndex &index)
211215{
216+ if (!index.isValid ()) { return QString (); }
212217 myModelItem *item = static_cast <myModelItem*>(index.internalPointer ());
213218 if (item) { return item->absoluteFilePath (); }
214219 return QString ();
@@ -217,6 +222,7 @@ QString myModel::filePath(const QModelIndex &index)
217222// ---------------------------------------------------------------------------------------
218223QString myModel::getMimeType (const QModelIndex &index)
219224{
225+ if (!index.isValid ()) { return QString (); }
220226 qDebug () << " myModel getMimeType" ;
221227 myModelItem *item = static_cast <myModelItem*>(index.internalPointer ());
222228 if (item->mMimeType .isNull ()) {
@@ -341,14 +347,13 @@ bool myModel::setRootPath(const QString& path)
341347 return false ;
342348 }
343349
344- if (item->watched == 0 ) { addWatcher (item); }
345-
346- if (item->walked == 0 ) {
350+ if (!item->watched ) { addWatcher (item); }
351+ if (!item->walked || !item->watched ) {
347352 populateItem (item);
348353 return false ;
349354 } else {
350355 if (item->dirty ) { // model is up to date, but view needs to be invalidated
351- item->dirty = 0 ;
356+ item->dirty = false ;
352357 return true ;
353358 }
354359 }
@@ -378,12 +383,10 @@ void myModel::fetchMore (const QModelIndex & parent)
378383{
379384 myModelItem *item = static_cast <myModelItem*>(parent.internalPointer ());
380385
381- if (item) {
386+ if (item) {
382387 populateItem (item);
383388 emit dataChanged (parent,parent);
384389 }
385-
386- return ;
387390}
388391
389392// ---------------------------------------------------------------------------------------
@@ -422,14 +425,15 @@ void myModel::refresh()
422425 watchers.clear ();
423426
424427 beginResetModel ();
425- item->clearAll ();
428+ if ( item) { item ->clearAll (); }
426429 endResetModel ();
427430}
428431
429432// ---------------------------------------------------------------------------------
430433void myModel::update ()
431434{
432435 myModelItem *item = rootItem->matchPath (currentRootPath.split (SEPARATOR));
436+ if (item == NULL ) { return ; }
433437 foreach (myModelItem *child, item->children ()) { child->refreshFileInfo (); }
434438}
435439
@@ -619,7 +623,6 @@ void myModel::loadThumbs(QModelIndexList indexes) {
619623 if (!thumbs->contains (item) || (item.split (" /" ).takeLast () == lastEventFilename && !lastEventFilename.isEmpty ())) {
620624 qDebug () << " gen new thumb" << item;
621625 thumbs->insert (item, getThumb (item));
622- emit thumbUpdate (index (item));
623626 if (item.split (" /" ).takeLast () == lastEventFilename) {
624627 qDebug () << " save new thumb cache" ;
625628 lastEventFilename.clear ();
@@ -634,10 +637,9 @@ void myModel::loadThumbs(QModelIndexList indexes) {
634637 }
635638 }
636639 }
637- } else {
638- emit thumbUpdate (index (item));
639640 }
640641 }
642+ emit thumbUpdate ();
641643 }
642644}
643645
@@ -650,6 +652,8 @@ void myModel::loadThumbs(QModelIndexList indexes) {
650652 */
651653QByteArray myModel::getThumb (QString item) {
652654
655+ if (item.isEmpty ()) { return QByteArray (); }
656+
653657 // Thumbnail image
654658 QImage theThumb, background;
655659 QImageReader pic (item);
@@ -808,6 +812,8 @@ QVariant myModel::data(const QModelIndex & index, int role) const {
808812 */
809813QVariant myModel::findIcon (myModelItem *item) const {
810814
815+ if (item == NULL ) { return QIcon (); }
816+
811817 // qDebug() << "findicon" << item->absoluteFilePath();
812818 // If type of file is directory, return icon of directory
813819 QFileInfo type (item->fileInfo ());
@@ -891,6 +897,8 @@ QVariant myModel::findIcon(myModelItem *item) const {
891897 */
892898QVariant myModel::findMimeIcon (myModelItem *item) const {
893899
900+ if (item == NULL ) { return QIcon (); }
901+
894902 // Retrieve mime and search cache for it
895903 QString mime = mimeUtilsPtr->getMimeType (item->absoluteFilePath ());
896904 if (mimeIcons->contains (mime)) {
0 commit comments