[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klflib.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * file klflib.cpp
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klflib.cpp 627 2011-04-12 12:36:22Z phfaist $ */
23 
24 #include <QDebug>
25 #include <QString>
26 #include <QBuffer>
27 #include <QByteArray>
28 #include <QDataStream>
29 #include <QColor>
30 #include <QMimeData>
31 
32 #include <klfutil.h>
33 #include "klflib_p.h"
34 #include "klflib.h"
35 
36 
37 
38 
39 // issue a warning if no default sub-resource is set
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!"); } \
44 
45 
46 
47 // ----------------------
48 
49 
50 KLFLibEntry::KLFLibEntry(const QString& latex, const QDateTime& dt, const QImage& preview,
51  const QSize& previewsize, const QString& category, const QString& tags,
52  const KLFStyle& style)
53  : KLFPropertizedObject("KLFLibEntry")
54 {
55  initRegisteredProperties();
56  setLatex(latex);
57  setDateTime(dt);
58  setPreview(preview);
59  setPreviewSize(previewsize);
60  setCategory(category);
61  setTags(tags);
62  setStyle(style);
63 }
64 KLFLibEntry::KLFLibEntry(const QString& latex, const QDateTime& dt, const QImage& preview,
65  const KLFStyle& style)
66  : KLFPropertizedObject("KLFLibEntry")
67 {
68  initRegisteredProperties();
69  QString latexonly = stripCategoryTagsFromLatex(latex);
71  QString tags = tagsFromLatex(latex);
72  QSize previewsize = preview.size();
73  setLatex(latexonly);
74  setDateTime(dt);
75  setPreview(preview);
76  setPreviewSize(previewsize);
77  setCategory(category);
78  setTags(tags);
79  setStyle(style);
80 }
82  : KLFPropertizedObject("KLFLibEntry")
83 {
84  initRegisteredProperties();
86 }
88 {
89 }
90 
91 
92 int KLFLibEntry::setEntryProperty(const QString& propName, const QVariant& value)
93 {
94  int propId = propertyIdForName(propName);
95  if (propId < 0) {
96  // register the property
97  propId = registerProperty(propName);
98  if (propId < 0)
99  return -1;
100  }
101  // and set the property
102  setProperty(propId, value);
103  return propId;
104 }
105 
106 // private, static
107 void KLFLibEntry::initRegisteredProperties()
108 {
110 
111  registerBuiltInProperty(Latex, "Latex");
112  registerBuiltInProperty(DateTime, "DateTime");
113  registerBuiltInProperty(Preview, "Preview");
114  registerBuiltInProperty(PreviewSize, "PreviewSize");
115  registerBuiltInProperty(Category, "Category");
116  registerBuiltInProperty(Tags, "Tags");
117  registerBuiltInProperty(Style, "Style");
118 }
119 
120 
121 // static
123 {
124  QString s = latex.section('\n', 0, 0, QString::SectionSkipEmpty);
125  if (s[0] == '%' && s[1] == ':') {
126  return s.mid(2).trimmed();
127  }
128  return QString::null;
129 }
130 // static
132 {
133  QString s = latex.section('\n', 0, 0, QString::SectionSkipEmpty);
134  if (s[0] == '%' && s[1] == ':') {
135  // category is s.mid(2);
136  s = latex.section('\n', 1, 1, QString::SectionSkipEmpty);
137  }
138  if (s[0] == '%') {
139  return s.mid(1).trimmed();
140  }
141  return QString::null;
142 }
143 
144 // static
146 {
147  int k = 0;
148  while (k < latex.length() && latex[k].isSpace())
149  ++k;
150  if (k == latex.length()) return "";
151  if (latex[k] == '%') {
152  ++k;
153  if (k == latex.length()) return "";
154  //strip category and/or tag:
155  if (latex[k] == ':') {
156  // strip category
157  while (k < latex.length() && latex[k] != '\n')
158  ++k;
159  ++k;
160  if (k >= latex.length()) return "";
161  if (latex[k] != '%') {
162  // there isn't any tags, just category; return rest of string
163  return latex.mid(k);
164  }
165  ++k;
166  if (k >= latex.length()) return "";
167  }
168  // strip tag:
169  while (k < latex.length() && latex[k] != '\n')
170  ++k;
171  ++k;
172  if (k >= latex.length()) return "";
173  }
174  // k is the beginnnig of the latex string
175  return latex.mid(k);
176 }
177 
178 // static
180  const QString& tags)
181 {
182  QString s;
183 
184  if (!category.isEmpty())
185  s = "%: "+category+"\n";
186 
187  if (!tags.isEmpty())
188  s += "% "+tags+"\n";
189 
190  s += latex;
191  return s;
192 }
193 
194 // static
196 {
197  QString c = categoryPath.trimmed().split('/', QString::SkipEmptyParts).join("/");
198  if (c.endsWith("/"))
199  c.chop(1);
200  return c;
201 }
202 
203 
204 
205 // ------------------------------------------------------------
206 
207 
208 
209 KLFLibEntrySorter::KLFLibEntrySorter(int propId, Qt::SortOrder order)
210  : pCloneOf(NULL), pPropId(propId), pOrder(order)
211 {
212 }
214  : pCloneOf(clone), pPropId(clone->pPropId), pOrder(clone->pOrder)
215 {
216 }
217 
219 {
220 }
221 
223 {
224  if (pCloneOf != NULL) {
225  qWarning()<<"Attempt to setPropId() in entry sorter that is a clone of "<<pCloneOf;
226  return;
227  }
228  pPropId = propId;
229 }
230 void KLFLibEntrySorter::setOrder(Qt::SortOrder order)
231 {
232  if (pCloneOf != NULL) {
233  qWarning()<<"Attempt to setOrder() in entry sorter that is a clone of "<<pCloneOf;
234  return;
235  }
236  pOrder = order;
237 }
238 
239 
240 
241 QString KLFLibEntrySorter::entryValue(const KLFLibEntry& entry, int propId) const
242 {
243  if (pCloneOf != NULL)
244  return pCloneOf->entryValue(entry, propId);
245 
246  // return an internal string representation of the value of the property 'propId' in libentry 'entry'
247 
248  // user friendliness. sort by date when selecting preview.
249  if (propId == KLFLibEntry::Preview)
250  propId = KLFLibEntry::DateTime;
251 
252  if (propId == KLFLibEntry::PreviewSize) {
253  QSize s = entry.previewSize();
254  // eg. "0000000280,0000000180" for 280x180
255  return QString("%1,%2").arg(s.width(), 10, 10, QChar('0')).arg(s.height(), 10, 10, QChar('0'));
256  }
257  if (propId == KLFLibEntry::DateTime) {
258  return entry.property(KLFLibEntry::DateTime).toDateTime().toString("yyyy-MM-dd+hh:mm:ss.zzz");
259  }
260  return entry.property(propId).toString();
261 }
262 
264  int propId, Qt::SortOrder order) const
265 {
266  if (pCloneOf != NULL)
267  return pCloneOf->compareLessThan(a, b, propId, order);
268 
269  QString as = entryValue(a, propId);
270  QString bs = entryValue(b, propId);
271  if (order == Qt::AscendingOrder)
272  return QString::localeAwareCompare(as, bs) < 0;
273  return QString::localeAwareCompare(as, bs) > 0;
274 }
275 
277 {
278  if (pCloneOf != NULL)
279  return pCloneOf->operator()(a, b);
280 
281  return compareLessThan(a, b, pPropId, pOrder);
282 }
283 
284 
285 // ---------------------------------------------------
286 
288 {
289  registerEncoder(this);
290 }
292 {
293 }
294 void KLFAbstractLibEntryMimeEncoder::registerEncoder(KLFAbstractLibEntryMimeEncoder *encoder)
295 {
296  staticEncoderList.append(encoder);
297 }
298 
300 {
301  return staticEncoderList;
302 }
303 
304 // static
306 {
307  QStringList encTypes;
308  int k;
309  for (k = 0; k < staticEncoderList.size(); ++k) {
310  encTypes << staticEncoderList[k]->supportedEncodingMimeTypes();
311  }
312  return encTypes;
313 }
314 // static
316 {
317  QStringList decTypes;
318  int k;
319  for (k = 0; k < staticEncoderList.size(); ++k) {
320  decTypes << staticEncoderList[k]->supportedDecodingMimeTypes();
321  }
322  return decTypes;
323 }
324 
325 // static
327  const QVariantMap& metaData)
328 {
329  QMimeData *mime = new QMimeData;
330  int k, j;
331  for (k = 0; k < staticEncoderList.size(); ++k) {
332  QStringList mimeTypeList = staticEncoderList[k]->supportedEncodingMimeTypes();
333  for (j = 0; j < mimeTypeList.size(); ++j) {
334  QByteArray data =
335  staticEncoderList[k]->encodeMime(entryList, metaData, mimeTypeList[j]);
336  if (data.isEmpty()) {
337  klfDbg("Skipping mime type "<<mimeTypeList[k]<<" because it did not provide any data.");
338  } else {
339  mime->setData(mimeTypeList[j], data);
340  }
341  }
342  }
343  return mime;
344 }
345 
346 
347 // static
349 {
350  QStringList fmts = mimeData->formats();
351  int k;
352  for (k = 0; k < fmts.size(); ++k) {
353  if (findDecoderFor(fmts[k], false) != NULL)
354  return true;
355  }
356  return false;
357 }
358 
359 // static
361  KLFLibEntryList *entryListPtr,
362  QVariantMap *metaDataPtr)
363 {
364  QStringList fmts = mimeData->formats();
365  int k;
366  for (k = 0; k < fmts.size(); ++k) {
367  KLFAbstractLibEntryMimeEncoder *decoder = findDecoderFor(fmts[k], false);
368  if (decoder == NULL)
369  continue;
370  bool result = decoder->decodeMime(mimeData->data(fmts[k]), fmts[k], entryListPtr, metaDataPtr);
371  if ( result )
372  return true;
373  // else continue trying
374  }
375  return false;
376 }
377 
378 
379 
381  bool warn)
382 {
383  int k;
384  for (k = 0; k < staticEncoderList.size(); ++k)
385  if (staticEncoderList[k]->supportedEncodingMimeTypes().contains(mimeType))
386  return staticEncoderList[k];
387  if (warn)
388  qWarning()<<KLF_FUNC_NAME<<": Failed to find encoder for mime-type "<<mimeType;
389  return NULL;
390 }
391 
393  bool warn)
394 {
395  int k;
396  for (k = 0; k < staticEncoderList.size(); ++k)
397  if (staticEncoderList[k]->supportedDecodingMimeTypes().contains(mimeType))
398  return staticEncoderList[k];
399  if (warn)
400  qWarning()<<KLF_FUNC_NAME<<": Failed to find decoder for mime-type "<<mimeType;
401  return NULL;
402 }
403 
404 
405 QList<KLFAbstractLibEntryMimeEncoder*> KLFAbstractLibEntryMimeEncoder::staticEncoderList;
406 
407 
408 
409 
410 // The instance of the basic encoder, that will auto-register itself
412 
413 
414 // ---------------------------------------------------
415 
416 KLFLibResourceEngine::KLFLibResourceEngine(const QUrl& url, uint featureflags,
417  QObject *parent)
418  : QObject(parent), KLFPropertizedObject("KLFLibResourceEngine"), pUrl(url),
419  pFeatureFlags(featureflags), pReadOnly(false), pDefaultSubResource(QString()),
420  pProgressBlocked(false), pThisOperationProgressBlockedOnly(false)
421 {
422  initRegisteredProperties();
423 
424  // klfDbg( "KLFLibResourceEngine::KLFLibResourceEngine("<<url<<","<<pFeatureFlags<<","
425  // <<parent<<")" ) ;
426 
427  QStringList rdonly = pUrl.allQueryItemValues("klfReadOnly");
428  if (rdonly.size() && rdonly.last() == "true") {
429  if (pFeatureFlags & FeatureReadOnly)
430  pReadOnly = true;
431  }
432  pUrl.removeAllQueryItems("klfReadOnly");
433 
434  if (pFeatureFlags & FeatureSubResources) {
435  QStringList defaultsubresource = pUrl.allQueryItemValues("klfDefaultSubResource");
436  if (!defaultsubresource.isEmpty()) {
437  pUrl.removeAllQueryItems("klfDefaultSubResource");
438  pDefaultSubResource = defaultsubresource.last();
439  }
440  }
441 
442 }
444 {
445 }
446 
447 void KLFLibResourceEngine::initRegisteredProperties()
448 {
450 
454  registerBuiltInProperty(PropAccessShared, "AccessShared");
455 }
456 
458 {
459  QUrl url = pUrl;
460  if (flags & WantUrlDefaultSubResource &&
461  (pFeatureFlags & FeatureSubResources) &&
462  !pDefaultSubResource.isNull()) {
463  url.addQueryItem("klfDefaultSubResource", pDefaultSubResource);
464  }
465  if (flags & WantUrlReadOnly) {
466  url.addQueryItem("klfReadOnly", pReadOnly?QString("true"):QString("false"));
467  }
468  return url;
469 }
470 
471 
473  ModifyType /*modifytype*/) const
474 {
475  return baseCanModifyStatus(true, subResource) == MS_CanModify;
476 }
477 
479 {
481  return canModifyData(pDefaultSubResource, modifytype);
482 }
483 
484 
486 {
487  ModifyStatus ms = baseCanModifyStatus(false);
488  return ms == MS_CanModify ||
489  (ms == MS_IsLocked && propId == PropLocked); // allow un-locking (!)
490 }
491 bool KLFLibResourceEngine::canRegisterProperty(const QString& /*propName*/) const
492 {
493  return false;
494 }
495 
496 bool KLFLibResourceEngine::hasSubResource(const QString& subResource) const
497 {
498  if ( !(pFeatureFlags & FeatureSubResources) )
499  return false;
500 
501  return subResourceList().contains(subResource);
502 }
503 
505 {
506  return pDefaultSubResource;
507 }
508 
510 {
511  return QString::compare(pDefaultSubResource, subResourceName) == 0;
512 }
513 
515 {
516  return false;
517 }
518 
519 bool KLFLibResourceEngine::canRenameSubResource(const QString& /*subResource*/) const
520 {
521  return false;
522 }
523 bool KLFLibResourceEngine::canDeleteSubResource(const QString& /*subResource*/) const
524 {
525  return false;
526 }
527 
528 QVariant KLFLibResourceEngine::subResourceProperty(const QString& /*subResource*/, int /*propId*/) const
529 {
530  return QVariant();
531 }
532 
534 {
535  switch (propId) {
536  case SubResPropTitle:
537  return QLatin1String("Title");
538  case SubResPropLocked:
539  return QLatin1String("Locked");
540  case SubResPropViewType:
541  return QLatin1String("ViewType");
542  default:
543  ;
544  }
545  return QString::number(propId);
546 }
547 
548 bool KLFLibResourceEngine::canModifySubResourceProperty(const QString& subResource, int propId) const
549 {
550  ModifyStatus ms = baseCanModifyStatus(true, subResource);
551  return ms == MS_CanModify ||
552  (ms == MS_SubResLocked && propId == SubResPropLocked); // allow sub-resource un-locking
553 }
554 
556 {
557  return setResourceProperty(PropTitle, title);
558 }
560 {
561  // if locked feature is supported, setResourceProperty().
562  // immediately return FALSE otherwise.
563  if (pFeatureFlags & FeatureLocked) {
564  return setResourceProperty(PropLocked, setlocked);
565  }
566  return false;
567 }
568 
570 {
571  return setResourceProperty(PropViewType, viewType);
572 }
573 
575 {
576  if ( !(pFeatureFlags & FeatureReadOnly) )
577  return false;
578 
579  pReadOnly = readonly;
580  return true;
581 }
582 
583 
585 {
586  if (pDefaultSubResource == subResource)
587  return;
588 
589  pDefaultSubResource = subResource;
590  emit defaultSubResourceChanged(subResource);
591 }
592 
593 bool KLFLibResourceEngine::setSubResourceProperty(const QString& /*subResource*/, int /*propId*/,
594  const QVariant& /*value*/)
595 {
596  return false;
597 }
598 
600  const QString& /*subResourceTitle*/)
601 {
602  return false;
603 }
605 {
606  return createSubResource(subResource, QString());
607 }
608 bool KLFLibResourceEngine::renameSubResource(const QString& /*old*/, const QString& /*new*/)
609 {
610  return false;
611 }
613 {
614  return false;
615 }
616 
617 
619 {
621  return entry(pDefaultSubResource, id);
622 }
624 {
626  return hasEntry(pDefaultSubResource, id);
627 }
630  const QList<int>& wantedEntryProperties)
631 {
633  return entries(pDefaultSubResource, idList, wantedEntryProperties);
634 }
635 
637 /* */ KLFLibResourceEngine::allEntries(const QList<int>& wantedEntryProperties)
638 {
640  return allEntries(pDefaultSubResource, wantedEntryProperties);
641 }
643 {
645  return allIds(pDefaultSubResource);
646 }
647 
649 {
650  pProgressBlocked = true;
651  pThisOperationProgressBlockedOnly = true;
652 }
653 
655 {
656  pProgressBlocked = block;
657  pThisOperationProgressBlockedOnly = false;
658 }
659 
661 {
662  bool blocked = pProgressBlocked;
663  if (pThisOperationProgressBlockedOnly)
664  pProgressBlocked = false; // reset for next operation
665  return blocked;
666 }
667 
668 
670  const KLFLibEntry& entry)
671 {
672  QList<entryId> ids = insertEntries(subResource, KLFLibEntryList() << entry);
673  if (ids.size() == 0)
674  return -1;
675 
676  return ids[0];
677 }
679 {
681  return insertEntry(pDefaultSubResource, entry);
682 }
684 {
686  return insertEntries(pDefaultSubResource, entrylist);
687 }
688 
689 bool KLFLibResourceEngine::changeEntries(const QList<entryId>& idlist, const QList<int>& properties,
690  const QList<QVariant>& values)
691 {
693  return changeEntries(pDefaultSubResource, idlist, properties, values);
694 }
695 
697 {
699  return deleteEntries(pDefaultSubResource, idList);
700 }
701 
702 
703 
705 {
706  // not implemented by default. Subclasses must reimplement
707  // to support this feature.
708  return false;
709 }
710 
712 {
713  return KLFPropertizedObject::property(name);
714 }
715 
717 {
718  int propId = propertyIdForName(propName);
719  if (propId < 0) {
720  if (!canRegisterProperty(propName))
721  return false;
722  // register the property
723  propId = registerProperty(propName);
724  if (propId < 0)
725  return false;
726  }
727  // finally set the property
728  return setResourceProperty(propId, value);
729 }
730 
732 {
734  return false;
735 
736  if ( !canModifyProp(propId) ) {
737  return false;
738  }
739 
740  bool result = saveResourceProperty(propId, value);
741  if (!result) // operation not permitted or failed
742  return false;
743 
744  // operation succeeded: set KLFPropertizedObject-based property.
745  KLFPropertizedObject::setProperty(propId, value);
746  emit resourcePropertyChanged(propId);
747  return true;
748 }
749 
750 
752 /* */ KLFLibResourceEngine::baseCanModifyStatus(bool inSubResource, const QString& subResource) const
753 {
754  if (pFeatureFlags & FeatureLocked) {
755  if (locked())
756  return MS_IsLocked;
757  if (inSubResource &&
758  (pFeatureFlags & FeatureSubResources) &&
759  (pFeatureFlags & FeatureSubResourceProps)) {
760  if (subResourceProperty(subResource, SubResPropLocked).toBool())
761  return MS_SubResLocked;
762  }
763  }
764 
765  if (pFeatureFlags & FeatureReadOnly) {
766  if (isReadOnly())
767  return MS_NotModifiable;
768  }
769 
770  return MS_CanModify;
771 }
772 
773 
774 
775 // static
777 {
779 }
780 // static
782 {
783  EntryMatchCondition c(PropertyMatchType);
784  c.mPropertyMatch = pmatch;
785  return c;
786 }
787 // static
789 {
790  EntryMatchCondition c(NegateMatchType);
791  c.mConditionList = QList<EntryMatchCondition>() << condition;
792  return c;
793 }
794 // static
796 {
797  EntryMatchCondition c(OrMatchType);
798  c.mConditionList = conditions;
799  return c;
800 }
801 // static
803 {
804  EntryMatchCondition c(AndMatchType);
805  c.mConditionList = conditions;
806  return c;
807 }
808 
809 
810 
811 
812 
813 
814 // -----
815 
816 // DATA STREAM OPERATORS
818 {
819  return stream << entrywid.id << entrywid.entry;
820 }
822 {
823  return stream >> entrywid.id >> entrywid.entry;
824 }
825 
826 // DEBUG OPERATOR<<'S
827 KLF_EXPORT QDebug& operator<<(QDebug& dbg, const KLFLib::StringMatch& smatch)
828 {
829  return dbg << "StringMatch[ref="<<smatch.matchValueString()<<";flags="<<smatch.matchFlags()<<"]";
830 }
831 KLF_EXPORT QDebug& operator<<(QDebug& dbg, const KLFLib::PropertyMatch& pmatch)
832 {
833  // KLF_DEBUG_BLOCK("operator<<(QDebug, KLFLib::PropertyMatch)") ;
834  // klfDbg("prop-id="<<pmatch.propertyId());
835  return dbg << "PropertyMatch[prop-id="<<pmatch.propertyId()<<"; ref="<<pmatch.matchValueString()
836  <<"; flags="<<pmatch.matchFlags()<<"]";
837 }
838 KLF_EXPORT QDebug& operator<<(QDebug& dbg, const KLFLib::EntryMatchCondition& c)
839 {
840  // KLF_DEBUG_BLOCK("operator<<(QDebug, KLFLib::EntryMatchCondition)") ;
841  klfDbg("type="<<c.type()) ;
842 #ifdef Q_WS_MAC
843  return dbg<<"EntryMatchCondition{...}";
844 #endif
845  dbg << "EntryMatchCondition{type=";
847  return dbg << "match-all}";
848  }
850  // KLF_DEBUG_BLOCK("if-block...") ;
851  dbg << "property-match; "<<c.propertyMatch();
852  // klfDbg("printed into dbg...") ;
853  dbg <<"}";
854  // klfDbg("printed into dbg...") ;
855  return dbg;
856  }
860  return dbg << "unknown-type}";
861  }
862  // NOT, AND or OR type:
863  static const char *w_and = " AND ";
864  static const char *w_or = " OR ";
865  static const char *w_not = " NOT ";
866  const char * word = (c.type()==KLFLib::EntryMatchCondition::NegateMatchType)? w_not :
867  ((c.type()==KLFLib::EntryMatchCondition::AndMatchType) ? w_and : w_or) ;
868  dbg << (word+1/*nospace*/) << "; list: ";
870  int k;
871  for (k = 0; k < conditions.size(); ++k) {
872  if (k > 0)
873  dbg << word;
874  dbg << conditions[k];
875  }
876  dbg << ".}";
877  return dbg;
878 }
879 KLF_EXPORT QDebug& operator<<(QDebug& dbg, const KLFLibResourceEngine::KLFLibEntryWithId& e)
880 {
881  return dbg <<"KLFLibEntryWithId(id="<<e.id<<";"<<e.entry.category()<<","<<e.entry.tags()<<","
882  <<e.entry.latex()<<")";
883 }
884 KLF_EXPORT QDebug& operator<<(QDebug& dbg, const KLFLibResourceEngine::Query& q)
885 {
886  // KLF_DEBUG_BLOCK("operator<<(QDebug, KLFLibRes.Eng.::Query)") ;
887  return dbg << "Query(cond.="<<q.matchCondition<<"; skip="<<q.skip<<",limit="<<q.limit
888  <<"; orderpropid="<<q.orderPropId<<"/"<<(q.orderDirection==Qt::AscendingOrder ? "Asc":"Desc")
889  <<"; wanted props="<<q.wantedEntryProperties<<")" ;
890 }
891 
892 
893 
894 
895 // ---------------------------------------------------
896 
898 {
899  QList<KLFLib::entryId> idList;
900  QList<KLFLibResourceEngine::KLFLibEntryWithId> elist = allEntries(subResource);
901  int k;
902  for (k = 0; k < idList.size(); ++k)
903  idList << elist[k].id;
904  return idList;
905 }
906 
908 {
910  return entry(subResource, id).latex().size();
911 }
912 
915  const QList<int>& /*wantedEntryProperties*/)
916 {
918  int k;
919  for (k = 0; k < idList.size(); ++k)
920  elist << KLFLibEntryWithId(idList[k], entry(subResource, idList[k]));
921  return elist;
922 }
923 
924 
926  const Query& query,
927  QueryResult *result)
928 {
929  return queryImpl(this, subResource, query, result);
930 }
931 
933 {
934  return queryValuesImpl(this, subResource, entryPropId);
935 }
936 
937 
938 template<class T>
939 static void qlist_skip_and_limit(QList<T> *list, int skip, int limit)
940 {
941  KLF_ASSERT_NOT_NULL( list, "list is NULL!", return; ) ;
942 
943  // skip `skip' first entries
944 
945  if (skip <= 0) {
946  // nothing to do
947  } else if (list->size() <= skip) {
948  list->clear();
949  } else {
950  *list = list->mid(skip);
951  }
952 
953  // and limit to `limit'
954  if (limit < 0)
955  return; // no limit
956 
957  if (list->size() > limit)
958  *list = list->mid(0, limit);
959 
960  return;
961 }
962 
963 // static
965  const Query& query, QueryResult *result)
966 {
968 
970  klfDbgSt("Query: "<<query);
971 
972  if (result == NULL) {
973  qWarning()<<KLF_FUNC_NAME<<": expected valid `result' pointer";
974  return -1;
975  }
976 
977  QList<KLFLibEntryWithId> allEList = resource->allEntries(subResource);
978 
979  KLFLibEntrySorter sorter(query.orderPropId, query.orderDirection);
980  QueryResultListSorter lsorter(&sorter, result);
981 
982  // we first need to order _all_ the entries (yes, since the order of allEntries()
983  // is undefined ... and limit/skip refer to _ordered_ entry list...)
984  int k;
985  for (k = 0; k < allEList.size(); ++k) {
986  // test match condition
987  const KLFLibEntryWithId& ewid = allEList[k];
988  if (testEntryMatchConditionImpl(query.matchCondition, ewid.entry)) {
989  lsorter.insertIntoOrderedResult(ewid);
990  }
991  }
992 
993  klfDbgSt("queried ordered list. result->entryWithIdList: \n"<<result->entryWithIdList) ;
994 
995  // now we need to remove the first 'query.skip' number of results.
996  // we can't do this while inserting because the order counts.
997 
998  qlist_skip_and_limit(&result->entryIdList, query.skip, query.limit);
999  qlist_skip_and_limit(&result->rawEntryList, query.skip, query.limit);
1000  qlist_skip_and_limit(&result->entryWithIdList, query.skip, query.limit);
1001 
1002  klfDbgSt("About to return. Number of entries in TEE VALUE.") ;
1003 
1004  return KLF_DEBUG_TEE( lsorter.numberOfEntries() );
1005 }
1006 
1007 // static
1009  const QString& subResource, int entryPropId)
1010 {
1011  QList<KLFLibEntryWithId> allEList = resource->allEntries(subResource);
1012  QList<QVariant> values;
1013  int k;
1014  for (k = 0; k < allEList.size(); ++k) {
1015  QVariant p = allEList[k].entry.property(entryPropId);
1016  if (!values.contains(p))
1017  values << p;
1018  }
1019  return values;
1020 }
1021 
1022 
1023 // static
1025  const KLFLibEntry& libentry)
1026 {
1027  int k;
1028  KLFLib::PropertyMatch pmatch;
1030 
1031  switch (condition.type()) {
1033  return true;
1035  pmatch = condition.propertyMatch();
1036  return klfMatch(libentry.property(pmatch.propertyId()), // test value
1037  pmatch.matchValue(), // match value
1038  pmatch.matchFlags(), // flags
1039  pmatch.matchValueString()); // variant converted to string, cached
1041  condlist = condition.conditionList(); // only first item is used
1042  if (condlist.isEmpty()) {
1043  qWarning()<<KLF_FUNC_NAME<<": NOT condition with no arguments!";
1044  return false;
1045  }
1046  return ! testEntryMatchConditionImpl(condlist[0], libentry); // negate test
1048  condlist = condition.conditionList();
1049  if (condlist.isEmpty())
1050  return true;
1051  for (k = 0; k < condlist.size(); ++k) {
1052  if (testEntryMatchConditionImpl(condlist[k], libentry)) // recurse
1053  return true; // 'OR' -> find one that's OK and the condition is OK
1054  }
1055  return false; // but if none is OK then we're not OK
1057  condlist = condition.conditionList();
1058  if (condlist.isEmpty())
1059  return true;
1060  for (k = 0; k < condlist.size(); ++k) {
1061  if ( ! testEntryMatchConditionImpl(condlist[k], libentry) ) // recurse
1062  return false; // 'AND' -> find one that's not OK and the condition is globally false
1063  }
1064  return true; // but if all are OK then we're OK
1065  default:
1066  qWarning()<<KLF_FUNC_NAME<<": KLFLib::EntryMatchCondition type "<<condition.type()<<" not known!";
1067  }
1068  return false;
1069 }
1070 
1071 
1073  QueryResult *result)
1074  : mSorter(sorter), mResult(result)
1075 {
1076  KLF_ASSERT_NOT_NULL( result, "result ptr is NULL!", return ) ;
1077 
1078  fillflags = result->fillFlags;
1079 
1080  if (fillflags & QueryResult::FillRawEntryList) {
1081  reference_is_rawentrylist = true;
1082  } else if (fillflags & QueryResult::FillEntryWithIdList) {
1083  reference_is_rawentrylist = false;
1084  } else {
1085  // fill also the raw entry list to have a reference (!)
1086  fillflags |= QueryResult::FillRawEntryList;
1087  reference_is_rawentrylist = true;
1088  }
1089 }
1091 {
1092  if (reference_is_rawentrylist)
1093  return mResult->rawEntryList.size();
1094  else
1095  return mResult->entryWithIdList.size();
1096 }
1097 
1098 
1099 /*
1100 KLFLibResourceSimpleEngine::QueryResultListSorter::QueryResultListSorter(const QueryResultListSorter& other)
1101  : mSorter(other.mSorter), mResult(other.mResult), fillflags(other.fillflags),
1102  reference_is_rawentrylist(other.reference_is_rawentrylist)
1103 {
1104 }
1105 */
1106 
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&>
1111 
1113 {
1114  int pos;
1115 
1116  if (mSorter->propId() == -1) {
1117  // just append
1118  if (reference_is_rawentrylist)
1119  pos = mResult->rawEntryList.size();
1120  else
1121  pos = mResult->entryWithIdList.size();
1122  } else {
1123  // insert at right place
1124  if (reference_is_rawentrylist) {
1125  KLFLibEntryList::iterator it =
1126  klf_lower_bound_entry(mResult->rawEntryList.begin(), mResult->rawEntryList.end(), ewid.entry, *mSorter);
1127  pos = it - mResult->rawEntryList.begin();
1128  } else {
1130  klf_lower_bound_ewid(mResult->entryWithIdList.begin(), mResult->entryWithIdList.end(), ewid, *this);
1131  pos = it - mResult->entryWithIdList.begin();
1132  }
1133  }
1134  // actually insert the items into appropriate lists
1135  if (fillflags & QueryResult::FillEntryIdList)
1136  mResult->entryIdList.insert(pos, ewid.id);
1137  if (fillflags & QueryResult::FillRawEntryList)
1138  mResult->rawEntryList.insert(pos, ewid.entry);
1139  if (fillflags & QueryResult::FillEntryWithIdList)
1140  mResult->entryWithIdList.insert(pos, ewid);
1141 }
1142 
1143 
1144 // ---------------------------------------------------
1145 
1146 // static
1147 KLFFactoryManager KLFLibEngineFactory::pFactoryManager;
1148 
1149 
1151  : QObject(parent), KLFFactoryBase(&pFactoryManager)
1152 {
1153 }
1155 {
1156 }
1157 
1158 uint KLFLibEngineFactory::schemeFunctions(const QString& /*scheme*/) const
1159 {
1160  return FuncOpen;
1161 }
1162 
1164 {
1165  return findFactoryFor(url.scheme());
1166 }
1167 
1169 {
1170  return dynamic_cast<KLFLibEngineFactory*>(pFactoryManager.findFactoryFor(urlscheme));
1171 }
1172 
1174 {
1175  return pFactoryManager.allSupportedTypes();
1176 }
1177 
1179  const Parameters& /*param*/,
1180  QObject */*parent*/)
1181 {
1182  return NULL;
1183 }
1184 
1185 bool KLFLibEngineFactory::saveResourceTo(KLFLibResourceEngine */*resource*/, const QUrl& /*newLocation*/)
1186 {
1187  return false;
1188 }
1189 
1190 
1192 {
1193  KLFLibEngineFactory *factory = findFactoryFor(url.scheme());
1194  if ( factory == NULL ) {
1195  qWarning()<<"KLFLibEngineFactory::openURL("<<url<<"): No suitable factory found!";
1196  return NULL;
1197  }
1198  return factory->openResource(url, parent);
1199 }
1200 
1201 // static
1203 {
1204  QUrl url = urlbase;
1205  url.addQueryItem("klfReadOnly", "true");
1206  KLFLibResourceEngine *resource = openURL(url, NULL); // NULL parent
1207  if ( resource == NULL ) {
1208  qWarning()<<"KLFLibEngineFactory::listSubResources("<<url<<"): Unable to open resource!";
1209  return QMap<QString,QString>();
1210  }
1212  qWarning()<<"KLFLibEngineFactory::listSubResources("<<url<<"): Resource does not support sub-resources!";
1213  return QMap<QString,QString>();
1214  }
1215  QStringList subreslist = resource->subResourceList();
1216  int k;
1217  QMap<QString,QString> subresmap;
1218  for (k = 0; k < subreslist.size(); ++k) {
1220  subresmap[subreslist[k]]
1221  = resource->subResourceProperty(subreslist[k],
1223  else
1224  subresmap[subreslist[k]] = QString();
1225  }
1226  delete resource;
1227  return subresmap;
1228 }
1229 
1230 // static
1232 {
1233  return listSubResourcesWithTitles(urlbase).keys();
1234 }
1235 
QDataStream & operator<<(QDataStream &stream, const KLFLatexSymbol &s)
virtual bool saveTo(const QUrl &newPath)
Definition: klflib.cpp:704
virtual void setDefaultSubResource(const QString &subResource)
Set the default sub-resource.
Definition: klflib.cpp:584
virtual uint schemeFunctions(const QString &scheme) const
What this factory is capable of doing.
Definition: klflib.cpp:1158
const QVariant matchValue() const
Definition: klflib.h:175
virtual bool canModifySubResourceProperty(const QString &subResource, int propId) const
Definition: klflib.cpp:548
static QString categoryFromLatex(const QString &latex)
Definition: klflib.cpp:122
static QStringList allDecodingMimeTypes()
Definition: klflib.cpp:315
data(const QString &mimeType)
virtual bool canRenameSubResource(const QString &subResource) const
Definition: klflib.cpp:519
QDataStream & operator>>(QDataStream &stream, KLFLatexSymbol &s)
static QList< QVariant > queryValuesImpl(KLFLibResourceEngine *resource, const QString &subResource, int entryPropId)
Definition: klflib.cpp:1008
virtual bool hasEntry(const QString &, entryId id)
Definition: klflib.cpp:907
EntryMatchCondition(Type type)
Definition: klflib.h:239
KLFLibEntryMimeEncoder __klf_lib_mime_encoder
Definition: klflib.cpp:411
virtual bool createSubResource(const QString &subResource, const QString &subResourceTitle)
Create a new sub-resource.
Definition: klflib.cpp:599
virtual QVariant subResourceProperty(const QString &subResource, int propId) const
Definition: klflib.cpp:528
A structure that describes a query for query()
Definition: klflib.h:933
A cached value of the size of value in Preview.
Definition: klflib.h:65
virtual void setOrder(Qt::SortOrder order)
Set the sort order.
Definition: klflib.cpp:230
const Qt::MatchFlags matchFlags() const
Definition: klflib.h:173
int setEntryProperty(const QString &propName, const QVariant &value)
Definition: klflib.cpp:92
entries have to match with one of a list of conditions
Definition: klflib.h:220
Sub-Resources may be assigned properties and values.
Definition: klflib.h:515
QList< KLFLibEntry > KLFLibEntryList
Definition: klflib.h:140
#define KLF_DEBUG_TEE(expr)
virtual bool locked() const
Is this resource is locked?
Definition: klflib.h:610
arg(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char( ' ')
KLFLib::entryId entryId
Definition: klflib.h:444
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
Definition: klflib.cpp:491
virtual bool hasEntry(const QString &subResource, entryId id)=0
query the existence of an entry in this resource
virtual ~KLFLibEntrySorter()
Definition: klflib.cpp:218
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
virtual void setProperty(const QString &propname, const QVariant &value)
virtual ~KLFLibEntry()
Definition: klflib.cpp:87
virtual bool setSubResourceProperty(const QString &subResource, int propId, const QVariant &value)
Definition: klflib.cpp:593
#define klfDbg(streamableItems)
static QStringList allSupportedSchemes()
Definition: klflib.cpp:1173
virtual KLFLibResourceEngine * openResource(const QUrl &location, QObject *parent=NULL)=0
Qt::SortOrder orderDirection
Definition: klflib.h:950
void setStyle(const KLFStyle &style)
Definition: klflib.h:103
static QString stripCategoryTagsFromLatex(const QString &latex)
Definition: klflib.cpp:145
virtual QVariant resourceProperty(const QString &name) const
Get the value of a resource property.
Definition: klflib.cpp:711
Matches entries that don&#39;t match a condition.
Definition: klflib.h:219
void registerBuiltInProperty(int propId, const QString &propName) const
virtual bool setViewType(const QString &viewType)
Definition: klflib.cpp:569
virtual KLFLibEntry entry(const QString &subResource, entryId id)=0
query an entry in this resource
KLFLibEntrySorter(int propId=-1, Qt::SortOrder order=Qt::AscendingOrder)
Definition: klflib.cpp:209
static bool canDecodeMimeData(const QMimeData *mimeData)
Definition: klflib.cpp:348
virtual bool setTitle(const QString &title)
set a new resource title for this library resource
Definition: klflib.cpp:555
#define KLFLIBRESOURCEENGINE_WARN_NO_DEFAULT_SUBRESOURCE(func)
Definition: klflib.cpp:40
chop(int n)
static EntryMatchCondition mkMatchAll()
Definition: klflib.cpp:776
void blockProgressReportingForNextOperation()
Specifies that the next operation (only) should not report progress.
Definition: klflib.cpp:648
static QString tagsFromLatex(const QString &latex)
Definition: klflib.cpp:131
KLFLibEngineFactory(QObject *parent=NULL)
Definition: klflib.cpp:1150
QString latex() const
Definition: klflib.h:82
virtual bool operator()(const KLFLibEntry &a, const KLFLibEntry &b) const
Definition: klflib.cpp:276
Helper class to sort entries into a KLFLibResourceEngine::QueryResult.
Definition: klflib.h:1607
void setCategory(const QString &s)
Definition: klflib.h:101
QList< KLFLibEntryWithId > entryWithIdList
Definition: klflib.h:981
static QList< KLFAbstractLibEntryMimeEncoder * > encoderList()
Definition: klflib.cpp:299
virtual QStringList supportedEncodingMimeTypes() const =0
A list of mime types this class can encode.
static QStringList allEncodingMimeTypes()
Definition: klflib.cpp:305
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
virtual bool deleteSubResource(const QString &subResource)
Definition: klflib.cpp:612
The Latex Code of the equation.
Definition: klflib.h:62
KLF_EXPORT bool klfMatch(const QVariant &testForHitCandidateValue, const QVariant &queryValue, Qt::MatchFlags flags, const QString &queryStringCache)
virtual bool isReadOnly() const
query read-only state
Definition: klflib.h:595
int registerProperty(const QString &propertyName) const
number(long n, int base=10)
Open in Read-Only mode.
Definition: klflib.h:491
virtual bool compareDefaultSubResourceEquals(const QString &subResourceName) const
Compare our sub-resource name to another.
Definition: klflib.cpp:509
bool propertyIdRegistered(int propId) const
bool thisOperationProgressBlocked() const
Definition: klflib.cpp:660
static EntryMatchCondition mkOrMatch(QList< EntryMatchCondition > conditions)
Definition: klflib.cpp:795
append(const T &value)
It&#39;s possible to modify that something.
Definition: klflib.h:1518
KLFLibResourceEngine(const QUrl &url, uint supportedfeatureflags, QObject *parent=NULL)
Definition: klflib.cpp:416
virtual QList< KLFLib::entryId > allIds()
Returns all IDs in this resource (and the default sub-resource)
Definition: klflib.cpp:642
QueryResultListSorter(KLFLibEntrySorter *sorter, QueryResult *result)
Definition: klflib.cpp:1072
QList< KLFLib::entryId > entryIdList
Definition: klflib.h:979
virtual bool setReadOnly(bool readonly)
Set the resource to be read-only or not.
Definition: klflib.cpp:574
virtual bool renameSubResource(const QString &oldSubResourceName, const QString &newSubResourceName)
Definition: klflib.cpp:608
QString category() const
Definition: klflib.h:86
int propertyId() const
Definition: klflib.h:198
const QString matchValueString() const
Definition: klflib.h:178
virtual bool setLocked(bool locked)
Set the resource to be locked.
Definition: klflib.cpp:559
void resourcePropertyChanged(int propId)
Emitted when a resource property changes.
Qt::SortOrder order() const
The currently set sorting order.
Definition: klflib.h:296
removeAllQueryItems(const QString &key)
KLFFactoryBase * findFactoryFor(const QString &objType)
virtual ~KLFLibEngineFactory()
Definition: klflib.cpp:1154
static bool testEntryMatchConditionImpl(const KLFLib::EntryMatchCondition &condition, const KLFLibEntry &libentry)
Definition: klflib.cpp:1024
Data can be stored in separate sub-resources.
Definition: klflib.h:508
void setDateTime(const QDateTime &dt)
Definition: klflib.h:94
int propId() const
The currently set property that will be queried in the items we&#39;re sorting.
Definition: klflib.h:294
void insertIntoOrderedResult(const KLFLibEntryWithId &entry)
Definition: klflib.cpp:1112
Open Resources.
Definition: klflib.h:1696
KLFLibEntryList rawEntryList
Definition: klflib.h:980
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.
Definition: klflib.cpp:731
static EntryMatchCondition mkPropertyMatch(PropertyMatch pmatch)
Definition: klflib.cpp:781
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 &parameters, QObject *parent=NULL)
Create a new resource of given type and parameters.
Definition: klflib.cpp:1178
virtual QList< KLFLibEntryWithId > entries(const QString &, const QList< KLFLib::entryId > &idList, const QList< int > &wantedEntryProperties=QList< int >())
Definition: klflib.cpp:914
The Category to which eq. belongs (path-style string)
Definition: klflib.h:66
That something is resource-locked (ie., the only possible action is to unlock it) ...
Definition: klflib.h:1519
virtual bool decodeMime(const QByteArray &data, const QString &mimeType, KLFLibEntryList *entryList, QVariantMap *metaData) const =0
static EntryMatchCondition mkAndMatch(QList< EntryMatchCondition > conditions)
Definition: klflib.cpp:802
virtual bool canCreateSubResource() const
Definition: klflib.cpp:514
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.
Definition: klflib.cpp:241
scheme()
virtual QString defaultSubResource() const
Definition: klflib.cpp:504
Add a query item for default sub-res. as &quot;klfDefaultSubResource&quot;.
Definition: klflib.h:555
KLFStyle style used.
Definition: klflib.h:68
#define KLF_DEBUG_TIME_BLOCK(msg)
void setPreviewSize(const QSize &sz)
Definition: klflib.h:96
void setTags(const QString &s)
Definition: klflib.h:102
static QString latexAddCategoryTagsComment(const QString &latex, const QString &category, const QString &tags)
Definition: klflib.cpp:179
#define KLF_FUNC_SINGLE_RUN
static KLFAbstractLibEntryMimeEncoder * findDecoderFor(const QString &mimeType, bool warnIfNotFound=true)
Definition: klflib.cpp:392
virtual uint supportedFeatureFlags() const
List of features supported by this resource engine.
Definition: klflib.h:550
virtual bool canModifyData(const QString &subResource, ModifyType modifytype) const
Definition: klflib.cpp:472
#define KLF_FUNC_NAME
virtual QList< entryId > insertEntries(const QString &subResource, const KLFLibEntryList &entrylist)=0
Insert new entries in this resource.
virtual QStringList subResourceList() const
Definition: klflib.h:722
Tags about the equation (string)
Definition: klflib.h:67
contains(const T &value)
QMap< QString, QVariant > allProperties() const
virtual int query(const QString &subResource, const Query &query, QueryResult *result)
Definition: klflib.cpp:925
static bool decodeMimeData(const QMimeData *mimeData, KLFLibEntryList *entryList, QVariantMap *metaData)
Definition: klflib.cpp:360
void blockProgressReporting(bool block)
(Un)Blocks generally progress reporting
Definition: klflib.cpp:654
QList< EntryMatchCondition > mConditionList
Definition: klflib.h:244
entries have to match with all given conditions
Definition: klflib.h:221
static QStringList listSubResources(const QUrl &url)
Definition: klflib.cpp:1231
Add a query item for read-only status, as &quot;klfReadOnly&quot;.
Definition: klflib.h:557
A structure that will hold the result of a query() query.
Definition: klflib.h:970
static EntryMatchCondition mkNegateMatch(const EntryMatchCondition &condition)
Definition: klflib.cpp:788
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)
Definition: klflib.cpp:964
An entry (single formula) in the library.
Definition: klflib.h:55
void defaultSubResourceChanged(const QString &newDefaultSubResource)
Emitted when the default sub-resource changes.
QList< int > wantedEntryProperties
Definition: klflib.h:951
virtual QList< QVariant > queryValues(const QString &subResource, int entryPropId)
Definition: klflib.cpp:932
virtual bool hasSubResource(const QString &subResource) const
Definition: klflib.cpp:496
virtual bool loadResourceProperty(const QString &propName, const QVariant &value)
Set the given property to the given value.
Definition: klflib.cpp:716
static KLFLibEngineFactory * findFactoryFor(const QUrl &url)
Definition: klflib.cpp:1163
#define klfDbgSt(streamableItems)
QStringList allSupportedTypes()
static KLFAbstractLibEntryMimeEncoder * findEncoderFor(const QString &mimeType, bool warnIfNotFound=true)
Definition: klflib.cpp:380
An Image Preview of equation (scaled down QImage)
Definition: klflib.h:64
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.
Definition: klflib.cpp:263
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)
Definition: klflib.h:218
static KLFLibResourceEngine * openURL(const QUrl &location, QObject *parent=NULL)
Definition: klflib.cpp:1191
mid(int pos, int length=-1)
static QMap< QString, QString > listSubResourcesWithTitles(const QUrl &url)
Definition: klflib.cpp:1202
virtual QList< KLFLibEntryWithId > allEntries(const QString &subResource, const QList< int > &wantedEntryProperties=QList< int >())=0
query all entries in this resource
virtual ~KLFAbstractLibEntryMimeEncoder()
Definition: klflib.cpp:291
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)
Definition: klflib.h:1841
#define klf_lower_bound_entry
Definition: klflib.cpp:1107
virtual QVariant property(const QString &propName) const
A KLFLibEntry in combination with a KLFLib::entryId.
Definition: klflib.h:447
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())
Definition: klflib.cpp:50
PropertyMatch mPropertyMatch
Definition: klflib.h:243
void setPreview(const QImage &img)
Definition: klflib.h:95
setData(const QString &mimeType, const QByteArray &data)
Utility class for sorting library entry items.
Definition: klflib.h:276
virtual ModifyStatus baseCanModifyStatus(bool inSubResource, const QString &subResource=QString()) const
can modify data in resource (base common tests only)
Definition: klflib.cpp:752
virtual QUrl url(uint flags=0x0) const
query URL
Definition: klflib.cpp:457
Type type() const
Get which type of condition this is.
Definition: klflib.h:225
An abstract resource engine.
Definition: klflib.h:440
allQueryItemValues(const QString &key)
virtual ~KLFLibResourceEngine()
Definition: klflib.cpp:443
The Date/Time at which the equation was evaluated.
Definition: klflib.h:63
static QMimeData * createMimeData(const KLFLibEntryList &entryList, const QVariantMap &metaData)
Creates a QMetaData with all known registered encoding mime types.
Definition: klflib.cpp:326
KLFLib::EntryMatchCondition matchCondition
Definition: klflib.h:946
virtual bool canDeleteSubResource(const QString &subResource) const
Definition: klflib.cpp:523
virtual bool canModifyProp(int propId) const
Definition: klflib.cpp:485
QString tags() const
Definition: klflib.h:87
virtual void setPropId(int propId)
Set the KLFLibEntry property id the sort will take into account.
Definition: klflib.cpp:222
static void qlist_skip_and_limit(QList< T > *list, int skip, int limit)
Definition: klflib.cpp:939
localeAwareCompare(const QString &s1, const QString &s2)
virtual entryId insertEntry(const QString &subResource, const KLFLibEntry &entry)
Insert an entry into this resource.
Definition: klflib.cpp:669
That something is read-only or not modifiable for another reason.
Definition: klflib.h:1521
#define klf_lower_bound_ewid
Definition: klflib.cpp:1109
virtual QString subResourcePropertyName(int propId) const
Definition: klflib.cpp:533
virtual bool saveResourceTo(KLFLibResourceEngine *resource, const QUrl &newLocation)
Save the given resource to a new location.
Definition: klflib.cpp:1185
PropertyMatch propertyMatch() const
Relevant for type PropertyMatchType.
Definition: klflib.h:227
That something is sub-resource-locked.
Definition: klflib.h:1520
QSize previewSize() const
Definition: klflib.h:85
static QString normalizeCategoryPath(const QString &categoryPath)
Definition: klflib.cpp:195
QList< EntryMatchCondition > conditionList() const
Relevant for types OrMatchType and AndMatchType.
Definition: klflib.h:229
void setLatex(const QString &latex)
Definition: klflib.h:93

Generated by doxygen 1.8.5