50 #include "BackupPlugin.hh"
51 #if QT_VERSION >= 0x050000
59 #include "GroupBackup.hh"
62 BackupPlugin::BackupPlugin():
65 backupsEnabledAction_(0),
70 undoContextAction_(0),
71 redoContextAction_(0),
79 void BackupPlugin::initializePlugin()
87 void BackupPlugin::pluginsInitialized() {
90 emit getMenubarMenu(tr(
"&Backup"),
backupMenu_,
true );
92 if ( OpenFlipper::Options::gui() ) {
94 backupsEnabledAction_ =
new QAction(
"Backups Enabled",0);
95 backupsEnabledAction_->setCheckable(
true);
98 undoMenuAction_ =
new QAction(tr(
"&Undo"),
this);
99 undoMenuAction_->setEnabled(
false);
100 undoMenuAction_->setStatusTip(tr(
"Undo the last action."));
101 undoMenuAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"edit-undo.png") );
102 connect(undoMenuAction_, SIGNAL(triggered()),
this, SIGNAL( undo() ) );
104 redoMenuAction_ =
new QAction(tr(
"&Redo"),
this);
105 redoMenuAction_->setEnabled(
false);
106 redoMenuAction_->setStatusTip(tr(
"Redo the last action"));
107 redoMenuAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"edit-redo.png") );
108 connect(redoMenuAction_, SIGNAL(triggered()),
this, SIGNAL( redo() ) );
116 QToolBar* toolbar =
new QToolBar(
"Backup Toolbar");
119 undoToolAction_ =
new QAction(tr(
"&Undo"),
this);
120 undoToolAction_->setEnabled(
false);
121 undoToolAction_->setStatusTip(tr(
"Undo the last action."));
122 undoToolAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"edit-undo.png") );
123 connect(undoToolAction_, SIGNAL(triggered()),
this, SIGNAL( undo() ) );
124 toolbar->addAction(undoToolAction_);
127 redoToolAction_ =
new QAction(tr(
"&Redo"),
this);
128 redoToolAction_->setEnabled(
false);
129 redoToolAction_->setStatusTip(tr(
"Redo the last action"));
130 redoToolAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"edit-redo.png") );
131 connect(redoToolAction_, SIGNAL(triggered()),
this, SIGNAL( redo() ) );
132 toolbar->addAction(redoToolAction_);
134 emit addToolbar( toolbar );
137 emit registerKey(Qt::Key_Z, Qt::ControlModifier, tr(
"Undo Action"));
138 emit registerKey(Qt::Key_Z, (Qt::ControlModifier | Qt::ShiftModifier), tr(
"Redo Action"));
141 undoContextAction_ =
new QAction(tr(
"&Undo"),
this);
142 undoContextAction_->setEnabled(
false);
143 undoContextAction_->setStatusTip(tr(
"Undo the last action."));
144 undoContextAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"edit-undo.png") );
145 connect(undoContextAction_, SIGNAL(triggered()),
this, SLOT(slotObjectUndo()) );
148 redoContextAction_ =
new QAction(tr(
"&Redo"),
this);
149 redoContextAction_->setEnabled(
false);
150 redoContextAction_->setStatusTip(tr(
"Redo the last action"));
151 redoContextAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"edit-redo.png") );
152 connect(redoContextAction_, SIGNAL(triggered()),
this, SLOT(slotObjectRedo()) );
156 if (maxBackupSpinBox_)
157 maxBackupSpinBox_->setValue(globalBackup_.
maxBackups());
162 emit setSlotDescription(
"createBackup(int,QString)", tr(
"Creates a backup which can be restored via undo."),
163 QString(
"objectId,name").split(
","), QString(
"Id of the object,name of the backup").split(
","));
164 emit setSlotDescription(
"createBackup(int,QString,UpdateType)", tr(
"Creates a backup which can be restored via undo."),
165 QString(
"objectId,name,type").split(
","), QString(
"Id of the object,name of the backup,updatetypes which are changed").split(
","));
170 void BackupPlugin::slotAllCleared(){
171 globalBackup_.
clear();
177 void BackupPlugin::updateButtons() {
180 undoMenuAction_->setText( tr(
"Undo '%1'").arg( globalBackup_.
undoName() ) );
181 undoMenuAction_->setEnabled(
true);
182 undoToolAction_->setText( tr(
"Undo '%1'").arg( globalBackup_.
undoName() ) );
183 undoToolAction_->setEnabled(
true);
185 undoMenuAction_->setText( tr(
"Undo") );
186 undoMenuAction_->setEnabled(
false);
187 undoToolAction_->setText( tr(
"Undo") );
188 undoToolAction_->setEnabled(
false);
192 redoMenuAction_->setText( tr(
"Redo '%1'").arg( globalBackup_.
redoName() ) );
193 redoMenuAction_->setEnabled(
true);
194 redoToolAction_->setText( tr(
"Redo '%1'").arg( globalBackup_.
redoName() ) );
195 redoToolAction_->setEnabled(
true);
197 redoMenuAction_->setText( tr(
"Redo") );
198 redoMenuAction_->setEnabled(
false);
199 redoToolAction_->setText( tr(
"Redo") );
200 redoToolAction_->setEnabled(
false);
203 backupsEnabledAction_->setChecked( OpenFlipper::Options::backupEnabled() );
209 OpenFlipper::Options::enableBackup(backupsEnabledAction_->isChecked());
214 void BackupPlugin::slotKeyEvent( QKeyEvent* _event ){
215 switch (_event->key())
218 if ( _event->modifiers() == Qt::ControlModifier )
220 else if ( _event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier) )
230 void BackupPlugin::objectDeleted(
int _objectid) {
237 void BackupPlugin::slotUpdateContextMenu(
int _objectId ){
240 undoContextAction_->setText( tr(
"Undo") );
241 undoContextAction_->setEnabled(
false);
242 redoContextAction_->setText( tr(
"Redo") );
243 redoContextAction_->setEnabled(
false);
257 undoContextAction_->setData(_objectId);
258 undoContextAction_->setText( tr(
"Undo '%1'").arg( backupData->
undoName() ) );
259 undoContextAction_->setEnabled( !backupData->
undoBlocked() );
263 redoContextAction_->setData(_objectId);
264 redoContextAction_->setText( tr(
"Redo '%1'").arg( backupData->
redoName() ) );
265 redoContextAction_->setEnabled( !backupData->
redoBlocked() );
274 void BackupPlugin::slotObjectUndo(){
276 int id = undoContextAction_->data().toInt();
282 void BackupPlugin::slotObjectRedo(){
284 int id = undoContextAction_->data().toInt();
290 void BackupPlugin::slotCreateBackup(
int _objectid, QString _name,
UpdateType _type){
292 if ( !OpenFlipper::Options::backupEnabled() )
298 emit log(
LOGWARN,
"Unable to find backup object with id " + QString::number(_objectid));
303 emit generateBackup( _objectid, _name, _type );
307 groupIds.push_back( _objectid );
309 bool skipBackup =
false;
315 if ( backupData != 0 )
325 emit log(
LOGOUT,
"Created backup for " + QString::number(_objectid)+
" , Name : '" + _name +
"'" );
330 void BackupPlugin::slotCreateBackup(
IdList _objectids , QString _name, std::vector<UpdateType> _types){
332 if ( !OpenFlipper::Options::backupEnabled() )
337 if ( _objectids.size() != _types.size() ){
338 emit log(
LOGWARN,
"Unable to create backup sizes of ids and updateTypes do not match!");
343 for (
unsigned int i=0; i < _objectids.size(); ++i){
348 emit log(
LOGWARN,
"Unable to find backup object with id " + QString::number(_objectids[i]));
353 emit generateBackup( _objectids[i], _name, _types[i] );
354 groupIds.push_back( _objectids[i] );
358 if ( ! groupIds.empty() ){
364 emit log(
LOGOUT,
"Created grouped backup, Name : '" + _name +
"'" );
370 void BackupPlugin::slotUndo(
int _objectid){
372 emit aboutToRestore(_objectid);
373 globalBackup_.
undo(_objectid);
374 emit restored(_objectid);
382 void BackupPlugin::slotUndo(){
386 IdList ids = group->objectIDs();
387 IdList::const_iterator it, end;
388 for (it = ids.begin(), end = ids.end(); it != end; ++it)
389 emit aboutToRestore(*it);
391 globalBackup_.
undo();
393 for (
unsigned int i=0; i < group->objectIDs().size(); i++)
395 emit restored(group->objectIDs()[i]);
396 emit updatedObject(group->objectIDs()[i],
UPDATE_ALL);
401 emit log(
LOGWARN,
"Unable to find the current GroupBackup");
406 void BackupPlugin::slotRedo(
int _objectid){
408 emit aboutToRestore(_objectid);
409 globalBackup_.
redo(_objectid);
410 emit restored(_objectid);
418 void BackupPlugin::slotRedo(){
419 globalBackup_.
redo();
424 for (
unsigned int i=0; i < group->objectIDs().size(); i++)
426 emit restored(group->objectIDs()[i]);
427 emit updatedObject(group->objectIDs()[i],
UPDATE_ALL);
437 slotCreateBackup(_objectId,_name,_type);
442 bool BackupPlugin::initializeOptionsWidget(QWidget*& _widget)
444 QLabel* maxBackupLabel =
new QLabel();
445 maxBackupLabel->setText(tr(
"Max. saved backups: "));
446 maxBackupSpinBox_ =
new QSpinBox();
447 maxBackupSpinBox_->setValue(globalBackup_.
maxBackups());
448 maxBackupSpinBox_->setRange(0,100);
450 QHBoxLayout* layout =
new QHBoxLayout();
451 layout->addWidget(maxBackupLabel);
452 layout->addWidget(maxBackupSpinBox_);
454 QWidget* baseWidget =
new QWidget();
455 baseWidget->setLayout(layout);
456 _widget = baseWidget;
463 void BackupPlugin::applyOptions()
465 int maxBackups = maxBackupSpinBox_->value();
470 #if QT_VERSION < 0x050000
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void undo()
perform an undo if possible
void storeBackup(BaseBackup *_backup)
store a backup
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void clear()
remove all backups
void slotEnableDisableBackups()
Backups enabled or disabled checkbox.
QMenu * backupMenu_
The backup Menu.
bool redoBlocked()
return if a redo backup is blocked
Class that encapsulates simultaneous backups on multiple objects.
bool hasObjectData(QString _dataName)
Checks if object data with given name is available.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
bool undoBlocked()
return if an undo backup is blocked
BaseBackup * currentState()
return the current state
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
bool undoAvailable()
return if an undo backup is available
size_t maxBackups()
return the maximum of backups which are saved
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void redo()
perform an redo if possible
The Menu will be shown when an object was picked.
QString undoName()
return the name of the next undo backup
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void eraseBackups(int _objectid)
erase all backups containing given id
bool redoAvailable()
return if a redo backup is available
void createBackup(int _objectId, QString _name, UpdateType _type=UPDATE_ALL)
Tell Backup Plugin to create a backup.
QString redoName()
return the name of the next redo backup
void setMaxBackups(size_t _max)
set the maximum of saved backups
Abstract class that is used to store backups.