forked from qt-creator/qt-creator
ModelEditor: Support editor's navigation history
For now only the id of the currently opened diagram is stored in the navigation state. The position of scrollers is not saved. Change-Id: Ic9b2237a0223596d1111c635f04f11e3951fd397 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -83,8 +83,21 @@ inline bool operator!=(const Uid &lhs, const Uid &rhs)
|
|||||||
return !operator==(lhs, rhs);
|
return !operator==(lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline QDataStream &operator<<(QDataStream &stream, const Uid &uid)
|
||||||
|
{
|
||||||
|
return stream << uid.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(qmt::Uid);
|
inline QDataStream &operator>>(QDataStream &stream, Uid &uid)
|
||||||
|
{
|
||||||
|
QUuid uuid;
|
||||||
|
stream >> uuid;
|
||||||
|
uid.setUuid(uuid);
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(qmt::Uid)
|
||||||
|
|
||||||
#endif // QMT_UID_H
|
#endif // QMT_UID_H
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ ModelEditor::ModelEditor(UiController *uiController, ActionHandler *actionHandle
|
|||||||
|
|
||||||
ModelEditor::~ModelEditor()
|
ModelEditor::~ModelEditor()
|
||||||
{
|
{
|
||||||
closeCurrentDiagram();
|
closeCurrentDiagram(false);
|
||||||
delete d->toolbar;
|
delete d->toolbar;
|
||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
@@ -151,6 +151,30 @@ QWidget *ModelEditor::toolBar()
|
|||||||
return d->toolbar;
|
return d->toolbar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray ModelEditor::saveState() const
|
||||||
|
{
|
||||||
|
return saveState(currentDiagram());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ModelEditor::restoreState(const QByteArray &state)
|
||||||
|
{
|
||||||
|
QDataStream stream(state);
|
||||||
|
int version = 0;
|
||||||
|
stream >> version;
|
||||||
|
if (version == 1) {
|
||||||
|
qmt::Uid uid;
|
||||||
|
stream >> uid;
|
||||||
|
if (uid.isValid()) {
|
||||||
|
qmt::MDiagram *diagram = d->document->documentController()->getModelController()->findObject<qmt::MDiagram>(uid);
|
||||||
|
if (diagram) {
|
||||||
|
openDiagram(diagram, false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void ModelEditor::init(QWidget *parent)
|
void ModelEditor::init(QWidget *parent)
|
||||||
{
|
{
|
||||||
// create and configure properties view
|
// create and configure properties view
|
||||||
@@ -361,14 +385,7 @@ qmt::MDiagram *ModelEditor::currentDiagram() const
|
|||||||
|
|
||||||
void ModelEditor::showDiagram(qmt::MDiagram *diagram)
|
void ModelEditor::showDiagram(qmt::MDiagram *diagram)
|
||||||
{
|
{
|
||||||
closeCurrentDiagram();
|
openDiagram(diagram, true);
|
||||||
if (diagram) {
|
|
||||||
qmt::DiagramSceneModel *diagramSceneModel = d->document->documentController()->getDiagramsManager()->bindDiagramSceneModel(diagram);
|
|
||||||
d->diagramView->setDiagramSceneModel(diagramSceneModel);
|
|
||||||
d->diagramStack->setCurrentWidget(d->diagramView);
|
|
||||||
updateSelectedArea(SelectedArea::Nothing);
|
|
||||||
addDiagramToSelector(diagram);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelEditor::undo()
|
void ModelEditor::undo()
|
||||||
@@ -945,7 +962,19 @@ void ModelEditor::initToolbars()
|
|||||||
d->leftToolBox->setCurrentIndex(0);
|
d->leftToolBox->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelEditor::closeCurrentDiagram()
|
void ModelEditor::openDiagram(qmt::MDiagram *diagram, bool addToHistory)
|
||||||
|
{
|
||||||
|
closeCurrentDiagram(addToHistory);
|
||||||
|
if (diagram) {
|
||||||
|
qmt::DiagramSceneModel *diagramSceneModel = d->document->documentController()->getDiagramsManager()->bindDiagramSceneModel(diagram);
|
||||||
|
d->diagramView->setDiagramSceneModel(diagramSceneModel);
|
||||||
|
d->diagramStack->setCurrentWidget(d->diagramView);
|
||||||
|
updateSelectedArea(SelectedArea::Nothing);
|
||||||
|
addDiagramToSelector(diagram);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelEditor::closeCurrentDiagram(bool addToHistory)
|
||||||
{
|
{
|
||||||
ExtDocumentController *documentController = d->document->documentController();
|
ExtDocumentController *documentController = d->document->documentController();
|
||||||
qmt::DiagramsManager *diagramsManager = documentController->getDiagramsManager();
|
qmt::DiagramsManager *diagramsManager = documentController->getDiagramsManager();
|
||||||
@@ -953,6 +982,8 @@ void ModelEditor::closeCurrentDiagram()
|
|||||||
if (sceneModel) {
|
if (sceneModel) {
|
||||||
qmt::MDiagram *diagram = sceneModel->getDiagram();
|
qmt::MDiagram *diagram = sceneModel->getDiagram();
|
||||||
if (diagram) {
|
if (diagram) {
|
||||||
|
if (addToHistory)
|
||||||
|
addToNavigationHistory(diagram);
|
||||||
d->diagramStack->setCurrentWidget(d->noDiagramLabel);
|
d->diagramStack->setCurrentWidget(d->noDiagramLabel);
|
||||||
d->diagramView->setDiagramSceneModel(0);
|
d->diagramView->setDiagramSceneModel(0);
|
||||||
diagramsManager->unbindDiagramSceneModel(diagram);
|
diagramsManager->unbindDiagramSceneModel(diagram);
|
||||||
@@ -966,6 +997,7 @@ void ModelEditor::closeDiagram(const qmt::MDiagram *diagram)
|
|||||||
qmt::DiagramsManager *diagramsManager = documentController->getDiagramsManager();
|
qmt::DiagramsManager *diagramsManager = documentController->getDiagramsManager();
|
||||||
qmt::DiagramSceneModel *sceneModel = d->diagramView->getDiagramSceneModel();
|
qmt::DiagramSceneModel *sceneModel = d->diagramView->getDiagramSceneModel();
|
||||||
if (sceneModel && diagram == sceneModel->getDiagram()) {
|
if (sceneModel && diagram == sceneModel->getDiagram()) {
|
||||||
|
addToNavigationHistory(diagram);
|
||||||
d->diagramStack->setCurrentWidget(d->noDiagramLabel);
|
d->diagramStack->setCurrentWidget(d->noDiagramLabel);
|
||||||
d->diagramView->setDiagramSceneModel(0);
|
d->diagramView->setDiagramSceneModel(0);
|
||||||
diagramsManager->unbindDiagramSceneModel(diagram);
|
diagramsManager->unbindDiagramSceneModel(diagram);
|
||||||
@@ -974,7 +1006,7 @@ void ModelEditor::closeDiagram(const qmt::MDiagram *diagram)
|
|||||||
|
|
||||||
void ModelEditor::closeAllDiagrams()
|
void ModelEditor::closeAllDiagrams()
|
||||||
{
|
{
|
||||||
closeCurrentDiagram();
|
closeCurrentDiagram(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelEditor::onContentSet()
|
void ModelEditor::onContentSet()
|
||||||
@@ -1059,6 +1091,25 @@ QString ModelEditor::buildDiagramLabel(const qmt::MDiagram *diagram)
|
|||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelEditor::addToNavigationHistory(const qmt::MDiagram *diagram)
|
||||||
|
{
|
||||||
|
if (Core::EditorManager::currentEditor() == this)
|
||||||
|
Core::EditorManager::cutForwardNavigationHistory();
|
||||||
|
Core::EditorManager::addCurrentPositionToNavigationHistory(saveState(diagram));
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray ModelEditor::saveState(const qmt::MDiagram *diagram) const
|
||||||
|
{
|
||||||
|
QByteArray state;
|
||||||
|
QDataStream stream(&state, QIODevice::WriteOnly);
|
||||||
|
stream << 1; // version number
|
||||||
|
if (diagram)
|
||||||
|
stream << diagram->getUid();
|
||||||
|
else
|
||||||
|
stream << qmt::Uid::getInvalidUid();
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
void ModelEditor::onEditSelectedElement()
|
void ModelEditor::onEditSelectedElement()
|
||||||
{
|
{
|
||||||
// TODO introduce similar method for selected elements in model tree
|
// TODO introduce similar method for selected elements in model tree
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ public:
|
|||||||
|
|
||||||
Core::IDocument *document() override;
|
Core::IDocument *document() override;
|
||||||
QWidget *toolBar() override;
|
QWidget *toolBar() override;
|
||||||
|
QByteArray saveState() const override;
|
||||||
|
bool restoreState(const QByteArray &state) override;
|
||||||
|
|
||||||
qmt::MDiagram *currentDiagram() const;
|
qmt::MDiagram *currentDiagram() const;
|
||||||
void showDiagram(qmt::MDiagram *diagram);
|
void showDiagram(qmt::MDiagram *diagram);
|
||||||
@@ -127,7 +129,8 @@ private:
|
|||||||
void onRightHorizSplitterChanged(const QByteArray &state);
|
void onRightHorizSplitterChanged(const QByteArray &state);
|
||||||
|
|
||||||
void initToolbars();
|
void initToolbars();
|
||||||
void closeCurrentDiagram();
|
void openDiagram(qmt::MDiagram *diagram, bool addToHistory);
|
||||||
|
void closeCurrentDiagram(bool addToHistory);
|
||||||
void closeDiagram(const qmt::MDiagram *diagram);
|
void closeDiagram(const qmt::MDiagram *diagram);
|
||||||
void closeAllDiagrams();
|
void closeAllDiagrams();
|
||||||
|
|
||||||
@@ -138,6 +141,9 @@ private:
|
|||||||
void onDiagramSelectorSelected(int index);
|
void onDiagramSelectorSelected(int index);
|
||||||
QString buildDiagramLabel(const qmt::MDiagram *diagram);
|
QString buildDiagramLabel(const qmt::MDiagram *diagram);
|
||||||
|
|
||||||
|
void addToNavigationHistory(const qmt::MDiagram *diagram);
|
||||||
|
QByteArray saveState(const qmt::MDiagram *diagram) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onEditSelectedElement();
|
void onEditSelectedElement();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user