Krita Source Code Documentation
Loading...
Searching...
No Matches
KisAbstractResourceModel Class Referenceabstract

#include <KisResourceModel.h>

+ Inheritance diagram for KisAbstractResourceModel:

Public Types

enum  Columns {
  Id = 0 , StorageId , Name , Filename ,
  Tooltip , Thumbnail , Status , Location ,
  ResourceType , Tags , MD5 , LargeThumbnail ,
  Dirty , MetaData , ResourceActive , StorageActive ,
  BrokenStatus , BrokenStatusMessage
}
 The Columns enum indexes the columns in the model. To get the thumbnail for a particular resource, create the index with QModelIndex(row, Thumbnail). More...
 

Public Member Functions

virtual bool addResource (KoResourceSP resource, const QString &storageId=QString(""))=0
 addResource adds the given resource to the database and storage. If the resource already exists in the given storage with md5, filename or name, the existing resource will be updated instead. If the existing resource was inactive, it will be active (undeleted).
 
virtual bool exportResource (KoResourceSP resource, QIODevice *device)=0
 exportResource exports a resource into a QIODevice
 
virtual KoResourceSP importResource (const QString &filename, QIODevice *device, const bool allowOverwrite, const QString &storageId=QString(""))=0
 importResource imports a resource from a QIODevice
 
virtual KoResourceSP importResourceFile (const QString &filename, const bool allowOverwrite, const QString &storageId=QString(""))=0
 importResourceFile
 
virtual bool importWillOverwriteResource (const QString &fileName, const QString &storageLocation=QString()) const =0
 importWillOverwriteResource checks is importing a resource with this filename will overwrite anything
 
virtual QModelIndex indexForResource (KoResourceSP resource) const =0
 indexFromResource
 
virtual QModelIndex indexForResourceId (int resourceId) const =0
 indexFromResource
 
virtual bool reloadResource (KoResourceSP resource)=0
 reloadResource
 
virtual bool renameResource (KoResourceSP resource, const QString &name)=0
 renameResource name the given resource. The resource will have its name field reset, will be saved to the storage and there will be a new version created in the database.
 
virtual KoResourceSP resourceForIndex (QModelIndex index=QModelIndex()) const =0
 resourceForIndex returns a properly versioned and id'ed resource object
 
virtual bool setResourceActive (const QModelIndex &index, bool value)=0
 setResourceActive changes 'active' state of the resource
 
bool setResourceInactive (const QModelIndex &index)
 
virtual bool setResourceMetaData (KoResourceSP resource, QMap< QString, QVariant > metadata)=0
 setResourceMetaData
 
virtual bool updateResource (KoResourceSP resource)=0
 updateResource creates a new version of the resource in the storage and in the database. This will also set the resource to active if it was inactive.
 
virtual ~KisAbstractResourceModel ()
 

Detailed Description

KisAbstractResourceModel defines the interface for accessing resources that is used in KisResourceModel and the various filter/proxy models

Definition at line 23 of file KisResourceModel.h.

Member Enumeration Documentation

◆ Columns

The Columns enum indexes the columns in the model. To get the thumbnail for a particular resource, create the index with QModelIndex(row, Thumbnail).

Enumerator
Id 
StorageId 
Name 
Filename 
Tooltip 
Thumbnail 
Status 

Whether the resource is active. Duplicate of ResourceActive.

Location 
ResourceType 
Tags 
MD5 
LargeThumbnail 

A larger thumbnail for displaying in a tooltip. 200x200 or so.

Dirty 

A dirty resource is one that has been modified locally but not saved.

MetaData 

MetaData is a map of key, value pairs that is associated with this resource.

ResourceActive 

Whether the current resource is active.

StorageActive 

Whether the current resource's storage is active.

BrokenStatus 

Whether the resource is broken (bool)

BrokenStatusMessage 

If resource is "broken", returns a non-empty string explaining why it is considered broken. Otherwise returns an empty QVariant.

Definition at line 32 of file KisResourceModel.h.

32 {
33 Id = 0,
35 Name,
37 Tooltip,
40 Status,
43 Tags,
44 MD5,
48 Dirty,
60 };
@ Status
Whether the resource is active. Duplicate of ResourceActive.
@ ResourceActive
Whether the current resource is active.
@ Dirty
A dirty resource is one that has been modified locally but not saved.
@ LargeThumbnail
A larger thumbnail for displaying in a tooltip. 200x200 or so.
@ MetaData
MetaData is a map of key, value pairs that is associated with this resource.
@ BrokenStatus
Whether the resource is broken (bool)
@ StorageActive
Whether the current resource's storage is active.

Constructor & Destructor Documentation

◆ ~KisAbstractResourceModel()

virtual KisAbstractResourceModel::~KisAbstractResourceModel ( )
inlinevirtual

Definition at line 62 of file KisResourceModel.h.

62{}

Member Function Documentation

◆ addResource()

virtual bool KisAbstractResourceModel::addResource ( KoResourceSP resource,
const QString & storageId = QString("") )
pure virtual

addResource adds the given resource to the database and storage. If the resource already exists in the given storage with md5, filename or name, the existing resource will be updated instead. If the existing resource was inactive, it will be active (undeleted).

