Browse Source

Centralize imageCollection creation
Cease to use needlessly static qualify method on ArtNodes

Donald Carr 6 years ago
parent
commit
49a2046c26

+ 6 - 6
qml/common/ArtImage.qml

@@ -13,7 +13,7 @@ Item {
 
     //color: Qt.rgba(Math.random(255), Math.random(255), Math.random(255), 1.0)
 
-    height: width*globalUtil.imageModel.data(modelIndex, PictureModel.SizeRole).height/globalUtil.imageModel.data(modelIndex, PictureModel.SizeRole).width
+    height: width*nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).height/nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).width
     width: parent ? parent.width : 0
 
     Image {
@@ -21,8 +21,8 @@ Item {
         cache: false
         opacity: globalSettings.fadeInImages ? 0 : 1.0
 
-        height: globalVars.imageWidthOverride > 0 ? Math.ceil(globalVars.imageWidthOverride*globalUtil.imageModel.data(modelIndex, PictureModel.SizeRole).height/globalUtil.imageModel.data(modelIndex, PictureModel.SizeRole).width) : globalUtil.imageModel.data(modelIndex, PictureModel.SizeRole).height
-        width: globalVars.imageWidthOverride > 0 ? globalVars.imageWidthOverride : globalUtil.imageModel.data(modelIndex, PictureModel.SizeRole).width
+        height: globalVars.imageWidthOverride > 0 ? Math.ceil(globalVars.imageWidthOverride*nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).height/nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).width) : nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).height
+        width: globalVars.imageWidthOverride > 0 ? globalVars.imageWidthOverride : nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).width
 
         transformOrigin: Item.TopLeft
         scale: root.width/image.width
@@ -30,7 +30,7 @@ Item {
         asynchronous: true
         fillMode: Image.PreserveAspectFit
 
-        source: globalUtil.imageModel.data(modelIndex)
+        source: nativeUtils.imageCollection.data(modelIndex)
 
         mirror: globalSettings.randomlyMirrorArt && (Math.random() < globalSettings.randomlyMirrorArtFreq)
         smooth: globalSettings.smoothArt
@@ -55,7 +55,7 @@ Item {
     }
 
     Component.onCompleted: {
-        modelIndex = globalUtil.imageModel.requestIndex()
+        modelIndex = nativeUtils.imageCollection.requestIndex()
         if (globalSettings.effect !== "" && Effects.validate(globalSettings.effect)) {
             var component = Qt.createComponent("VisualEffect.qml");
             component.status !== Component.Ready && console.log('Component failed with:' + component.errorString())
@@ -63,5 +63,5 @@ Item {
         }
     }
 
-    Component.onDestruction: globalUtil.imageModel.retireIndex(modelIndex)
+    Component.onDestruction: nativeUtils.imageCollection.retireIndex(modelIndex)
 }

+ 0 - 7
qml/common/View.qml

@@ -23,11 +23,4 @@ Item {
         model: globalSettings.columnCount
         delegate: columnComponent
     }
-
-    PictureModel {
-        id: imageModel
-        Component.onCompleted: {
-            globalUtil.imageModel = imageModel
-        }
-    }
 }

+ 0 - 1
qml/main.qml

@@ -25,7 +25,6 @@ Item {
 
     QtObject {
         id: globalUtil
-        property var imageModel
         property int itemCount
         property int currentColumn: 0
         property bool primed: d.primedColumns === globalSettings.columnCount

+ 0 - 7
qml/views/animator/Animator.qml

@@ -132,11 +132,4 @@ Item {
         target: globalSettings
         onColumnCountChanged: console.log('Col count:' + globalSettings.columnCount)
     }
-
-    PictureModel {
-        id: imageModel
-        Component.onCompleted: {
-            globalUtil.imageModel = imageModel
-        }
-    }
 }

+ 0 - 7
qml/views/cascade/Cascade.qml

@@ -164,11 +164,4 @@ Item {
     Component.onCompleted: {
         pictureDelegate.status !== Component.Ready && console.log('Component failed with:' + pictureDelegate.errorString())
     }
-
-    PictureModel {
-        id: imageModel
-        Component.onCompleted: {
-            globalUtil.imageModel = imageModel
-        }
-    }
 }

+ 1 - 7
qml/views/conveyor/Conveyor.qml

@@ -118,7 +118,7 @@ Item {
 
             density: 1
             height: root.height/conveyorSettings.rowCount
-            width: height/globalUtil.imageModel.data(modelIndex, PictureModel.SizeRole).height*globalUtil.imageModel.data(modelIndex, PictureModel.SizeRole).width
+            width: height/nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).height*nativeUtils.imageCollection.data(modelIndex, PictureModel.SizeRole).width
             bodyType: Body.Dynamic
             fixedRotation: true
 
@@ -213,10 +213,4 @@ Item {
             }
         "
     }
-    PictureModel {
-        id: imageModel
-        Component.onCompleted: {
-            globalUtil.imageModel = imageModel
-        }
-    }
 }

+ 5 - 9
qml/views/simplelistview/SimpleListView.qml

