Commit c609bfdc authored by Matthias Möller's avatar Matthias Möller
Browse files

add option for max backups

closes #2264

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@20242 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b9822c2c
#include "BackupData.hh"
#define MAX_BACKUPS 20
//-----------------------------------------------------------------------------
BackupData::BackupData(BaseObjectData* _object) : currentState_(0), object_(_object)
BackupData::BackupData(BaseObjectData* _object) : currentState_(0), object_(_object), maxBackups_(20)
{
}
......@@ -16,6 +14,20 @@ BackupData::~BackupData(){
//-----------------------------------------------------------------------------
size_t BackupData::maxBackups()
{
return maxBackups_;
}
//-----------------------------------------------------------------------------
void BackupData::setMaxBackups(size_t _max)
{
maxBackups_ = _max;
}
//-----------------------------------------------------------------------------
void BackupData::storeBackup(BaseBackup* _backup){
//store state
......@@ -31,7 +43,7 @@ void BackupData::storeBackup(BaseBackup* _backup){
}
//delete undo backups if there are too many
while( undoStates_.size() > MAX_BACKUPS ){
while( undoStates_.size() > maxBackups_ ){
delete undoStates_.front();
undoStates_.erase( undoStates_.begin() );
}
......
......@@ -106,12 +106,20 @@ class DLLEXPORT BackupData : public PerObjectData
/// return the current state
BaseBackup* currentState();
/// return the maximum of backups which are saved
size_t maxBackups();
/// set the maximum of saved backups
void setMaxBackups(size_t _max);
protected:
std::vector< BaseBackup* > undoStates_;
std::vector< BaseBackup* > redoStates_;
BaseBackup* currentState_;
BaseObjectData* object_;
size_t maxBackups_;
};
#endif //BACKUPDATA_HH
......@@ -69,6 +69,14 @@ redoContextAction_(0)
//-----------------------------------------------------------------------------
void BackupPlugin::initializePlugin()
{
int maxBackups = OpenFlipperSettings().value("BackupPlugin/MaxBackups",static_cast<unsigned>(globalBackup_.maxBackups())).toInt();
globalBackup_.setMaxBackups(maxBackups);
}
//-----------------------------------------------------------------------------
void BackupPlugin::pluginsInitialized() {
// Create Backup menu
......@@ -136,6 +144,11 @@ void BackupPlugin::pluginsInitialized() {
redoContextAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-redo.png") );
connect(redoContextAction_, SIGNAL(triggered()), this, SLOT(slotObjectRedo()) );
emit addContextMenuItem(redoContextAction_, DATA_ALL, CONTEXTOBJECTMENU);
//update option widget since it is created earlier
if (maxBackupSpinBox_)
maxBackupSpinBox_->setValue(globalBackup_.maxBackups());
}
//createBackup(int _objectId, QString _name, UpdateType _type= UPDATE_ALL)
......@@ -410,6 +423,34 @@ void BackupPlugin::createBackup(int _objectId, QString _name, UpdateType _type)
//-----------------------------------------------------------------------------
bool BackupPlugin::initializeOptionsWidget(QWidget*& _widget)
{
QLabel* maxBackupLabel = new QLabel();
maxBackupLabel->setText(tr("Max. saved backups: "));
maxBackupSpinBox_ = new QSpinBox();
maxBackupSpinBox_->setValue(globalBackup_.maxBackups());
maxBackupSpinBox_->setRange(0,100);
QHBoxLayout* layout = new QHBoxLayout();
layout->addWidget(maxBackupLabel);
layout->addWidget(maxBackupSpinBox_);
QWidget* baseWidget = new QWidget();
baseWidget->setLayout(layout);
_widget = baseWidget;
return true;
}
//-----------------------------------------------------------------------------
void BackupPlugin::applyOptions()
{
int maxBackups = maxBackupSpinBox_->value();
globalBackup_.setMaxBackups(maxBackups);
OpenFlipperSettings().setValue("BackupPlugin/MaxBackups", maxBackups);
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( backupplugin , BackupPlugin );
#endif
......
......@@ -51,6 +51,7 @@
#include <OpenFlipper/BasePlugin/ToolbarInterface.hh>
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <OpenFlipper/BasePlugin/OptionsInterface.hh>
#include <OpenFlipper/common/Types.hh>
#include <QObject>
......@@ -58,7 +59,7 @@
#include "GroupData.hh"
class BackupPlugin : public QObject, BaseInterface , KeyInterface, MenuInterface, BackupInterface, LoggingInterface, ToolbarInterface, LoadSaveInterface, ContextMenuInterface
class BackupPlugin : public QObject, BaseInterface , KeyInterface, MenuInterface, BackupInterface, LoggingInterface, ToolbarInterface, LoadSaveInterface, ContextMenuInterface, OptionsInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
......@@ -69,6 +70,7 @@ Q_INTERFACES(LoggingInterface)
Q_INTERFACES(ToolbarInterface)
Q_INTERFACES(LoadSaveInterface)
Q_INTERFACES(ContextMenuInterface)
Q_INTERFACES(OptionsInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Backup")
......@@ -110,6 +112,7 @@ signals:
private slots:
// BaseInterface
void initializePlugin();
void pluginsInitialized();
void slotAllCleared();
......@@ -131,6 +134,10 @@ private slots:
//ContextMenuInterface
void slotUpdateContextMenu( int _objectId );
// OptionsInterface
bool initializeOptionsWidget(QWidget*& _widget);
void applyOptions();
private slots:
void updateButtons();
......@@ -169,6 +176,8 @@ private :
QAction* undoContextAction_;
QAction* redoContextAction_;
QSpinBox* maxBackupSpinBox_;
};
#endif //BACKUPPLUGIN_HH
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment