28 #include <QDataStream>
40 #define KLFLIBRESOURCEENGINE_WARN_NO_DEFAULT_SUBRESOURCE(func) \
41 if ((pFeatureFlags & FeatureSubResources) && pDefaultSubResource.isNull()) { \
42 qWarning("KLFLibResourceEngine::" func "(id): sub-resources are supported feature but" \
43 " no default sub-resource is specified!"); } \
55 initRegisteredProperties();
68 initRegisteredProperties();
84 initRegisteredProperties();
107 void KLFLibEntry::initRegisteredProperties()
125 if (s[0] ==
'%' && s[1] ==
':') {
126 return s.
mid(2).trimmed();
128 return QString::null;
134 if (s[0] ==
'%' && s[1] ==
':') {
136 s = latex.
section(
'\n', 1, 1, QString::SectionSkipEmpty);
139 return s.
mid(1).trimmed();
141 return QString::null;
148 while (k < latex.
length() && latex[k].isSpace())
150 if (k == latex.
length())
return "";
151 if (latex[k] ==
'%') {
153 if (k == latex.
length())
return "";
155 if (latex[k] ==
':') {
157 while (k < latex.
length() && latex[k] !=
'\n')
160 if (k >= latex.
length())
return "";
161 if (latex[k] !=
'%') {
166 if (k >= latex.
length())
return "";
169 while (k < latex.
length() && latex[k] !=
'\n')
172 if (k >= latex.
length())
return "";
185 s =
"%: "+category+
"\n";
197 QString c = categoryPath.
trimmed().split(
'/', QString::SkipEmptyParts).join(
"/");
210 : pCloneOf(NULL), pPropId(propId), pOrder(order)
214 : pCloneOf(clone), pPropId(clone->pPropId), pOrder(clone->pOrder)
224 if (pCloneOf != NULL) {
225 qWarning()<<
"Attempt to setPropId() in entry sorter that is a clone of "<<pCloneOf;
232 if (pCloneOf != NULL) {
233 qWarning()<<
"Attempt to setOrder() in entry sorter that is a clone of "<<pCloneOf;
243 if (pCloneOf != NULL)
264 int propId, Qt::SortOrder order)
const
266 if (pCloneOf != NULL)
271 if (order == Qt::AscendingOrder)
278 if (pCloneOf != NULL)
279 return pCloneOf->operator()(a, b);
289 registerEncoder(
this);
296 staticEncoderList.
append(encoder);
301 return staticEncoderList;
309 for (k = 0; k < staticEncoderList.
size(); ++k) {
310 encTypes << staticEncoderList[k]->supportedEncodingMimeTypes();
319 for (k = 0; k < staticEncoderList.
size(); ++k) {
320 decTypes << staticEncoderList[k]->supportedDecodingMimeTypes();
327 const QVariantMap& metaData)
331 for (k = 0; k < staticEncoderList.
size(); ++k) {
332 QStringList mimeTypeList = staticEncoderList[k]->supportedEncodingMimeTypes();
333 for (j = 0; j < mimeTypeList.size(); ++j) {
335 staticEncoderList[k]->encodeMime(entryList, metaData, mimeTypeList[j]);
337 klfDbg(
"Skipping mime type "<<mimeTypeList[k]<<
" because it did not provide any data.");
339 mime->
setData(mimeTypeList[j], data);
352 for (k = 0; k < fmts.size(); ++k) {
362 QVariantMap *metaDataPtr)
366 for (k = 0; k < fmts.size(); ++k) {
370 bool result = decoder->
decodeMime(mimeData->
data(fmts[k]), fmts[k], entryListPtr, metaDataPtr);
384 for (k = 0; k < staticEncoderList.
size(); ++k)
386 return staticEncoderList[k];
388 qWarning()<<
KLF_FUNC_NAME<<
": Failed to find encoder for mime-type "<<mimeType;
396 for (k = 0; k < staticEncoderList.
size(); ++k)
398 return staticEncoderList[k];
400 qWarning()<<
KLF_FUNC_NAME<<
": Failed to find decoder for mime-type "<<mimeType;
419 pFeatureFlags(featureflags), pReadOnly(false), pDefaultSubResource(
QString()),
420 pProgressBlocked(false), pThisOperationProgressBlockedOnly(false)
422 initRegisteredProperties();
428 if (rdonly.size() && rdonly.last() ==
"true") {
436 if (!defaultsubresource.isEmpty()) {
438 pDefaultSubResource = defaultsubresource.last();
447 void KLFLibResourceEngine::initRegisteredProperties()
462 !pDefaultSubResource.
isNull()) {
463 url.
addQueryItem(
"klfDefaultSubResource", pDefaultSubResource);
506 return pDefaultSubResource;
579 pReadOnly = readonly;
586 if (pDefaultSubResource == subResource)
589 pDefaultSubResource = subResource;
621 return entry(pDefaultSubResource,
id);
626 return hasEntry(pDefaultSubResource,
id);
633 return entries(pDefaultSubResource, idList, wantedEntryProperties);
640 return allEntries(pDefaultSubResource, wantedEntryProperties);
645 return allIds(pDefaultSubResource);
650 pProgressBlocked =
true;
651 pThisOperationProgressBlockedOnly =
true;
656 pProgressBlocked = block;
657 pThisOperationProgressBlockedOnly =
false;
662 bool blocked = pProgressBlocked;
663 if (pThisOperationProgressBlockedOnly)
664 pProgressBlocked =
false;
693 return changeEntries(pDefaultSubResource, idlist, properties, values);
819 return stream << entrywid.
id << entrywid.
entry;
823 return stream >> entrywid.
id >> entrywid.
entry;
843 return dbg<<
"EntryMatchCondition{...}";
845 dbg <<
"EntryMatchCondition{type=";
847 return dbg <<
"match-all}";
860 return dbg <<
"unknown-type}";
863 static const char *w_and =
" AND ";
864 static const char *w_or =
" OR ";
865 static const char *w_not =
" NOT ";
868 dbg << (word+1) <<
"; list: ";
871 for (k = 0; k < conditions.size(); ++k) {
874 dbg << conditions[k];
902 for (k = 0; k < idList.
size(); ++k)
903 idList << elist[k].
id;
910 return entry(subResource,
id).latex().size();
919 for (k = 0; k < idList.
size(); ++k)
929 return queryImpl(
this, subResource, query, result);
934 return queryValuesImpl(
this, subResource, entryPropId);
947 }
else if (list->
size() <= skip) {
950 *list = list->
mid(skip);
957 if (list->
size() > limit)
958 *list = list->
mid(0, limit);
972 if (result == NULL) {
973 qWarning()<<
KLF_FUNC_NAME<<
": expected valid `result' pointer";
985 for (k = 0; k < allEList.
size(); ++k) {
1002 klfDbgSt(
"About to return. Number of entries in TEE VALUE.") ;
1009 const QString& subResource,
int entryPropId)
1014 for (k = 0; k < allEList.
size(); ++k) {
1015 QVariant p = allEList[k].entry.property(entryPropId);
1031 switch (condition.
type()) {
1043 qWarning()<<
KLF_FUNC_NAME<<
": NOT condition with no arguments!";
1046 return ! testEntryMatchConditionImpl(condlist[0], libentry);
1051 for (k = 0; k < condlist.
size(); ++k) {
1052 if (testEntryMatchConditionImpl(condlist[k], libentry))
1060 for (k = 0; k < condlist.
size(); ++k) {
1061 if ( ! testEntryMatchConditionImpl(condlist[k], libentry) )
1066 qWarning()<<
KLF_FUNC_NAME<<
": KLFLib::EntryMatchCondition type "<<condition.
type()<<
" not known!";
1074 : mSorter(sorter), mResult(result)
1081 reference_is_rawentrylist =
true;
1083 reference_is_rawentrylist =
false;
1087 reference_is_rawentrylist =
true;
1092 if (reference_is_rawentrylist)
1093 return mResult->rawEntryList.size();
1095 return mResult->entryWithIdList.size();
1107 #define klf_lower_bound_entry \
1108 qLowerBound<KLFLibEntryList::iterator,KLFLibEntry,const KLFLibEntrySorter&>
1109 #define klf_lower_bound_ewid \
1110 qLowerBound<QList<KLFLibEntryWithId>::iterator,KLFLibEntryWithId,const QueryResultListSorter&>
1116 if (mSorter->propId() == -1) {
1118 if (reference_is_rawentrylist)
1119 pos = mResult->rawEntryList.size();
1121 pos = mResult->entryWithIdList.size();
1124 if (reference_is_rawentrylist) {
1125 KLFLibEntryList::iterator it =
1127 pos = it - mResult->rawEntryList.begin();
1130 klf_lower_bound_ewid(mResult->entryWithIdList.begin(), mResult->entryWithIdList.end(), ewid, *
this);
1131 pos = it - mResult->entryWithIdList.
begin();
1136 mResult->entryIdList.insert(pos, ewid.
id);
1138 mResult->rawEntryList.insert(pos, ewid.
entry);
1140 mResult->entryWithIdList.insert(pos, ewid);
1194 if ( factory == NULL ) {
1195 qWarning()<<
"KLFLibEngineFactory::openURL("<<url<<
"): No suitable factory found!";
1207 if ( resource == NULL ) {
1208 qWarning()<<
"KLFLibEngineFactory::listSubResources("<<url<<
"): Unable to open resource!";
1212 qWarning()<<
"KLFLibEngineFactory::listSubResources("<<url<<
"): Resource does not support sub-resources!";
1218 for (k = 0; k < subreslist.size(); ++k) {
1220 subresmap[subreslist[k]]
1224 subresmap[subreslist[k]] =
QString();
virtual bool saveTo(const QUrl &newPath)
virtual void setDefaultSubResource(const QString &subResource)
Set the default sub-resource.
virtual uint schemeFunctions(const QString &scheme) const
What this factory is capable of doing.
const QVariant matchValue() const
virtual bool canModifySubResourceProperty(const QString &subResource, int propId) const
static QString categoryFromLatex(const QString &latex)
static QStringList allDecodingMimeTypes()
data(const QString &mimeType)
virtual bool canRenameSubResource(const QString &subResource) const
static QList< QVariant > queryValuesImpl(KLFLibResourceEngine *resource, const QString &subResource, int entryPropId)
KLF_EXPORT QDataStream & operator<<(QDataStream &stream, const KLFLibResourceEngine::KLFLibEntryWithId &entrywid)
virtual bool hasEntry(const QString &, entryId id)
EntryMatchCondition(Type type)
KLFLibEntryMimeEncoder __klf_lib_mime_encoder
virtual bool createSubResource(const QString &subResource, const QString &subResourceTitle)
Create a new sub-resource.
virtual QVariant subResourceProperty(const QString &subResource, int propId) const
A structure that describes a query for query()
A cached value of the size of value in Preview.
virtual void setOrder(Qt::SortOrder order)
Set the sort order.
const Qt::MatchFlags matchFlags() const
int setEntryProperty(const QString &propName, const QVariant &value)
entries have to match with one of a list of conditions
Sub-Resources may be assigned properties and values.
QList< KLFLibEntry > KLFLibEntryList
#define KLF_DEBUG_TEE(expr)
virtual bool locked() const
Is this resource is locked?
arg(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char( ' ')
virtual QList< KLFLibEntryWithId > entries(const QString &subResource, const QList< KLFLib::entryId > &idList, const QList< int > &wantedEntryProperties=QList< int >())=0
query multiple entries in this resource
virtual bool canRegisterProperty(const QString &propName) const
virtual bool hasEntry(const QString &subResource, entryId id)=0
query the existence of an entry in this resource
virtual ~KLFLibEntrySorter()
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
virtual void setProperty(const QString &propname, const QVariant &value)
virtual bool setSubResourceProperty(const QString &subResource, int propId, const QVariant &value)
#define klfDbg(streamableItems)
static QStringList allSupportedSchemes()
virtual KLFLibResourceEngine * openResource(const QUrl &location, QObject *parent=NULL)=0
Qt::SortOrder orderDirection
void setStyle(const KLFStyle &style)
static QString stripCategoryTagsFromLatex(const QString &latex)
virtual QVariant resourceProperty(const QString &name) const
Get the value of a resource property.
Matches entries that don't match a condition.
void registerBuiltInProperty(int propId, const QString &propName) const
virtual bool setViewType(const QString &viewType)
virtual KLFLibEntry entry(const QString &subResource, entryId id)=0
query an entry in this resource
KLFLibEntrySorter(int propId=-1, Qt::SortOrder order=Qt::AscendingOrder)
static bool canDecodeMimeData(const QMimeData *mimeData)
virtual bool setTitle(const QString &title)
set a new resource title for this library resource
#define KLFLIBRESOURCEENGINE_WARN_NO_DEFAULT_SUBRESOURCE(func)
static EntryMatchCondition mkMatchAll()
void blockProgressReportingForNextOperation()
Specifies that the next operation (only) should not report progress.
static QString tagsFromLatex(const QString &latex)
KLFLibEngineFactory(QObject *parent=NULL)
virtual bool operator()(const KLFLibEntry &a, const KLFLibEntry &b) const
Helper class to sort entries into a KLFLibResourceEngine::QueryResult.
void setCategory(const QString &s)
QList< KLFLibEntryWithId > entryWithIdList
static QList< KLFAbstractLibEntryMimeEncoder * > encoderList()
virtual QStringList supportedEncodingMimeTypes() const =0
A list of mime types this class can encode.
static QStringList allEncodingMimeTypes()
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
virtual bool deleteSubResource(const QString &subResource)
KLF_EXPORT QDataStream & operator>>(QDataStream &stream, KLFLibResourceEngine::KLFLibEntryWithId &entrywid)
The Latex Code of the equation.
KLF_EXPORT bool klfMatch(const QVariant &testForHitCandidateValue, const QVariant &queryValue, Qt::MatchFlags flags, const QString &queryStringCache)
virtual bool isReadOnly() const
query read-only state
int registerProperty(const QString &propertyName) const
number(long n, int base=10)
virtual bool compareDefaultSubResourceEquals(const QString &subResourceName) const
Compare our sub-resource name to another.
bool propertyIdRegistered(int propId) const
bool thisOperationProgressBlocked() const
static EntryMatchCondition mkOrMatch(QList< EntryMatchCondition > conditions)
It's possible to modify that something.
KLFLibResourceEngine(const QUrl &url, uint supportedfeatureflags, QObject *parent=NULL)
virtual QList< KLFLib::entryId > allIds()
Returns all IDs in this resource (and the default sub-resource)
QueryResultListSorter(KLFLibEntrySorter *sorter, QueryResult *result)
QList< KLFLib::entryId > entryIdList
virtual bool setReadOnly(bool readonly)
Set the resource to be read-only or not.
virtual bool renameSubResource(const QString &oldSubResourceName, const QString &newSubResourceName)
const QString matchValueString() const
virtual bool setLocked(bool locked)
Set the resource to be locked.
void resourcePropertyChanged(int propId)
Emitted when a resource property changes.
Qt::SortOrder order() const
The currently set sorting order.
removeAllQueryItems(const QString &key)
KLFFactoryBase * findFactoryFor(const QString &objType)
virtual ~KLFLibEngineFactory()
static bool testEntryMatchConditionImpl(const KLFLib::EntryMatchCondition &condition, const KLFLibEntry &libentry)
Data can be stored in separate sub-resources.
void setDateTime(const QDateTime &dt)
int propId() const
The currently set property that will be queried in the items we're sorting.
void insertIntoOrderedResult(const KLFLibEntryWithId &entry)
KLFLibEntryList rawEntryList
endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive)
compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
int propertyIdForName(const QString &propertyName) const
virtual bool setResourceProperty(int propId, const QVariant &value)
Set a resource property to the given value.
static EntryMatchCondition mkPropertyMatch(PropertyMatch pmatch)
virtual bool saveResourceProperty(int propId, const QVariant &value)=0
Save a resource property to the backend resource data.
virtual KLFLibResourceEngine * createResource(const QString &scheme, const Parameters ¶meters, QObject *parent=NULL)
Create a new resource of given type and parameters.
virtual QList< KLFLibEntryWithId > entries(const QString &, const QList< KLFLib::entryId > &idList, const QList< int > &wantedEntryProperties=QList< int >())
The Category to which eq. belongs (path-style string)
That something is resource-locked (ie., the only possible action is to unlock it) ...
virtual bool decodeMime(const QByteArray &data, const QString &mimeType, KLFLibEntryList *entryList, QVariantMap *metaData) const =0
static EntryMatchCondition mkAndMatch(QList< EntryMatchCondition > conditions)
virtual bool canCreateSubResource() const
virtual bool deleteEntries(const QString &subResource, const QList< entryId > &idlist)=0
Delete some entries in this resource.
virtual QString entryValue(const KLFLibEntry &entry, int propId) const
Returns a string representation of the given property in the given entry.
virtual QString defaultSubResource() const
Add a query item for default sub-res. as "klfDefaultSubResource".
#define KLF_DEBUG_TIME_BLOCK(msg)
void setPreviewSize(const QSize &sz)
void setTags(const QString &s)
static QString latexAddCategoryTagsComment(const QString &latex, const QString &category, const QString &tags)
#define KLF_FUNC_SINGLE_RUN
static KLFAbstractLibEntryMimeEncoder * findDecoderFor(const QString &mimeType, bool warnIfNotFound=true)
virtual uint supportedFeatureFlags() const
List of features supported by this resource engine.
virtual bool canModifyData(const QString &subResource, ModifyType modifytype) const
virtual QList< entryId > insertEntries(const QString &subResource, const KLFLibEntryList &entrylist)=0
Insert new entries in this resource.
virtual QStringList subResourceList() const
Tags about the equation (string)
QMap< QString, QVariant > allProperties() const
virtual int query(const QString &subResource, const Query &query, QueryResult *result)
static bool decodeMimeData(const QMimeData *mimeData, KLFLibEntryList *entryList, QVariantMap *metaData)
void blockProgressReporting(bool block)
(Un)Blocks generally progress reporting
QList< EntryMatchCondition > mConditionList
entries have to match with all given conditions
static QStringList listSubResources(const QUrl &url)
Add a query item for read-only status, as "klfReadOnly".
A structure that will hold the result of a query() query.
static EntryMatchCondition mkNegateMatch(const EntryMatchCondition &condition)
virtual QStringList supportedDecodingMimeTypes() const =0
A list of mime types this class can decode.
mid(int position, int n=-1)
static int queryImpl(KLFLibResourceEngine *resource, const QString &subResource, const Query &query, QueryResult *result)
An entry (single formula) in the library.
void defaultSubResourceChanged(const QString &newDefaultSubResource)
Emitted when the default sub-resource changes.
QList< int > wantedEntryProperties
virtual QList< QVariant > queryValues(const QString &subResource, int entryPropId)
virtual bool hasSubResource(const QString &subResource) const
virtual bool loadResourceProperty(const QString &propName, const QVariant &value)
Set the given property to the given value.
static KLFLibEngineFactory * findFactoryFor(const QUrl &url)
KLFAbstractLibEntryMimeEncoder()
#define klfDbgSt(streamableItems)
QStringList allSupportedTypes()
static KLFAbstractLibEntryMimeEncoder * findEncoderFor(const QString &mimeType, bool warnIfNotFound=true)
An Image Preview of equation (scaled down QImage)
virtual bool compareLessThan(const KLFLibEntry &a, const KLFLibEntry &b, int propId, Qt::SortOrder order) const
Compares entries two entries according to the given property and order.
virtual bool changeEntries(const QString &subResource, const QList< entryId > &idlist, const QList< int > &properties, const QList< QVariant > &values)=0
Change some entries in this resource.
Matches a property ID with a string (with a StringMatch)
static KLFLibResourceEngine * openURL(const QUrl &location, QObject *parent=NULL)
mid(int pos, int length=-1)
static QMap< QString, QString > listSubResourcesWithTitles(const QUrl &url)
virtual QList< KLFLibEntryWithId > allEntries(const QString &subResource, const QList< int > &wantedEntryProperties=QList< int >())=0
query all entries in this resource
virtual ~KLFAbstractLibEntryMimeEncoder()
section(QChar sep, int start, int end=-1, SectionFlags flags=SectionDefault)
void setAllProperties(const QMap< QString, QVariant > &propValues)
addQueryItem(const QString &key, const QString &value)
Helper class to encode an entry list as mime data (abstract interface)
#define klf_lower_bound_entry
virtual QVariant property(const QString &propName) const
A KLFLibEntry in combination with a KLFLib::entryId.
KLFLibEntry(const QString &latex=QString(), const QDateTime &dt=QDateTime(), const QImage &preview=QImage(), const QSize &previewsize=QSize(), const QString &category=QString(), const QString &tags=QString(), const KLFStyle &style=KLFStyle())
PropertyMatch mPropertyMatch
void setPreview(const QImage &img)
setData(const QString &mimeType, const QByteArray &data)
Utility class for sorting library entry items.
virtual ModifyStatus baseCanModifyStatus(bool inSubResource, const QString &subResource=QString()) const
can modify data in resource (base common tests only)
virtual QUrl url(uint flags=0x0) const
query URL
Type type() const
Get which type of condition this is.
An abstract resource engine.
allQueryItemValues(const QString &key)
virtual ~KLFLibResourceEngine()
The Date/Time at which the equation was evaluated.
static QMimeData * createMimeData(const KLFLibEntryList &entryList, const QVariantMap &metaData)
Creates a QMetaData with all known registered encoding mime types.
KLFLib::EntryMatchCondition matchCondition
virtual bool canDeleteSubResource(const QString &subResource) const
virtual bool canModifyProp(int propId) const
virtual void setPropId(int propId)
Set the KLFLibEntry property id the sort will take into account.
static void qlist_skip_and_limit(QList< T > *list, int skip, int limit)
localeAwareCompare(const QString &s1, const QString &s2)
virtual entryId insertEntry(const QString &subResource, const KLFLibEntry &entry)
Insert an entry into this resource.
That something is read-only or not modifiable for another reason.
#define klf_lower_bound_ewid
virtual QString subResourcePropertyName(int propId) const
virtual bool saveResourceTo(KLFLibResourceEngine *resource, const QUrl &newLocation)
Save the given resource to a new location.
PropertyMatch propertyMatch() const
Relevant for type PropertyMatchType.
That something is sub-resource-locked.
QSize previewSize() const
static QString normalizeCategoryPath(const QString &categoryPath)
QList< EntryMatchCondition > conditionList() const
Relevant for types OrMatchType and AndMatchType.
void setLatex(const QString &latex)