Class sh::filesystem::FilesystemModel

class sh::filesystem::FilesystemModel : public QAbstractItemModel, public sh::base::Singleton

The filesystem model.

This is the engine which creates and manages sh::filesystem::FilesystemNode nodes. Filesystem nodes are used on many places for all kinds of operations.

Public Functions

std::shared_ptr<sh::filesystem::FilesystemNode> rootNode()

The sh::filesystem::FilesystemNode which is the root node of the entire model. It is the parent for all toplevel nodes.

QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
Qt::ItemFlags flags(const QModelIndex &index) const
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
QModelIndex parent(const QModelIndex &index) const
int rowCount(const QModelIndex &parent = QModelIndex()) const
int columnCount(const QModelIndex &parent = QModelIndex()) const
sh::filesystem::FilesystemModelFileviewProxy *createFileviewProxy(QModelIndex root, bool withtooltip, std::function<void(std::shared_ptr<sh::filesystem::FilesystemNode>)> onBecomesInvalid)

Creates a sh::filesystem::FilesystemModelFileviewProxy for presenting the content of a directory.

QList<QPersistentModelIndex> findIndexesForEurl(std::shared_ptr<const sh::filesystem::Eurl> eurl)

Get a list of qt model indexes for a sh::filesystem::Eurl.

If nodes for this eurl are unknown to the model so far, it tries to build them. In typical cases, this list either contains one element, or is empty if the filesystem handlers decide that this file does not exist. But in some cases, there is also more than one index for one sh::filesystem::Eurl (when the sh::filesystem::Eurl appears on more than one place in the tree).

QList<std::shared_ptr<sh::filesystem::FilesystemNode>> findNodesForEurl(std::shared_ptr<const sh::filesystem::Eurl> eurl)

Get a list of sh::filesystem::FilesystemNode for a sh::filesystem::Eurl.

If it is unknown to the model so far, it tries to build them. In typical cases, this list either contains one element, or is empty if the filesystem handlers decide that this file does not exist. But in some cases, there is also more than one node for one sh::filesystem::Eurl (when the sh::filesystem::Eurl appears on more than one place in the tree). It only returns nodes, which are ‘alive’, i.e. which have a living parent and which are a child of this parent.

QList<std::shared_ptr<sh::filesystem::FilesystemNode>> tryGetNodesForEurl(std::shared_ptr<const sh::filesystem::Eurl> eurl)

Returns a list of sh::filesystem::FilesystemNode for a sh::filesystem::Eurl. It only considers the current state of the in-memory model. It will only return nodes which are already known to the model so far. This operation is cheaper and handling only the known nodes is sufficient in many situations. In typical cases, this list either contains one element, or is empty. But in some cases, there is also more than one node for one sh::filesystem::Eurl (when the sh::filesystem::Eurl appears on more than one place in the tree). It only returns nodes, which are ‘alive’, i.e. which have a living parent and which are a child of this parent.

std::shared_ptr<sh::filesystem::FilesystemNode> getNodeForIndex(const QModelIndex index) const

Returns the sh::filesystem::FilesystemNode for a qt model index (in the main model).

QModelIndex getIndexForNode(std::shared_ptr<sh::filesystem::FilesystemNode> node)

Returns a qt model index (in the main model) for a sh::filesystem::FilesystemNode.

std::shared_ptr<sh::filesystem::FilesystemNode> createFilesystemNode(std::shared_ptr<const sh::filesystem::Eurl> eurl, sh::filesystem::FilesystemHandler *handler, sh::filesystem::FilesystemNodeType nodetype, bool isHidden, std::shared_ptr<sh::filesystem::FilesystemNode> parent, bool doinsert = true, bool showInitialLoadingLabel = true)

Creates a new sh::filesystem::FilesystemNode for placing it into the model.

If such a node (with the same eurl for the same parent node) does not exist, it generates a new one. If there already is such a node alive, but currently not placed in the model, it recycles this one. This can happen when references exist to a node which is not yet inserted or which is removed meanwhile. It is not allowed to call this method when such a node already exists in the model.

Use this function for getting a sh::filesystem::FilesystemNode, which is to be added to the model now or later. Depending on some parameter values, a call directly adds the node to the filesystem model (not e.g. when doinsert is false or parentnode is 0) It is typically used within a sh::filesystem::FilesystemHandler implementation.

std::shared_ptr<sh::filesystem::FilesystemNode> getOrCreateFilesystemNode(std::shared_ptr<const sh::filesystem::Eurl> neweurl, sh::filesystem::FilesystemHandler *handler, sh::filesystem::FilesystemNodeType nodetype, bool isHidden, std::shared_ptr<sh::filesystem::FilesystemNode> parent, bool doinsert = true, bool showInitialLoadingLabel = true, bool *pIsNew = 0)

Returns a sh::filesystem::FilesystemNode for using it as a child node in the model.

It either creates a new one, if there currently is no node for this eurl in this parentnode, or returns the existing one. Even for existing ones, this call can change the nodetype of that node.

Depending on some parameter values, a call directly adds the node to the filesystem model (not e.g. when doinsert is false or parent is 0).

void refreshData(std::shared_ptr<const sh::filesystem::Eurl> eurl, bool forceFindParent = false, bool withDetails = true)

Request to refresh the internal model information for a sh::filesystem::Eurl. This may be a place which is already known (then a change of some metadata or the removal is detected) or a formerly unknown place (then new nodes get inserted in the model).

void addOpenNodeHelper(int index, std::function<QList<std::shared_ptr<sh::filesystem::FilesystemNode>>(std::shared_ptr<const sh::filesystem::Eurl>)> openNodeHelper)

Registers a helper method for ‘opening’ (mounting, activating, …) locations on demand.

Only used in very rare cases.

~FilesystemModel()
void doInitialize()

Executes singleton initialization.

void doShutdown()

Executes singleton shutdown.

void shutdown()

Shutdown down this singleton.

bool isAlive()

Returns if this singleton is alive (true until its shutdown begins).

Private Functions

FilesystemModel()
QList<std::shared_ptr<sh::filesystem::FilesystemNode>> _findNodesForEurl_helper(std::shared_ptr<const sh::filesystem::Eurl> eurl)
QList<std::shared_ptr<sh::filesystem::FilesystemNode>> openRootEurl(std::shared_ptr<const sh::filesystem::Eurl> eurl)
void _subitemFetchingStateChanged(std::shared_ptr<sh::filesystem::FilesystemNode> node, bool value)

Private Members

QList< std::function< QList< std::shared_ptr< sh::filesystem::FilesystemNode > >std::shared_ptr< const sh::filesystem::Eurl >)> > _openNodeHelpers
QMap< int, std::function< QList< std::shared_ptr< sh::filesystem::FilesystemNode > >std::shared_ptr< const sh::filesystem::Eurl >)> > _openNodeHelpersMap
std::shared_ptr<sh::filesystem::FilesystemNode> rootnode
QMutex mutex
QHash<std::shared_ptr<const sh::filesystem::Eurl>, std::weak_ptr<sh::filesystem::FilesystemNode>> eurl2node
QMutex eurl2nodemutex
QMutex _nodeDataMutex
QMutex _openNodeHelpersMutex

Friends

friend class FilesystemNode
friend class LoadOnDemandPlaceholderFilesystemNode
friend class ModelBackedFilesystemNodeList
friend class ::sh::filesystem::DetailColumn