1 #ifndef MAINWINDOW_H 2 #define MAINWINDOW_H 3 4 #include "sqlitedb.h" 5 6 #include <memory> 7 #include <QMainWindow> 8 9 struct BrowseDataTableSettings; 10 class DbStructureModel; 11 class EditDialog; 12 class ExtendedTableWidget; 13 class FindReplaceDialog; 14 class PlotDock; 15 class RemoteDock; 16 class RunSql; 17 class SqliteTableModel; 18 19 class QDragEnterEvent; 20 class QModelIndex; 21 class QLabel; 22 class QPersistentModelIndex; 23 class QToolButton; 24 25 namespace Ui { 26 class MainWindow; 27 } 28 29 class MainWindow : public QMainWindow 30 { 31 Q_OBJECT 32 33 public: 34 explicit MainWindow(QWidget* parent = nullptr); 35 ~MainWindow() override; 36 getDb()37 DBBrowserDB& getDb() { return db; } 38 39 private: 40 struct PragmaValues 41 { 42 int autovacuum; 43 int automatic_index; 44 int checkpoint_fullsync; 45 int foreign_keys; 46 int fullfsync; 47 int ignore_check_constraints; 48 QString journal_mode; 49 int journal_size_limit; 50 QString locking_mode; 51 int max_page_count; 52 int page_size; 53 int recursive_triggers; 54 int secure_delete; 55 int synchronous; 56 int temp_store; 57 int user_version; 58 int wal_autocheckpoint; 59 int case_sensitive_like; 60 } pragmaValues; 61 62 Ui::MainWindow* ui; 63 64 DBBrowserDB db; 65 66 SqliteTableModel* m_currentTabTableModel; 67 68 QMenu* popupTableMenu; 69 QMenu* popupSchemaDockMenu; 70 QMenu* recentFilesMenu; 71 QMenu* popupOpenDbMenu; 72 QMenu* popupSaveSqlFileMenu; 73 QMenu* popupSaveSqlResultsMenu; 74 75 QLabel* statusEncodingLabel; 76 QLabel* statusEncryptionLabel; 77 QLabel* statusReadOnlyLabel; 78 QToolButton* statusStopButton; 79 QLabel* statusBusyLabel; 80 81 DbStructureModel* dbStructureModel; 82 83 static const int MaxRecentFiles = 5; 84 QAction *recentFileActs[MaxRecentFiles]; 85 QAction *recentSeparatorAct; 86 87 EditDialog* editDock; 88 PlotDock* plotDock; 89 RemoteDock* remoteDock; 90 FindReplaceDialog* findReplaceDialog; 91 92 std::unique_ptr<RunSql> execute_sql_worker; 93 94 QString defaultOpenTabs; 95 QByteArray defaultWindowState; 96 97 QString currentProjectFilename; 98 bool isProjectModified; 99 100 void init(); 101 void clearCompleterModelsFields(); 102 103 void updateRecentFileActions(); 104 void setCurrentFile(const QString& fileName); 105 void addToRecentFilesMenu(const QString& filename, bool read_only = false); 106 void activateFields(bool enable = true); 107 void saveAsView(const std::string& query); 108 void attachPlot(ExtendedTableWidget* tableWidget, SqliteTableModel* model, BrowseDataTableSettings* settings = nullptr, bool keepOrResetSelection = true); 109 110 void toggleTabVisible(QWidget* tabWidget, bool show); 111 void restoreOpenTabs(QString tabs); 112 QString saveOpenTabs(); 113 void saveProject(const QString& currentFilename); 114 bool closeFiles(); 115 bool closeProject(); 116 bool askSaveSqlTab(int index, bool& ignoreUnattachedBuffers); 117 void focusSqlEditor(); 118 void moveDocksTo(Qt::DockWidgetArea area); 119 120 protected: 121 void closeEvent(QCloseEvent *) override; 122 void dragEnterEvent(QDragEnterEvent *event) override; 123 void dropEvent(QDropEvent *event) override; 124 void resizeEvent(QResizeEvent *event) override; 125 126 public slots: 127 bool fileOpen(const QString& fileName = QString(), bool openFromProject = false, bool readOnly = false); 128 void logSql(const QString &sql, int msgtype); 129 void dbState(bool dirty); 130 void refresh(); 131 void switchToBrowseDataTab(sqlb::ObjectIdentifier tableToBrowse = sqlb::ObjectIdentifier()); 132 void populateStructure(const sqlb::ObjectIdentifier& old_table = sqlb::ObjectIdentifier{}); 133 void reloadSettings(); 134 135 private slots: 136 void createTreeContextMenu(const QPoint & qPoint); 137 void createSchemaDockContextMenu(const QPoint & qPoint); 138 void changeTreeSelection(); 139 void fileNew(); 140 void fileNewInMemoryDatabase(); 141 void populateTable(); 142 bool fileClose(); 143 void createTable(); 144 void createIndex(); 145 void compact(); 146 void deleteObject(); 147 void editObject(); 148 void helpWhatsThis(); 149 void helpAbout(); 150 void updateRecordText(const QPersistentModelIndex& idx, const QByteArray& text, bool isBlob); 151 void toggleEditDock(bool visible); 152 void dataTableSelectionChanged(const QModelIndex& index); 153 void doubleClickTable(const QModelIndex& index); 154 void executeQuery(); 155 void importTableFromCSV(); 156 void exportTableToCSV(); 157 void exportTableToJson(); 158 void fileSave(); 159 void fileRevert(); 160 void exportDatabaseToSQL(); 161 void importDatabaseFromSQL(); 162 void openRecentFile(); 163 void loadPragmas(); 164 void updatePragmaUi(); 165 void savePragmas(); 166 void mainTabSelected( int tabindex ); 167 int openSqlTab(bool resetCounter = false); 168 void closeSqlTab(int index, bool force = false); 169 void changeSqlTab(int index); 170 void openSqlFile(); 171 void saveSqlFile(); 172 void saveSqlFileAs(); 173 void saveSqlResultsAsCsv(); 174 void saveSqlResultsAsView(); 175 void loadExtension(); 176 void checkNewVersion(const QString& versionstring, const QString& url); 177 void on_actionWiki_triggered() const; 178 void on_actionBug_report_triggered() const; 179 void on_actionFeature_Request_triggered() const; 180 void on_actionSqlCipherFaq_triggered() const; 181 void on_actionWebsite_triggered() const; 182 void on_actionDonatePatreon_triggered() const; 183 bool loadProject(QString filename = QString(), bool readOnly = false); 184 void saveProject(); 185 void saveProjectAs(); 186 void fileAttach(const QString& fileName = QString()); 187 void editEncryption(); 188 void copyCurrentCreateStatement(); 189 void fileOpenReadOnly(); 190 void requestCollation(const QString& name, int eTextRep); 191 void renameSqlTab(int index); 192 void setFindFrameVisibility(bool show); 193 void openFindReplaceDialog(); 194 void toggleSqlBlockComment(); 195 void openSqlPrintDialog(); 196 void runSqlNewTab(const QString& query, const QString& title, const QString& helpUrl, const bool autoRun = true); 197 void printDbStructure(); 198 void updateDatabaseBusyStatus(bool busy, const QString& user); 199 void openPreferences(); 200 void closeTab(int index); 201 void showStatusMessage5s(QString message); 202 void saveSqlFile(int tabIndex); 203 void saveAll(); 204 void showContextMenuSqlTabBar(const QPoint& pos); 205 void openUrlOrFile(const QString& urlString); 206 }; 207 208 #endif 209