From 7167ce41b61d2ba2cdb526777a4233eb84a3b66a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 6 Dec 2014 17:33:25 -0500 Subject: Imported Upstream version 2.99.6 --- SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h | 135 +++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h (limited to 'SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h') diff --git a/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h new file mode 100644 index 0000000..c92fa2c --- /dev/null +++ b/SQLiteStudio3/guiSQLiteStudio/dbtree/dbtreemodel.h @@ -0,0 +1,135 @@ +#ifndef DBTREEMODEL_H +#define DBTREEMODEL_H + +#include "db/db.h" +#include "dbtreeitem.h" +#include "services/config.h" +#include "guiSQLiteStudio_global.h" +#include "common/strhash.h" +#include +#include + +class DbManager; +class DbTreeView; +class DbPlugin; +class DbObjectOrganizer; +class QMenu; +class QCheckBox; + +class GUI_API_EXPORT DbTreeModel : public QStandardItemModel +{ + Q_OBJECT + + public: + DbTreeModel(); + ~DbTreeModel(); + + void connectDbManagerSignals(); + DbTreeItem* findItem(DbTreeItem::Type type, const QString &name); + DbTreeItem* findItem(DbTreeItem::Type type, Db* db); + DbTreeItem* findItemBySignature(const QString& signature); + QList findItems(DbTreeItem::Type type); + void move(QStandardItem* itemToMove, QStandardItem* newParentItem, int newRow = -1); + void move(QStandardItem* itemToMove, int newRow); + DbTreeItem *createGroup(const QString& name, QStandardItem *parent = nullptr); + void deleteGroup(QStandardItem* groupItem); + QStandardItem *root() const; + QStringList getGroupFor(QStandardItem* item); + void storeGroups(); + void refreshSchema(Db* db); + QList getAllItemsAsFlatList() const; + void setTreeView(DbTreeView *value); + QVariant data(const QModelIndex &index, int role) const; + QStringList mimeTypes() const; + QMimeData* mimeData(const QModelIndexList &indexes) const; + bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent); + bool pasteData(const QMimeData* data, int row, int column, const QModelIndex& parent, Qt::DropAction defaultAction = Qt::IgnoreAction, + bool *invokeStdAction = nullptr); + void interruptableStarted(Interruptable* obj); + void interruptableFinished(Interruptable* obj); + bool getIgnoreDbLoadedSignal() const; + void setIgnoreDbLoadedSignal(bool value); + bool hasDbTreeItem(const QMimeData* data); + QList getDragItems(const QMimeData* data); + QList getItemsForIndexes(const QModelIndexList& indexes) const; + + static DbTreeItem* findItem(QStandardItem *parentItem, DbTreeItem::Type type, const QString &name); + static DbTreeItem* findItem(QStandardItem* parentItem, DbTreeItem::Type type, Db* db); + static QList findItems(QStandardItem* parentItem, DbTreeItem::Type type); + static void staticInit(); + + static const constexpr char* MIMETYPE = "application/x-sqlitestudio-dbtreeitem"; + + private: + void readGroups(QList dbList); + QList childsToConfig(QStandardItem* item); + void restoreGroup(const Config::DbGroupPtr& group, QList* dbList = nullptr, QStandardItem *parent = nullptr); + bool applyFilter(QStandardItem* parentItem, const QString& filter); + void refreshSchema(Db* db, QStandardItem* item); + void collectExpandedState(QHash& state, QStandardItem* parentItem = nullptr); + QStandardItem* refreshSchemaDb(Db* db); + QList refreshSchemaTables(const QStringList &tables, const QStringList& virtualTables, bool sort); + StrHash > refreshSchemaTableColumns(const StrHash& columns); + StrHash > refreshSchemaIndexes(const StrHash& indexes, bool sort); + StrHash > refreshSchemaTriggers(const StrHash& triggers, bool sort); + QList refreshSchemaViews(const QStringList &views, bool sort); + void populateChildItemsWithDb(QStandardItem* parentItem, Db* db); + void refreshSchemaBuild(QStandardItem* dbItem, QList tables, StrHash > indexes, + StrHash > triggers, QList views, StrHash > allTableColumns); + void restoreExpandedState(const QHash& expandedState, QStandardItem* parentItem); + QString getToolTip(DbTreeItem *item) const; + QString getDbToolTip(DbTreeItem *item) const; + QString getTableToolTip(DbTreeItem *item) const; + QList getChildsAsFlatList(QStandardItem* item) const; + bool dropDbTreeItem(const QList& srcItems, DbTreeItem* dstItem, Qt::DropAction defaultAction, bool &invokeStdDropAction); + bool dropDbObjectItem(const QList& srcItems, DbTreeItem* dstItem, Qt::DropAction defaultAction); + QCheckBox* createCopyOrMoveMenuCheckBox(QMenu* menu, const QString& label); + bool dropUrls(const QList& urls); + void moveOrCopyDbObjects(const QList& srcItems, DbTreeItem* dstItem, bool move, bool includeData, bool includeIndexes, bool includeTriggers); + + static bool confirmReferencedTables(const QStringList& tables); + static bool resolveNameConflict(QString& nameInConflict); + static bool confirmConversion(const QList>& diffs); + static bool confirmConversionErrors(const QHash >& errors); + + static const QString toolTipTableTmp; + static const QString toolTipHdrRowTmp; + static const QString toolTipRowTmp; + static const QString toolTipIconRowTmp; + + DbTreeView* treeView = nullptr; + bool requireSchemaReloading = false; + DbObjectOrganizer* dbOrganizer = nullptr; + QList interruptables; + bool ignoreDbLoadedSignal = false; + QString currentFilter; + + private slots: + void expanded(const QModelIndex &index); + void collapsed(const QModelIndex &index); + void dbAdded(Db* db); + void dbUpdated(const QString &oldName, Db* db); + void dbRemoved(Db* db); + void dbConnected(Db* db); + void dbDisconnected(Db* db); + void dbUnloaded(Db* db); + void dbLoaded(Db* db); + void massSaveBegins(); + void massSaveCommited(); + void markSchemaReloadingRequired(); + void dbObjectsMoveFinished(bool success, Db* srcDb, Db* dstDb); + void dbObjectsCopyFinished(bool success, Db* srcDb, Db* dstDb); + + public slots: + void loadDbList(); + void itemChangedVisibility(DbTreeItem* item); + void applyFilter(const QString& filter); + void dbRemoved(const QString& name); + void dbRemoved(QStandardItem* item); + void interrupt(); + + signals: + void updateItemHidden(DbTreeItem* item); +}; + +#endif // DBTREEMODEL_H -- cgit v1.2.3