@@ -18,17 +18,13 @@ ListView {
         height: size.height
         width: size.width
         Component.onDestruction: {
-            d.settled ? globalUtil.imageModel.retireIndex(index) : undefined
+            d.settled ? nativeUtils.imageCollection.retireIndex(index) : undefined
         }
     }
-    model: globalUtil.imageModel
+    model: nativeUtils.imageCollection
 
-    PictureModel {
-        id: imageModel
-        Component.onCompleted: {
-            imageModel.assumeLinearAccess()
-            globalUtil.imageModel = imageModel
-            d.settled = true
-        }
+    Component.onCompleted: {
+        nativeUtils.imageCollection.assumeLinearAccess()
+        d.settled = true
     }
 }

+ 0 - 7
qml/views/trivial/Trivial.qml

@@ -132,11 +132,4 @@ Item {
         target: globalSettings
         onColumnCountChanged: console.log('Col count:' + globalSettings.columnCount)
     }
-
-    PictureModel {
-        id: imageModel
-        Component.onCompleted: {
-            globalUtil.imageModel = imageModel
-        }
-    }
 }

+ 1 - 1
qml/widgets/CollectionSize.qml

@@ -1,5 +1,5 @@
 import QtQuick 2.6
 
 Widget {
-    text: "DB:" + globalUtil.imageModel.count
+    text: "DB:" + nativeUtils.imageCollection.count
 }

+ 5 - 0
src/main.cpp

@@ -64,17 +64,20 @@ bool CloseEventFilter::eventFilter(QObject *obj, QEvent *event)
 class NativeUtils : public QObject {
     Q_OBJECT
     Q_PROPERTY(bool rebootRequired MEMBER rebootRequired NOTIFY rebootRequiredChanged)
+    Q_PROPERTY(PictureModel* imageCollection MEMBER imageCollection NOTIFY imageCollectionChanged)
 public:
     NativeUtils(QObject *p);
 
 signals:
     void rebootRequiredChanged();
+    void imageCollectionChanged();
 public slots:
     void monitorRunPath(const QString &path);
 private:
     QString watchFile;
     QFileSystemWatcher runDirWatcher;
     bool rebootRequired;
+    PictureModel *imageCollection;
 };
 
 NativeUtils::NativeUtils(QObject *p)
@@ -82,6 +85,8 @@ NativeUtils::NativeUtils(QObject *p)
       watchFile("/run/reboot-required"),
       rebootRequired(false)
 {
+    imageCollection = new PictureModel(this);
+    connect(imageCollection, &PictureModel::countChanged, this, &NativeUtils::imageCollectionChanged);
     runDirWatcher.addPath(QFileInfo(watchFile).absolutePath());
     connect(&runDirWatcher, &QFileSystemWatcher::directoryChanged, this, &NativeUtils::monitorRunPath);
     monitorRunPath("");

+ 7 - 6
src/picturemodel.cpp

@@ -65,7 +65,7 @@ struct ArtPiece {
 struct FSNode {
   FSNode(const QString& rname, const FSNode *pparent = nullptr);
 
-  static QString qualifyNode(const FSNode *node);
+  QString qualify() const;
 
   const QString name;
   const FSNode *parent;
@@ -82,9 +82,10 @@ FSNode::FSNode(const QString& rname, const FSNode *pparent)
 {
 }
 
-QString FSNode::qualifyNode(const FSNode *node) {
+QString FSNode::qualify() const {
     QString qualifiedPath;
 
+    const FSNode *node = this;
     while(node->parent != nullptr) {
         qualifiedPath = "/" + node->name + qualifiedPath;
         node = node->parent;
@@ -146,7 +147,7 @@ FSNodeTree::~FSNodeTree()
 void FSNodeTree::addModelNode(const FSNode* parentNode)
 {
     // TODO: Check for symlink recursion
-    QDir parentDir(FSNode::qualifyNode(parentNode));
+    QDir parentDir(parentNode->qualify());
 
     foreach(const QString &currentDir, parentDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
         const FSNode *dir = new FSNode(currentDir, parentNode);
@@ -159,7 +160,7 @@ void FSNodeTree::addModelNode(const FSNode* parentNode)
             continue;
 
         FSLeafNode *file = new FSLeafNode(currentFile, parentNode);
-        const QString fullPath = FSNode::qualifyNode(file);
+        const QString fullPath = file->qualify();
 
         QSize size = QImageReader(fullPath).size();
 
@@ -260,7 +261,7 @@ void FSNodeTree::dumpTreeToDb()
 
         for(int i = wave*itemCountPerWave; i < (wave*itemCountPerWave + itemCount); i++) {
             const FSLeafNode *node = files.at(i);
-            query.addBindValue(node->qualifyNode(node));
+            query.addBindValue(node->qualify());
             query.addBindValue(node->size.width());
             query.addBindValue(node->size.height());
         }
@@ -437,7 +438,7 @@ QVariant PictureModel::data(const QModelIndex &index, int role) const
             return d->fsTree->files.at(index.row())->name;
         case PathRole:
         default:
-            return QUrl::fromLocalFile(FSNode::qualifyNode(d->fsTree->files.at(index.row())));
+            return QUrl::fromLocalFile(d->fsTree->files.at(index.row())->qualify());
         }
     } else {
         int hashIndex = ::offsetHash(index.row());