Utility class to load image and video content from a folder into a container widget. More...
#include <MultiWidgets/ContentLoader.hpp>
Public Types | |
| enum | Concurrency { SYNCHRONOUS, ASYNCHRONOUS } |
| Concurrency is used to determine wether the ContentLoader operates in synchronous or asynchronous mode. More... | |
Public Member Functions | |
| ContentLoader () | |
| Construct a new ContentLoader. | |
| bool | isRecreateDeleted () const |
| Are deleted widgets recreated when files change. More... | |
| bool | isRecursive () const |
| Is the ContentLoader using recursive loading of directories. | |
| void | onChange (std::function< void(const MultiWidgets::WidgetPtr &w)> callback) |
| Set the callback for changed widgets. More... | |
| void | onCreate (std::function< void(const MultiWidgets::WidgetPtr &w)> callback) |
| Set the callback for created widgets. More... | |
| void | onRemove (std::function< void(const MultiWidgets::WidgetPtr &w)> callback) |
| Set the callback for removed widgets. More... | |
| bool | populate (const QString &source, Concurrency concurrency=SYNCHRONOUS, bool stopPendingAsync=false) |
| Loads all content from the given source. More... | |
| bool | populate (const QStringList &sources, Concurrency concurrency=SYNCHRONOUS, bool stopPendingAsync=false) |
| Loads all content from the given sources. More... | |
| void | setContainer (WidgetContainer &) |
| Sets the container to use when populating. More... | |
| void | setFilter (std::function< bool(const QString &filePath)> filter) |
| Set an input filter All files that the ContentLoader will attempt to load are first passed through the input filter if it has been specified. More... | |
| void | setFilter (const QRegExp &filter) |
| Set an input filter that performs regular expression matching. More... | |
| void | setFilter (const QStringList &patterns) |
| Set input filter that performs MIME pattern matching. More... | |
| void | setRecreateDeleted (bool recreate) |
| Set if deleted widgets should be recreated. More... | |
| void | setRecursive (bool recursive) |
| Set if the ContentLoader should recursively traverse input directories. | |
| ~ContentLoader () | |
| Destroy the ContentLoader. | |
Static Public Member Functions | |
| static void | populateContainerFromFolder (WidgetContainer &cont, const QString &dirname) |
| Populate a given container form a folder, using synchronous loading. More... | |
Public Attributes | |
| std::unique_ptr< D > | m_d |
Utility class to load image and video content from a folder into a container widget.
This class can not be used without MultiWidgets::Application.
Concurrency is used to determine wether the ContentLoader operates in synchronous or asynchronous mode.
| Enumerator | |
|---|---|
| SYNCHRONOUS |
Synchronous operation. |
| ASYNCHRONOUS |
Asynchronous operation. |
| bool MultiWidgets::ContentLoader::isRecreateDeleted | ( | ) | const |
Are deleted widgets recreated when files change.
| void MultiWidgets::ContentLoader::onChange | ( | std::function< void(const MultiWidgets::WidgetPtr &w)> | callback | ) |
Set the callback for changed widgets.
The given function gets called every time a file changes on the filesystem that has a widget associated with it. I.e. the loader previously created a widget for it. The function gets called in the main-thread after update.
| callback | function to call |
| void MultiWidgets::ContentLoader::onCreate | ( | std::function< void(const MultiWidgets::WidgetPtr &w)> | callback | ) |
Set the callback for created widgets.
The given function gets called every time a new widget is created by the loader. For example, when a file is added on the filesystem. The function is called in the main-thread after update.
| callback | function to call |
| void MultiWidgets::ContentLoader::onRemove | ( | std::function< void(const MultiWidgets::WidgetPtr &w)> | callback | ) |
Set the callback for removed widgets.
The given function gets called every time a file is removed on the filesystem that has a widget associated with it. I.e. the loader previously created a widget for it. The function gets called in the main-thread after update.
| callback | function to call |
| bool MultiWidgets::ContentLoader::populate | ( | const QString & | source, |
| Concurrency | concurrency = SYNCHRONOUS, |
||
| bool | stopPendingAsync = false |
||
| ) |
Loads all content from the given source.
| source | directory to traverse for content |
| concurrency | operation mode |
| stopPendingAsync | if pending asynchronous populate tasks should be stopped. This only affects already running asynchronous tasks. |
| bool MultiWidgets::ContentLoader::populate | ( | const QStringList & | sources, |
| Concurrency | concurrency = SYNCHRONOUS, |
||
| bool | stopPendingAsync = false |
||
| ) |
Loads all content from the given sources.
| sources | list of directories to traverse for content |
| concurrency | operation mode |
| stopPendingAsync | if pending asynchronous populate tasks should be stopped. This only affects already running asynchronous tasks. |
|
static |
Populate a given container form a folder, using synchronous loading.
| container | WidgetContainer holding the newly created widgets. |
| dirname | Directory name where widgets are loaded. |
| void MultiWidgets::ContentLoader::setContainer | ( | WidgetContainer & | ) |
Sets the container to use when populating.
This function creates a set of standard callbacks for creating, changing and removing widgets and therefore overrides any previously set callbacks.
| void MultiWidgets::ContentLoader::setFilter | ( | std::function< bool(const QString &filePath)> | filter | ) |
Set an input filter All files that the ContentLoader will attempt to load are first passed through the input filter if it has been specified.
The input for the filter is the absolute file path of the content file. If the filter returns true, the content is instantiated; otherwise it is ignored.
| void MultiWidgets::ContentLoader::setFilter | ( | const QRegExp & | filter | ) |
Set an input filter that performs regular expression matching.
This is an utility function that creates a filter which uses a regular expression to filter input files. For a file to pass the input filter, the given regular expression must match the input filepath.
| filter | regular expression used to match input files |
| void MultiWidgets::ContentLoader::setFilter | ( | const QStringList & | patterns | ) |
Set input filter that performs MIME pattern matching.
This is an utility function that creates a filter which uses MIME patterns to filter input files. For a file to pass the input filter, it's MIME type must match the given patterns.
| patterns | list of MIME patterns |
| void MultiWidgets::ContentLoader::setRecreateDeleted | ( | bool | recreate | ) |
Set if deleted widgets should be recreated.
This affects the situation where a widget that was instantiated from a file has been deleted but the file changes. If recreate deleted is true, a new widget will be instantiated and passed to the onChange() callback. If recreate deleted is false, new widget is not instantiated and the callback is not called.
| recreate | recreate deleted widgets on file changes |