FreeCAD

Форк
0
/
DlgUndoRedo.cpp 
130 строк · 4.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#ifndef _PreComp_
26
#include <QAction>
27
#include <QList>
28
#endif
29

30
#include "DlgUndoRedo.h"
31
#include "Application.h"
32
#include "MainWindow.h"
33
#include "MDIView.h"
34

35

36
using namespace Gui::Dialog;
37

38
/* TRANSLATOR Gui::Dialog::UndoRedoDialog */
39

40
/**
41
 *  Constructs a UndoRedoDialog which is a child of 'parent', with the
42
 *  name 'name'.'
43
 */
44
UndoDialog::UndoDialog( QWidget* parent )
45
  : QMenu( parent )
46
{
47
    connect(this, &QMenu::aboutToShow, this, &UndoDialog::onFetchInfo);
48
}
49

50
/**
51
 *  Destroys the object and frees any allocated resources.
52
 */
53
UndoDialog::~UndoDialog() = default;
54

55
/**
56
 *  This method fetches the undo / redo information from the
57
 *  active document and shows it in the undo / redo dialog.
58
 */
59
void UndoDialog::onFetchInfo()
60
{
61
    clear(); // Remove first all items
62

63
    MDIView* mdi =  getMainWindow()->activeWindow();
64
    if (mdi) {
65
        QStringList vecUndos = mdi->undoActions();
66
        for (QStringList::Iterator i = vecUndos.begin(); i != vecUndos.end(); ++i) {
67
            addAction(*i, this, &UndoDialog::onSelected);
68
        }
69
    }
70
}
71

72
/** Closes the dialog and sends the message 'Undo' to the currently active MDI view. */
73
void UndoDialog::onSelected()
74
{
75
    auto a = static_cast<QAction*>(sender());
76
    QList<QAction*> acts = this->actions();
77
    for (QList<QAction*>::Iterator it = acts.begin(); it != acts.end(); ++it) {
78
        Gui::Application::Instance->sendMsgToActiveView("Undo");
79
        if (*it == a)
80
            break;
81
    }
82
}
83

84
/* TRANSLATOR Gui::Dialog::RedoDialog */
85

86
/**
87
 *  Constructs a UndoRedoDialog which is a child of 'parent', with the
88
 *  name 'name'.'
89
 */
90
RedoDialog::RedoDialog( QWidget* parent )
91
  : QMenu( parent )
92
{
93
    connect(this, &QMenu::aboutToShow, this, &RedoDialog::onFetchInfo);
94
}
95

96
/**
97
 *  Destroys the object and frees any allocated resources.
98
 */
99
RedoDialog::~RedoDialog() = default;
100

101
/**
102
 *  This method fetches the undo / redo information from the
103
 *  active document and shows it in the undo / redo dialog.
104
 */
105
void RedoDialog::onFetchInfo()
106
{
107
    clear(); // Remove first all items
108

109
    MDIView* mdi = getMainWindow()->activeWindow();
110
    if (mdi) {
111
        QStringList vecRedos = mdi->redoActions();
112
        for (QStringList::Iterator i = vecRedos.begin(); i != vecRedos.end(); ++i) {
113
            addAction(*i, this, &RedoDialog::onSelected);
114
        }
115
    }
116
}
117

118
/** Closes the dialog and sends the message 'Redo' to the currently active MDI view. */
119
void RedoDialog::onSelected()
120
{
121
    auto a = static_cast<QAction*>(sender());
122
    QList<QAction*> acts = this->actions();
123
    for (QList<QAction*>::Iterator it = acts.begin(); it != acts.end(); ++it) {
124
        Gui::Application::Instance->sendMsgToActiveView("Redo");
125
        if (*it == a)
126
            break;
127
    }
128
}
129

130
#include "moc_DlgUndoRedo.cpp"
131

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.