[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
klflibview.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klflibview.h
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: klflibview.h 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 #ifndef KLFLIBVIEW_H
25 #define KLFLIBVIEW_H
26 
27 #include <QAbstractItemModel>
28 #include <QAbstractItemDelegate>
29 #include <QMimeData>
30 #include <QEvent>
31 #include <QWidget>
32 #include <QDialog>
33 #include <QAbstractButton>
34 #include <QTreeView>
35 #include <QItemSelectionModel>
36 #include <QTextDocument>
37 #include <QTextCharFormat>
38 #include <QStandardItemModel>
39 #include <QListView>
40 
41 #include <klfdefs.h>
42 #include <klflib.h>
43 #include <klfsearchbar.h>
44 #include <klfguiutil.h>
45 
46 
47 namespace KLFLib {
48  enum RestoreMode {
49  RestoreLatex = 0x0001,
50  RestoreStyle = 0x0002,
51 
53  RestoreAll = 0xFFFF
54  };
55 };
56 
57 
59 
82 class KLF_EXPORT KLFAbstractLibView : public QWidget
83 {
84  Q_OBJECT
85 public:
86  KLFAbstractLibView(QWidget *parent);
87  virtual ~KLFAbstractLibView() { }
88 
89  virtual KLFLibResourceEngine * resourceEngine() const { return pResourceEngine; }
90 
92 
102  virtual QUrl url() const = 0;
103 
105 
130  virtual uint compareUrlTo(const QUrl& other, uint interestFlags = 0xFFFFFFFF) const = 0;
131 
132 
134  inline bool validResourceEngine() const { return pResourceEngine != NULL; }
135 
136  virtual void setResourceEngine(KLFLibResourceEngine *resource);
137 
139  virtual KLFLibEntryList selectedEntries() const = 0;
140 
143  virtual QList<KLFLib::entryId> selectedEntryIds() const = 0;
144 
153  virtual QList<QAction*> addContextMenuActions(const QPoint& pos);
154 
156  virtual QVariantMap saveGuiState() const = 0;
157 
160  virtual bool restoreGuiState(const QVariantMap& state) = 0;
161 
165  virtual QStringList getCategorySuggestions() = 0;
166 
167  virtual KLFSearchable * searchable() { return NULL; }
168 
169 signals:
177  void requestRestore(const KLFLibEntry& entry, uint restoreflags = KLFLib::RestoreLatexAndStyle);
181  void requestRestoreStyle(const KLFStyle& style);
182 
184  void resourceDataChanged(const QList<KLFLib::entryId>& entryIdList);
185 
187  void entriesSelected(const KLFLibEntryList& entries);
188 
191  void moreCategorySuggestions(const QStringList& categorylist);
192 
198  void operationStartReportingProgress(KLFProgressReporter *progressReporter, const QString& descriptiveText);
199 
200 public slots:
201  virtual void updateResourceEngine() = 0;
202  virtual void updateResourceProp(int propId) = 0;
203  virtual void updateResourceData(const QString& subres, int modifyType,
204  const QList<KLFLib::entryId>& entryIdList) = 0;
206  virtual void updateResourceDefaultSubResourceChanged(const QString& newSubResource);
207 
214  // virtual bool writeEntryProperty(int property, const QVariant& value) = 0;
215 
216  /* * Provides a reasonable default implementation that should suit for most purposes. */
217  // virtual bool writeEntryCategory(const QString& category)
218  // { return writeEntryProperty(KLFLibEntry::Category, category); }
219 
220  /* * Provides a reasonable default implementation that should suit for most purposes. */
221  // virtual bool writeEntryTags(const QString& tags)
222  // { return writeEntryProperty(KLFLibEntry::Tags, tags); }
223 
224  // virtual bool deleteSelected(bool requireConfirm = true);
225 
226  // virtual bool insertEntries(const KLFLibEntryList& entries);
227 
228  /* * Provides a reasonable default implementation that should suit for most purposes. */
229  // virtual bool insertEntry(const KLFLibEntry& entry)
230  // { return insertEntries(KLFLibEntryList() << entry); }
231 
238  virtual bool selectEntries(const QList<KLFLib::entryId>& idList) = 0;
239 
241  virtual void restore(uint restoreFlags = KLFLib::RestoreLatexAndStyle) = 0;
243  virtual void restoreWithStyle() { restore(KLFLib::RestoreLatexAndStyle); }
245  virtual void restoreLatexOnly() { restore(KLFLib::RestoreLatex); }
246 
252  virtual void wantMoreCategorySuggestions();
253 
254 private:
255  KLFLibResourceEngine *pResourceEngine;
256 };
257 
258 
259 // -----------------
260 
261 class KLF_EXPORT KLFLibViewFactory : public QObject
262 {
263  Q_OBJECT
264 public:
265  KLFLibViewFactory(const QStringList& viewTypeIdentifiers, QObject *parent = NULL);
266  virtual ~KLFLibViewFactory();
267 
272  virtual QStringList viewTypeIdentifiers() { return pViewTypeIdentifiers; }
273 
276  virtual QString viewTypeTitle(const QString& viewTypeIdent) const = 0;
277 
282  virtual bool canCreateLibView(const QString& viewTypeIdent, KLFLibResourceEngine *engine) = 0;
283 
286  virtual KLFAbstractLibView * createLibView(const QString& viewTypeIdent, QWidget *parent,
287  KLFLibResourceEngine *resourceEngine) = 0;
288 
293  static QString defaultViewTypeIdentifier();
294 
297  static KLFLibViewFactory *findFactoryFor(const QString& viewTypeIdentifier);
298 
301  static QStringList allSupportedViewTypeIdentifiers();
303  static QList<KLFLibViewFactory*> allFactories() { return pRegisteredFactories; }
304 
305 private:
306  QStringList pViewTypeIdentifiers;
307 
308  static void registerFactory(KLFLibViewFactory *factory);
309  static void unRegisterFactory(KLFLibViewFactory *factory);
310 
311  static QList<KLFLibViewFactory*> pRegisteredFactories;
312 
313 };
314 
315 
316 // --------------------
317 
318 
319 
321 
339 class KLF_EXPORT KLFLibWidgetFactory : public QObject, public KLFFactoryBase
340 {
341  Q_OBJECT
342 public:
352 
355  KLFLibWidgetFactory(QObject *parent);
356 
359  static KLFLibWidgetFactory * findFactoryFor(const QString& wtype);
360 
363  static QStringList allSupportedWTypes();
364 
365 
367 
368  virtual QStringList supportedTypes() const = 0;
369 
371 
374  virtual QString widgetTypeTitle(const QString& wtype) const = 0;
375 
389  virtual QWidget * createPromptUrlWidget(QWidget *wparent, const QString& wtype,
390  QUrl defaultlocation = QUrl()) = 0;
391 
394  virtual QUrl retrieveUrlFromWidget(const QString& wtype, QWidget *widget) = 0;
395 
398  virtual bool hasCreateWidget(const QString& wtype) const;
399 
406  virtual QWidget *createPromptCreateParametersWidget(QWidget *wparent, const QString& wtype,
407  const Parameters& defaultparameters = Parameters());
424  virtual Parameters retrieveCreateParametersFromWidget(const QString& wtype, QWidget *widget);
425 
428  virtual bool hasSaveToWidget(const QString& wtype) const;
433  virtual QWidget *createPromptSaveToWidget(QWidget *wparent, const QString& wtype,
434  KLFLibResourceEngine *resource, const QUrl& defaultUrl);
437  virtual QUrl retrieveSaveToUrlFromWidget(const QString& wtype, QWidget *widget);
438 
439 
440 private:
441  static KLFFactoryManager pFactoryManager;
442 };
443 
444 
445 
446 
447 
448 // -----------------
449 
450 class KLFLibModelCache;
451 
459 class KLF_EXPORT KLFLibModel : public QAbstractItemModel
460 {
461  Q_OBJECT
462 public:
463  enum FlavorFlag {
464  LinearList = 0x0001,
465  IconViewList = LinearList,
466  CategoryTree = 0x0002,
467  DisplayTypeMask = 0x000f,
468 
469  GroupSubCategories = 0x1000
470  };
471 
472  KLFLibModel(KLFLibResourceEngine *resource, uint flavorFlags = LinearList|GroupSubCategories,
473  QObject *parent = NULL);
474  virtual ~KLFLibModel();
475 
476  enum ItemKind { EntryKind, CategoryLabelKind };
477  enum {
478  ItemKindItemRole = Qt::UserRole+768, // = 800 in Qt 4.4, nice in debugging messages ;-)
483  FullCategoryPathItemRole
484  };
485 
492  static inline int entryItemRole(int propertyId) { return (Qt::UserRole+788) + propertyId; } // = 820+propId
494  static inline int entryPropIdForItemRole(int role) { return role - (Qt::UserRole+788); } // = role - 820
495 
496  virtual void setResource(KLFLibResourceEngine *resource);
497 
498  virtual KLFLibResourceEngine * resource() { return pResource; }
499 
500  virtual QUrl url() const;
501 
511  virtual void setFlavorFlags(uint flags, uint modify_mask = 0xffffffff);
512  virtual uint flavorFlags() const;
513  inline uint displayType() const { return flavorFlags() & DisplayTypeMask; }
514 
516  virtual void prefetch(const QModelIndexList& index) const;
517  virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
518  virtual Qt::ItemFlags flags(const QModelIndex& index) const;
519  virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
520  virtual QVariant headerData(int section, Qt::Orientation orientation,
521  int role = Qt::DisplayRole) const;
522  virtual bool hasIndex(int row, int column,
523  const QModelIndex &parent = QModelIndex()) const;
524  virtual QModelIndex index(int row, int column,
525  const QModelIndex &parent = QModelIndex()) const;
526  virtual QModelIndex parent(const QModelIndex &index) const;
527  virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
528  virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
529 
530  virtual bool canFetchMore(const QModelIndex& parent) const;
531  virtual void fetchMore(const QModelIndex& parent);
532 
533  virtual Qt::DropActions supportedDropActions() const;
534 
535  virtual QStringList mimeTypes() const;
536  virtual QMimeData *mimeData(const QModelIndexList& indexes) const;
537 
538  virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row,
539  int column, const QModelIndex& parent);
540 
541  enum { DropWillAccept = 0x0001,
542  DropWillCategorize = 0x0002,
543  DropWillMove = 0x0004 };
544  virtual uint dropFlags(QDragMoveEvent *event, QAbstractItemView *view);
545 
546  virtual QImage dragImage(const QModelIndexList& indexes);
547 
548  virtual int entryColumnContentsPropertyId(int column) const;
549  virtual int columnForEntryPropertyId(int entryPropertyId) const;
550 
551  virtual bool isDesendantOf(const QModelIndex& child, const QModelIndex& ancestor);
552 
553  virtual QStringList categoryList() const;
554 
555  virtual void updateData(const QList<KLFLib::entryId>& entryIdList, int modifyType);
556 
558  virtual QModelIndex walkNextIndex(const QModelIndex& cur);
560  virtual QModelIndex walkPrevIndex(const QModelIndex& cur);
561 
562  virtual KLFLib::entryId entryIdForIndex(const QModelIndex& index) const;
563  virtual QModelIndex findEntryId(KLFLib::entryId eid) const;
564  virtual QList<KLFLib::entryId> entryIdForIndexList(const QModelIndexList& indexlist) const;
565  virtual QModelIndexList findEntryIdList(const QList<KLFLib::entryId>& eidlist) const;
566 
567  virtual int fetchBatchCount() const { return pFetchBatchCount; }
568 
569 
571  virtual void redoSort();
572 
574  virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
575 
577  virtual KLFLibEntrySorter * entrySorter() { return pEntrySorter; }
578 
580  virtual void setEntrySorter(KLFLibEntrySorter *entrySorter);
581 
582 signals:
584  void operationStartReportingProgress(KLFProgressReporter *progressReporter, const QString& descriptiveText);
585 
586 public slots:
587 
588  virtual QModelIndex searchFind(const QString& queryString, const QModelIndex& fromIndex
589  = QModelIndex(), bool forward = true);
590  virtual QModelIndex searchFindNext(bool forward);
591  virtual void searchAbort();
592 
593  // virtual bool changeEntries(const QModelIndexList& items, int property, const QVariant& value);
594  // virtual bool insertEntries(const KLFLibEntryList& entries);
595  // virtual bool deleteEntries(const QModelIndexList& items);
596 
597  virtual void completeRefresh();
598 
600  virtual void setFetchBatchCount(int count) { pFetchBatchCount = count; }
601 
602 private:
603 
604  friend class KLFLibModelCache;
605 
606  KLFLibResourceEngine *pResource;
607 
608  unsigned int pFlavorFlags;
609 
610  int pFetchBatchCount;
611 
612  KLFLibModelCache *pCache;
613 
614  KLFLibEntrySorter *pEntrySorter;
615 
616  struct PersistentId {
617  int kind;
618  KLFLib::entryId entry_id;
619  QString categorylabel_fullpath;
620  int column;
621  };
622  friend QDebug& operator<<(QDebug&, const PersistentId&);
623 
624  QList<PersistentId> persistentIdList(const QModelIndexList& persistentindexlist);
625  QModelIndexList newPersistentIndexList(const QList<PersistentId>& persistentidlist);
626 
627  void startLayoutChange(bool withQtLayoutChangedSignal = true);
628  void endLayoutChange(bool withQtLayoutChangedSignal = true);
629 
630  QModelIndexList pLytChgIndexes;
631  QList<PersistentId> pLytChgIds;
632 
633  void updateCacheSetupModel();
634 
635  QString pSearchString;
636  QModelIndex pSearchCurNode;
637  bool pSearchAborted;
638 
639  bool dropCanInternal(const QMimeData *data);
640 
642 };
643 
644 
645 
646 // -----------------
647 
648 
649 class KLF_EXPORT KLFLibViewDelegate : public QAbstractItemDelegate
650 {
651  Q_OBJECT
652 
653  Q_PROPERTY(QSize previewSize READ previewSize WRITE setPreviewSize) ;
654 public:
658  KLFLibViewDelegate(QObject *parent);
659  virtual ~KLFLibViewDelegate();
660 
661  inline QSize previewSize() const { return pPreviewSize; }
662 
663  virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem& option,
664  const QModelIndex& index) const;
665  virtual bool editorEvent(QEvent *event,QAbstractItemModel *model, const QStyleOptionViewItem& option,
666  const QModelIndex& index);
667  virtual void paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
668  virtual void setEditorData(QWidget *editor, const QModelIndex& index) const;
669  virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex& index) const;
670  virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
671  virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem& option,
672  const QModelIndex& index) const;
673 
674  virtual void setSearchString(const QString& s) { pSearchString = s; }
675  virtual void setSearchIndex(const QModelIndex& index) { pSearchIndex = index; }
676  virtual void setSelectionModel(QItemSelectionModel *sm) { pSelModel = sm; }
682  virtual void setTheTreeView(QTreeView *theTreeView) { pTheTreeView = theTreeView; }
683  // virtual void setIndexExpanded(const QModelIndex& index, bool isexpanded) {
684  // pExpandedIndexes[QPersistentModelIndex(index)] = isexpanded;
685  // }
686 
687  virtual bool autoBackgroundItems() const { return pAutoBackgroundItems; }
688  virtual void setAutoBackgroundItems(bool autoBgItems) { pAutoBackgroundItems = autoBgItems; }
689  virtual QColor autoBackgroundColor() const { return pAutoBackgroundColor; }
690  virtual void setAutoBackgroundColor(const QColor& autoBgColor) { pAutoBackgroundColor = autoBgColor; }
691 
692 public slots:
693  void setPreviewSize(const QSize& psize) { pPreviewSize = psize; }
694 
695 protected:
696  struct PaintPrivate {
703  };
704 
705  virtual void paintEntry(PaintPrivate *p, const QModelIndex& index) const;
706  virtual void paintCategoryLabel(PaintPrivate *p, const QModelIndex& index) const;
707 
708  enum { PTF_HighlightSearch = 0x0001,
709  PTF_HighlightSearchCurrent = 0x0002,
710  PTF_SelUnderline = 0x0004,
711  PTF_ForceRichTextRender = 0x0008,
712  PTF_FontLarge = 0x0010,
713  PTF_FontTT = 0x0020
714  };
715  virtual void paintText(PaintPrivate *p, const QString& text, uint flags = PTF_HighlightSearch) const;
716 
717  virtual bool indexHasSelectedDescendant(const QModelIndex& parent) const;
718  virtual bool selectionIntersectsIndexChildren(const QItemSelection& selection,
719  const QModelIndex& parent) const;
721  virtual bool func_indexHasSelectedDescendant(const QModelIndex& parent, const QTime& timer,
722  int timeLimitMs) const;
723 
724 private:
725  QString pSearchString;
726  QModelIndex pSearchIndex;
727  QItemSelectionModel *pSelModel;
728  QTreeView *pTheTreeView;
729 
730  QSize pPreviewSize;
731 
732  bool pAutoBackgroundItems;
733  QColor pAutoBackgroundColor;
734 
735  // QMap<QPersistentModelIndex, bool> pExpandedIndexes;
736 
737  struct ColorRegion {
738  ColorRegion(QTextCharFormat f = QTextCharFormat(), int s = -1, int l = 0)
739  : fmt(f), start(s), len(l) { }
740  QTextCharFormat fmt; int start; int len;
741  bool operator<(const ColorRegion& other) const {
742  return start < other.start;
743  }
744  };
745  friend QDebug& operator<<(QDebug&, const ColorRegion&);
746 };
747 
748 // -----------------
749 
753 class KLF_EXPORT KLFLibDefaultView : public KLFAbstractLibView, public KLFSearchable
754 {
755  Q_OBJECT
756  Q_PROPERTY(bool autoBackgroundItems READ autoBackgroundItems WRITE setAutoBackgroundItems) ;
757  Q_PROPERTY(QColor autoBackgroundColor READ autoBackgroundColor WRITE setAutoBackgroundColor) ;
758 
759  Q_PROPERTY(QListView::Flow iconViewFlow READ iconViewFlow WRITE setIconViewFlow) ;
760 
761  Q_PROPERTY(QSize previewSize READ previewSize WRITE setPreviewSize) ;
762 
763 public:
764  enum ViewType { CategoryTreeView, ListTreeView, IconView };
765  KLFLibDefaultView(QWidget *parent, ViewType viewtype = CategoryTreeView);
766  virtual ~KLFLibDefaultView();
767 
768  virtual QUrl url() const;
769  virtual uint compareUrlTo(const QUrl& other, uint interestFlags = 0xFFFFFFFF) const;
770 
771  inline QSize previewSize() const { return pDelegate->previewSize(); }
772 
773  bool groupSubCategories() const { return pGroupSubCategories; }
774 
775  virtual bool event(QEvent *e);
776  virtual bool eventFilter(QObject *o, QEvent *e);
777 
778  virtual KLFLibEntryList selectedEntries() const;
780 
781  ViewType viewType() const { return pViewType; }
782 
783  virtual QList<QAction*> addContextMenuActions(const QPoint& pos);
784 
785  virtual QVariantMap saveGuiState() const;
786  virtual bool restoreGuiState(const QVariantMap& state);
787 
789  virtual QModelIndex currentVisibleIndex() const { return currentVisibleIndex(true); }
791  virtual QModelIndex currentVisibleIndex(bool forward) const;
792 
793  bool autoBackgroundItems() const { return pDelegate->autoBackgroundItems(); }
794  QColor autoBackgroundColor() const { return pDelegate->autoBackgroundColor(); }
795 
796  QListView::Flow iconViewFlow() const;
797 
799 
800  virtual KLFSearchable * searchable() { return this; }
801 
802 public slots:
803  // virtual bool writeEntryProperty(int property, const QVariant& value);
804  // virtual bool deleteSelected(bool requireConfirmation = true);
805  // virtual bool insertEntries(const KLFLibEntryList& entries);
806  virtual bool selectEntries(const QList<KLFLib::entryId>& idList);
807 
808  virtual bool searchFind(const QString& queryString, bool forward = true);
809  virtual bool searchFindNext(bool forward);
810  virtual void searchAbort();
811 
812  virtual void restore(uint restoreflags = KLFLib::RestoreLatexAndStyle);
813 
814  virtual void showColumns(int propIdColumn, bool show);
815  virtual void sortBy(int propIdColumn, Qt::SortOrder sortorder);
816 
820  virtual void slotSelectAll(bool expandItems = false);
821  virtual void slotRefresh();
822  virtual void slotRelayoutIcons();
823 
824  void setPreviewSize(const QSize& size) { pDelegate->setPreviewSize(size); }
825 
826  void setAutoBackgroundItems(bool on) { pDelegate->setAutoBackgroundItems(on); }
827  void setAutoBackgroundColor(const QColor& c) { pDelegate->setAutoBackgroundColor(c); }
828 
832  void setIconViewFlow(QListView::Flow flow);
833 
836  void setGroupSubCategories(bool yesOrNo) { pGroupSubCategories = yesOrNo; }
837 
838  void updateDisplay();
839 
840 protected:
841  virtual void updateResourceEngine();
842  virtual void updateResourceProp(int propId);
843  virtual void expandRootNice();
844  virtual void updateResourceData(const QString& subRes, int modifyType,
845  const QList<KLFLib::entryId>& entryIdList);
846  virtual void updateResourceOwnData(const QList<KLFLib::entryId>& entryIdList);
847 
848  virtual void showEvent(QShowEvent *event);
849 
850  enum SelectAllFlags { ExpandItems = 0x01, NoSignals = 0x02 } ;
851 
852 protected slots:
853  void slotViewSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
854 
862  virtual void slotSelectAll(const QModelIndex& parent, uint selectFlags);
863 
864  void slotViewItemClicked(const QModelIndex& index);
865  void slotEntryDoubleClicked(const QModelIndex& index);
866 
867  void slotShowColumnSenderAction(bool showCol);
868 
869  // called from model
870  void slotResourceModelReset();
871  void slotResourceDataChanged(const QModelIndex& topLeft, const QModelIndex& botRight);
872 
873  void slotPreviewSizeFromActionSender();
874  void slotPreviewSizeActionsRefreshChecked();
875 
876 private:
877  ViewType pViewType;
878  QAbstractItemView *pView;
879  KLFLibViewDelegate *pDelegate;
880  KLFLibModel *pModel;
881 
882  bool pGroupSubCategories;
883 
884  QList<QAction*> pCommonActions;
885  QList<QAction*> pShowColumnActions;
886  QMenu *pPreviewSizeMenu;
887  QList<QAction*> pIconViewActions;
888 
889  QList<QAction*> pViewActionsWithShortcut;
890 
891  bool pEventFilterNoRecurse;
892 
893  QModelIndexList selectedEntryIndexes() const;
894 
895  bool func_selectAll(const QModelIndex& parent, uint flags, QTime *tm, KLFDelayedPleaseWaitPopup *pleaseWait);
896 
897 private slots:
898  void searchFound(const QModelIndex& i);
899 
900 protected:
901  KLF_DEBUG_DECLARE_REF_INSTANCE( QFileInfo(url().path()).fileName()+":"
902  +(resourceEngine()?resourceEngine()->defaultSubResource():"[NULL]")
903  +"|viewtype="+QString::number(pViewType) ) ;
904 };
905 
906 // -----------------
907 
909 {
910  Q_OBJECT
911 public:
912  KLFLibDefaultViewFactory(QObject *parent = NULL);
914 
915  virtual QString viewTypeTitle(const QString& viewTypeIdent) const;
916 
917  virtual bool canCreateLibView(const QString& /*viewTypeIdent*/,
918  KLFLibResourceEngine */*engine*/) { return true; }
919 
920  virtual KLFAbstractLibView * createLibView(const QString& viewTypeIdent, QWidget *parent,
921  KLFLibResourceEngine *resourceEngine);
922 };
923 
924 
925 
926 // -----------------
927 
928 namespace Ui {
929  class KLFLibOpenResourceDlg;
931  class KLFLibResPropEditor;
932  class KLFLibNewSubResDlg;
933 };
934 
936 class KLF_EXPORT KLFLibOpenResourceDlg : public QDialog
937 {
938  Q_OBJECT
939 public:
940  KLFLibOpenResourceDlg(const QUrl& defaultlocation = QUrl(), QWidget *parent = 0);
941  virtual ~KLFLibOpenResourceDlg();
942 
943  virtual QUrl url() const;
944 
945  static QUrl queryOpenResource(const QUrl& defaultlocation = QUrl(), QWidget *parent = 0);
946 
947 protected slots:
948 
949  virtual void updateReadyToOpenFromSender(bool isready);
950  virtual void updateReadyToOpen();
951 
952 protected:
953  virtual QUrl retrieveRawUrl() const;
954 
955 private:
956  Ui::KLFLibOpenResourceDlg *pUi;
957  QAbstractButton *btnGo;
958 };
959 
960 // --
961 
962 
963 class KLF_EXPORT KLFLibCreateResourceDlg : public QDialog
964 {
965  Q_OBJECT
966 public:
968 
969  KLFLibCreateResourceDlg(const QString& defaultWtype, QWidget *parent = 0);
970  virtual ~KLFLibCreateResourceDlg();
971 
972  virtual Parameters getCreateParameters() const;
973 
974  static KLFLibResourceEngine *createResource(const QString& defaultWtype, QObject *resourceParent,
975  QWidget *parent = 0);
976 
977 public slots:
978 
979  virtual void accept();
980  virtual void reject();
981 
982 protected slots:
983 
984  virtual void updateReadyToCreateFromSender(bool isready);
985  virtual void updateReadyToCreate();
986 
987 private:
988  Ui::KLFLibOpenResourceDlg *pUi;
989  QAbstractButton *btnGo;
990 
991  Parameters pParam;
992 };
993 
994 
995 // --
996 
997 class KLF_EXPORT KLFLibResPropEditor : public QWidget
998 {
999  Q_OBJECT
1000 public:
1001  KLFLibResPropEditor(KLFLibResourceEngine *resource, QWidget *parent = 0);
1002  virtual ~KLFLibResPropEditor();
1003 
1004 public slots:
1005  bool apply();
1006 
1007 protected slots:
1008  void slotResourcePropertyChanged(int propId);
1009  void slotSubResourcePropertyChanged(const QString& subResource, int propId);
1010  void on_btnAdvanced_toggled(bool on);
1011  void advPropEdited(QStandardItem *item);
1012  void advSubResPropEdited(QStandardItem *item);
1013  void on_cbxSubResource_currentIndexChanged(int newSubResItemIndex);
1014 
1015  void updateResourceProperties();
1016  void updateSubResourceProperties();
1017  void updateSubResources(const QString& curSubResource = QString());
1018 
1019 private:
1020  KLFLibResourceEngine *pResource;
1021  bool pSuppSubRes;
1022  bool pSuppSubResProps;
1023  Ui::KLFLibResPropEditor *U;
1024  QStandardItemModel *pPropModel;
1025  QStandardItemModel *pSubResPropModel;
1026 
1027  QString curSubResource() const;
1028 };
1029 
1030 class KLF_EXPORT KLFLibResPropEditorDlg : public QDialog
1031 {
1032  Q_OBJECT
1033 public:
1034  KLFLibResPropEditorDlg(KLFLibResourceEngine *resource, QWidget *parent = 0);
1035  virtual ~KLFLibResPropEditorDlg();
1036 
1037 public slots:
1038  void applyAndClose();
1039  void cancelAndClose();
1040 
1041 private:
1042  KLFLibResPropEditor *pEditor;
1043 };
1044 
1045 
1046 
1047 
1048 class KLF_EXPORT KLFLibNewSubResDlg : public QDialog
1049 {
1050  Q_OBJECT
1051 public:
1052  KLFLibNewSubResDlg(KLFLibResourceEngine *resource, QWidget *parent = 0);
1053  virtual ~KLFLibNewSubResDlg();
1054 
1055  QString newSubResourceName() const;
1056  QString newSubResourceTitle() const;
1057 
1063  static QString createSubResourceIn(KLFLibResourceEngine *resource, QWidget *parent = 0);
1064 
1069  static QString makeSubResInternalName(const QString& title);
1070 
1071 private slots:
1072  void on_txtTitle_textChanged(const QString& text);
1073  void on_txtName_textChanged(const QString& text);
1074 
1075 private:
1076  Ui::KLFLibNewSubResDlg *u;
1077 
1078  bool isAutoName;
1079 };
1080 
1081 
1082 
1083 
1084 
1097 {
1098 public:
1100  virtual ~KLFLibLocalFileSchemeGuesser();
1101 
1103 
1118  virtual QString guessScheme(const QString& fileName) const = 0;
1119 };
1120 
1121 
1122 
1124 
1137 {
1138  Q_OBJECT
1139 public:
1141  struct LocalFileType {
1145  };
1146 
1147  KLFLibBasicWidgetFactory(QObject *parent = NULL);
1148  virtual ~KLFLibBasicWidgetFactory();
1149 
1150  virtual QStringList supportedTypes() const;
1151 
1152  virtual QString widgetTypeTitle(const QString& wtype) const;
1153 
1154  virtual QWidget * createPromptUrlWidget(QWidget *parent, const QString& scheme,
1155  QUrl defaultlocation = QUrl());
1156  virtual QUrl retrieveUrlFromWidget(const QString& scheme, QWidget *widget);
1157 
1158  virtual bool hasCreateWidget(const QString& /*wtype*/) const { return true; }
1159 
1165  virtual QWidget * createPromptCreateParametersWidget(QWidget *parent, const QString& scheme,
1166  const Parameters& defaultparameters = Parameters());
1167 
1175  virtual Parameters retrieveCreateParametersFromWidget(const QString& wtype, QWidget *widget);
1176 
1177 
1182  static void addLocalFileType(const LocalFileType& fileType);
1183  static QList<LocalFileType> localFileTypes();
1184 
1189  static QString guessLocalFileScheme(const QString& fileName);
1190 
1191 protected:
1194 
1196 
1201  static void addLocalFileSchemeGuesser(KLFLibLocalFileSchemeGuesser *schemeguesser);
1202 
1203  static void removeLocalFileSchemeGuesser(KLFLibLocalFileSchemeGuesser *schemeguesser);
1204 
1205 };
1206 
1207 
1208 
1209 
1210 
1211 #endif
hasIndex(int row, int column, const QModelIndex &parent=QModelIndex()
QDataStream & operator<<(QDataStream &stream, const KLFLatexSymbol &s)
#define KLF_DEBUG_DECLARE_REF_INSTANCE(expr)
virtual QWidget * createPromptUrlWidget(QWidget *wparent, const QString &wtype, QUrl defaultlocation=QUrl())=0
virtual KLFLibResourceEngine * resource()
Definition: klflibview.h:498
void setGroupSubCategories(bool yesOrNo)
Definition: klflibview.h:836
virtual void setTheTreeView(QTreeView *theTreeView)
Definition: klflibview.h:682
QColor autoBackgroundColor() const
Definition: klflibview.h:794
const QStyleOptionViewItem * option
Definition: klflibview.h:699
rowCount(const QModelIndex &parent=QModelIndex()
KLFLibEngineFactory::Parameters Parameters
Definition: klflibview.h:351
void setAutoBackgroundItems(bool on)
Definition: klflibview.h:826
virtual QString viewTypeTitle(const QString &viewTypeIdent) const =0
Model for Item-Views displaying a library resource's contents.
Definition: klflibview.h:459
index(int row, int column, const QModelIndex &parent=QModelIndex()
virtual bool canCreateLibView(const QString &, KLFLibResourceEngine *)
Definition: klflibview.h:917
virtual void updateResourceEngine()=0
static int entryItemRole(int propertyId)
Definition: klflibview.h:492
virtual KLFAbstractLibView * createLibView(const QString &viewTypeIdent, QWidget *parent, KLFLibResourceEngine *resourceEngine)=0
RestoreMode
Definition: klflibview.h:48
virtual QWidget * createPromptCreateParametersWidget(QWidget *wparent, const QString &wtype, const Parameters &defaultparameters=Parameters())
Definition: klflibview.cpp:311
virtual bool searchFindNext(bool forward)=0
canFetchMore(const QModelIndex &parent)
qint32 entryId
An entry ID.
Definition: klflib.h:156
virtual QVariantMap saveGuiState() const =0
virtual void searchAbort()=0
static int entryPropIdForItemRole(int role)
Definition: klflibview.h:494
createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index)
void setAutoBackgroundColor(const QColor &c)
Definition: klflibview.h:827
virtual void setSelectionModel(QItemSelectionModel *sm)
Definition: klflibview.h:676
virtual uint compareUrlTo(const QUrl &other, uint interestFlags=0xFFFFFFFF) const =0
Compare this resource view's URL to another URL.
dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
virtual void setAutoBackgroundItems(bool autoBgItems)
Definition: klflibview.h:688
sort(int column, Qt::SortOrder order=Qt::AscendingOrder)
#define KLF_DEBUG_DECLARE_ASSIGNABLE_REF_INSTANCE()
virtual bool hasCreateWidget(const QString &) const
Definition: klflibview.h:1158
virtual bool searchFind(const QString &queryString, bool forward)=0
number(long n, int base=10)
uint displayType() const
Definition: klflibview.h:513
bool validResourceEngine() const
Returns TRUE if a non-NULL resource engine has been set.
Definition: klflibview.h:134
virtual bool restoreGuiState(const QVariantMap &state)=0
KLFLibEngineFactory::Parameters Parameters
Definition: klflibview.h:967
virtual QStringList viewTypeIdentifiers()
Definition: klflibview.h:272
showEvent(QShowEvent *event)
virtual void restoreWithStyle()
Definition: klflibview.h:243
virtual ~KLFLibDefaultViewFactory()
Definition: klflibview.h:913
virtual void setFetchBatchCount(int count)
Definition: klflibview.h:600
updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index)
QSize previewSize() const
Definition: klflibview.h:661
A known local file type for KLFLibBasicWidgetFactory-created widgets.
Definition: klflibview.h:1141
ViewType viewType() const
Definition: klflibview.h:781
virtual void setAutoBackgroundColor(const QColor &autoBgColor)
Definition: klflibview.h:690
virtual QUrl retrieveUrlFromWidget(const QString &wtype, QWidget *widget)=0
virtual void updateResourceProp(int propId)=0
data(const QModelIndex &index, int role=Qt::DisplayRole)
A view widget to display a library resource's contents.
Definition: klflibview.h:82
editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
mimeData(const QModelIndexList &indexes)
virtual void updateResourceData(const QString &subres, int modifyType, const QList< KLFLib::entryId > &entryIdList)=0
QSize previewSize() const
Definition: klflibview.h:771
headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole)
setEditorData(QWidget *editor, const QModelIndex &index)
parent(const QModelIndex &index)
paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index)
Dialog prompting user to choose a resource and a sub-resource to open.
Definition: klflibview.h:936
void setPreviewSize(const QSize &size)
Definition: klflibview.h:824
virtual QUrl url() const =0
Display Resource URL. NOT exactly like KLFLibResourceEngine::url() !
virtual KLFLibEntryList selectedEntries() const =0
void setPreviewSize(const QSize &psize)
Definition: klflibview.h:693
virtual QModelIndex currentVisibleIndex() const
The first index that is currently visible in the current scrolling position.
Definition: klflibview.h:789
virtual void setSearchString(const QString &s)
Definition: klflibview.h:674
virtual KLFSearchable * searchable()
Definition: klflibview.h:167
virtual void restoreLatexOnly()
Definition: klflibview.h:245
bool autoBackgroundItems() const
Definition: klflibview.h:793
Interface for guessing file schemes.
Definition: klflibview.h:1096
virtual void restore(uint restoreFlags=KLFLib::RestoreLatexAndStyle)=0
virtual bool autoBackgroundItems() const
Definition: klflibview.h:687
KLF_EXPORT bool operator<(const KLFLatexSymbol &a, const KLFLatexSymbol &b)
QString filter
eg. "Local Library Database File (*.klf.db)"
Definition: klflibview.h:1144
Create Associated Widgets to resources for Open/Create/Save actions.
Definition: klflibview.h:339
static QList< KLFLibViewFactory * > allFactories()
Definition: klflibview.h:303
virtual QStringList getCategorySuggestions()=0
virtual KLFLibEntrySorter * entrySorter()
The current KLFLibEntrySorter that sorts our items.
Definition: klflibview.h:577
An entry (single formula) in the library.
Definition: klflib.h:55
bool groupSubCategories() const
Definition: klflibview.h:773
virtual void setSearchIndex(const QModelIndex &index)
Definition: klflibview.h:675
hasChildren(const QModelIndex &parent=QModelIndex()
virtual KLFSearchable * searchable()
Definition: klflibview.h:800
static QList< KLFLibLocalFileSchemeGuesser * > pSchemeGuessers
Definition: klflibview.h:1193
virtual Parameters retrieveCreateParametersFromWidget(const QString &wtype, QWidget *widget)
Definition: klflibview.cpp:318
virtual KLFLibResourceEngine * resourceEngine() const
Definition: klflibview.h:89
columnCount(const QModelIndex &parent=QModelIndex()
fetchMore(const QModelIndex &parent)
sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index)
virtual ~KLFAbstractLibView()
Definition: klflibview.h:87
virtual QStringList supportedTypes() const =0
List the supported widget types that this factory can create.
QString scheme
eg. "klf+sqlite"
Definition: klflibview.h:1142
virtual QList< KLFLib::entryId > selectedEntryIds() const =0
Utility class for sorting library entry items.
Definition: klflib.h:276
virtual QColor autoBackgroundColor() const
Definition: klflibview.h:689
setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)
virtual QString widgetTypeTitle(const QString &wtype) const =0
The human-readable label for this type of input.
An abstract resource engine.
Definition: klflib.h:440
virtual QList< QAction * > addContextMenuActions(const QPoint &pos)
Definition: klflibview.cpp:200
static QList< LocalFileType > pLocalFileTypes
Definition: klflibview.h:1192
event(QEvent *event)
virtual QStringList supportedTypes() const =0
QString filepattern
eg. "*.klf.db"
Definition: klflibview.h:1143
virtual int fetchBatchCount() const
Definition: klflibview.h:567
Provides some basic UIs to access resources.
Definition: klflibview.h:1136
virtual bool selectEntries(const QList< KLFLib::entryId > &idList)=0

Generated by doxygen 1.8.6