Parameters
resourcethe resource itself
storageIdthe id of the storage (could be "memory" for temporary resources, the document's storage id for document storages or empty to save to the default resources folder
Returns
true if adding the resource succeeded.

Implemented in KisTagResourceModel, KisAllResourcesModel, KisResourceModel, and KisTagFilterResourceProxyModel.

◆ exportResource()

virtual bool KisAbstractResourceModel::exportResource ( KoResourceSP resource,
QIODevice * device )
pure virtual

exportResource exports a resource into a QIODevice

Exporting a resource as a binary blob is the only way to guarantee that its MD5 checksum is kept persistent. The underlying storage will just copy bytes into the device without doing any conversions

Parameters
resourcethe resource to be exported
devicedevice where the resource should be written to
Returns
true if export operation has been successful

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.

◆ importResource()

virtual KoResourceSP KisAbstractResourceModel::importResource ( const QString & filename,
QIODevice * device,
const bool allowOverwrite,
const QString & storageId = QString("") )
pure virtual

importResource imports a resource from a QIODevice

Importing a resource from a binary blob is the only way to guarantee that its MD5 checksum is kept persistent. The underlying storage will just copy bytes into its location.

Parameters
filenamefile name of the resource if preset. File name may be used for addressing the resource, so it is usually preferred to preserve it.
devicedevice where the resource should be read from
Returns
the loaded resource object

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.

◆ importResourceFile()

virtual KoResourceSP KisAbstractResourceModel::importResourceFile ( const QString & filename,
const bool allowOverwrite,
const QString & storageId = QString("") )
pure virtual

importResourceFile

Parameters
filename
Returns

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.

◆ importWillOverwriteResource()

virtual bool KisAbstractResourceModel::importWillOverwriteResource ( const QString & fileName,
const QString & storageLocation = QString() ) const
pure virtual

importWillOverwriteResource checks is importing a resource with this filename will overwrite anything

If this function returns true, then importResource() is guaranteed to fail with 'allowOverwrite' set to false.

Parameters
filenamefile name of the resource if preset. File name may be used for addressing the resource, so it is usually preferred to preserve it.
Returns
true if the some existing will be overwritten while importing

Implemented in KisTagFilterResourceProxyModel, KisTagResourceModel, KisAllResourcesModel, and KisResourceModel.

◆ indexForResource()

virtual QModelIndex KisAbstractResourceModel::indexForResource ( KoResourceSP resource) const
pure virtual

indexFromResource

Parameters
resource
Returns

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.

◆ indexForResourceId()

virtual QModelIndex KisAbstractResourceModel::indexForResourceId ( int resourceId) const
pure virtual

indexFromResource

Parameters
resourceIdresource id for which we want to get an index
Returns

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.

◆ reloadResource()

virtual bool KisAbstractResourceModel::reloadResource ( KoResourceSP resource)
pure virtual

reloadResource

Parameters
resource
Returns

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.

◆ renameResource()

virtual bool KisAbstractResourceModel::renameResource ( KoResourceSP resource,
const QString & name )
pure virtual

renameResource name the given resource. The resource will have its name field reset, will be saved to the storage and there will be a new version created in the database.

Parameters
resourceThe resource to rename
nameThe new name
Returns
true if the operation succeeded.

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.

◆ resourceForIndex()

virtual KoResourceSP KisAbstractResourceModel::resourceForIndex ( QModelIndex index = QModelIndex()) const
pure virtual

resourceForIndex returns a properly versioned and id'ed resource object

Implemented in KisTagResourceModel, KisAllResourcesModel, KisResourceModel, and KisTagFilterResourceProxyModel.

◆ setResourceActive()

virtual bool KisAbstractResourceModel::setResourceActive ( const QModelIndex & index,
bool value )
pure virtual

setResourceActive changes 'active' state of the resource

Parameters
indexthe index of the resource
valuenew 'active' state of the resource
Returns
true if the new state has been assigned successfully

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.

◆ setResourceInactive()

bool KisAbstractResourceModel::setResourceInactive ( const QModelIndex & index)
inline

A convenience function to put a resource into inactive state

Definition at line 94 of file KisResourceModel.h.

94 {
95 return setResourceActive(index, false);
96 }
virtual bool setResourceActive(const QModelIndex &index, bool value)=0
setResourceActive changes 'active' state of the resource

◆ setResourceMetaData()

virtual bool KisAbstractResourceModel::setResourceMetaData ( KoResourceSP resource,
QMap< QString, QVariant > metadata )
pure virtual

setResourceMetaData

Parameters
metadata
Returns

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.

◆ updateResource()

virtual bool KisAbstractResourceModel::updateResource ( KoResourceSP resource)
pure virtual

updateResource creates a new version of the resource in the storage and in the database. This will also set the resource to active if it was inactive.

Note: if the storage does not support versioning, updating the resource will fail.

Parameters
resource
Returns
true if the resource was successful updated,

Implemented in KisAllResourcesModel, KisResourceModel, KisTagFilterResourceProxyModel, and KisTagResourceModel.


The documentation for this class was generated from the following file: