Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,7 @@ void MainWindow::dbState(bool dirty)
{
ui->fileSaveAction->setEnabled(dirty);
ui->fileRevertAction->setEnabled(dirty);
ui->undoAction->setEnabled(dirty);
// Unfortunately, sqlite does not allow to backup the DB while there are pending savepoints,
// so we cannot "Save As" when the DB is dirty.
ui->fileSaveAsAction->setEnabled(!dirty);
Expand Down Expand Up @@ -1498,6 +1499,14 @@ void MainWindow::fileRevert()
}
}

void MainWindow::undo()
{
if (db.isOpen()) {
db.revertToSavepoint("DB4S_UNDO");
refreshTableBrowsers();
}
}

void MainWindow::exportDatabaseToSQL()
{
QString current_table;
Expand Down
1 change: 1 addition & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ private slots:
void exportTableToJson();
void fileSave();
void fileRevert();
void undo();
void exportDatabaseToSQL();
void importDatabaseFromSQL();
void openRecentFile();
Expand Down
49 changes: 46 additions & 3 deletions src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ You can drag SQL statements from an object row and drop them into other applicat
<rect>
<x>0</x>
<y>0</y>
<width>673</width>
<height>544</height>
<width>640</width>
<height>526</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
Expand Down Expand Up @@ -753,7 +753,7 @@ You can drag SQL statements from an object row and drop them into other applicat
<x>0</x>
<y>0</y>
<width>1037</width>
<height>23</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="fileMenu">
Expand Down Expand Up @@ -792,6 +792,7 @@ You can drag SQL statements from an object row and drop them into other applicat
<addaction name="separator"/>
<addaction name="fileSaveAction"/>
<addaction name="fileRevertAction"/>
<addaction name="undoAction"/>
<addaction name="separator"/>
<addaction name="menuImport"/>
<addaction name="menuExport"/>
Expand Down Expand Up @@ -882,6 +883,7 @@ You can drag SQL statements from an object row and drop them into other applicat
<addaction name="separator"/>
<addaction name="fileSaveAction"/>
<addaction name="fileRevertAction"/>
<addaction name="undoAction"/>
</widget>
<widget class="QDockWidget" name="dockEdit">
<property name="windowTitle">
Expand Down Expand Up @@ -1254,6 +1256,30 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="undoAction">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="icons/icons.qrc">
<normaloff>:/icons/undo.svg</normaloff>:/icons/undo.svg</iconset>
</property>
<property name="text">
<string>&amp;Undo</string>
</property>
<property name="toolTip">
<string>Undo last change to a cell in the browser</string>
</property>
<property name="statusTip">
<string>Undo last change to a cell in the browser</string>
</property>
<property name="whatsThis">
<string>This action is used to undo the last change performed to a cell in the database browser. Redoing is not possible.</string>
</property>
<property name="menuRole">
<enum>QAction::NoRole</enum>
</property>
</action>
<action name="fileSaveAction">
<property name="enabled">
<bool>false</bool>
Expand Down Expand Up @@ -2530,6 +2556,22 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
</hint>
</hints>
</connection>
<connection>
<sender>undoAction</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>undo()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>299</y>
</hint>
</hints>
</connection>
<connection>
<sender>fileSaveAction</sender>
<signal>triggered()</signal>
Expand Down Expand Up @@ -3903,6 +3945,7 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
<slot>importTableFromCSV()</slot>
<slot>exportTableToCSV()</slot>
<slot>fileRevert()</slot>
<slot>undo()</slot>
<slot>fileSave()</slot>
<slot>deleteIndex()</slot>
<slot>createIndex()</slot>
Expand Down
1 change: 1 addition & 0 deletions src/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@
<file alias="text_underline">text_underlined.svg</file>
<file alias="set_to_null">textfield_delete.svg</file>
<file alias="settings">wrench.svg</file>
<file>undo.svg</file>
</qresource>
</RCC>
29 changes: 29 additions & 0 deletions src/icons/undo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,15 @@ void DBBrowserDB::getSqliteVersion(QString& sqlite, QString& sqlcipher)
#endif
}

bool DBBrowserDB::setSavepoint(const std::string& pointname)
bool DBBrowserDB::setSavepoint(const std::string& pointname, bool unique)
{
if(!isOpen())
return false;
if(isReadOnly) {
qWarning() << "setSavepoint: not done. DB is read-only";
return false;
}
if(contains(savepointList, pointname))
if(unique && contains(savepointList, pointname))
return true;

executeSQL("SAVEPOINT " + sqlb::escapeIdentifier(pointname) + ";", false, true);
Expand Down
2 changes: 1 addition & 1 deletion src/sqlitedb.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class DBBrowserDB : public QObject
**/
db_pointer_type get (const QString& user, bool force_wait = false);

bool setSavepoint(const std::string& pointname = "RESTOREPOINT");
bool setSavepoint(const std::string& pointname = "RESTOREPOINT", bool unique = true);
bool releaseSavepoint(const std::string& pointname = "RESTOREPOINT");
bool revertToSavepoint(const std::string& pointname = "RESTOREPOINT");
bool releaseAllSavepoints();
Expand Down
2 changes: 2 additions & 0 deletions src/sqlitetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ bool SqliteTableModel::setTypedData(const QModelIndex& index, bool isBlob, const
return false;
}

m_db.setSavepoint("DB4S_UNDO", false);

if(index.isValid() && role == Qt::EditRole)
{
std::unique_lock<std::mutex> lock(m_mutexDataCache);
Expand Down