forked from qt-creator/qt-creator
QmlDesigner: Code cleanup in design mode widget
Remove the redundant initialization of navigation views. Change-Id: I26d0c199cfc8be11b364763c0dba37e41dedc64e Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Henning Gründl
parent
949c380018
commit
d3b8df68eb
@@ -251,38 +251,27 @@ void DesignModeWidget::setup()
|
|||||||
|
|
||||||
// First get all navigation views
|
// First get all navigation views
|
||||||
QList<Core::INavigationWidgetFactory *> factories = Core::INavigationWidgetFactory::allNavigationFactories();
|
QList<Core::INavigationWidgetFactory *> factories = Core::INavigationWidgetFactory::allNavigationFactories();
|
||||||
|
QList<Core::Command *> viewCommands;
|
||||||
QList<Core::Command*> viewCommands;
|
const QList<Utils::Id> navigationViewIds = {"Projects", "File System", "Open Documents"};
|
||||||
|
|
||||||
for (Core::INavigationWidgetFactory *factory : factories) {
|
for (Core::INavigationWidgetFactory *factory : factories) {
|
||||||
Core::NavigationView navigationView;
|
Core::NavigationView navigationView = {nullptr, {}};
|
||||||
navigationView.widget = nullptr;
|
|
||||||
QString uniqueId;
|
|
||||||
QString title;
|
|
||||||
|
|
||||||
if (factory->id() == "Projects") {
|
if (!navigationViewIds.contains(factory->id()))
|
||||||
navigationView = factory->createWidget();
|
continue;
|
||||||
hideToolButtons(navigationView.dockToolBarWidgets);
|
|
||||||
navigationView.widget->setWindowTitle(tr(factory->id().name()));
|
navigationView = factory->createWidget();
|
||||||
uniqueId = "Projects";
|
|
||||||
title = "Projects";
|
if (!navigationView.widget)
|
||||||
}
|
continue;
|
||||||
if (factory->id() == "File System") {
|
|
||||||
navigationView = factory->createWidget();
|
hideToolButtons(navigationView.dockToolBarWidgets);
|
||||||
hideToolButtons(navigationView.dockToolBarWidgets);
|
navigationView.widget->setWindowTitle(tr(factory->id().name()));
|
||||||
navigationView.widget->setWindowTitle(tr(factory->id().name()));
|
|
||||||
uniqueId = "FileSystem";
|
QString idString = factory->id().toSetting().toString();
|
||||||
title = "File System";
|
const QString title = idString;
|
||||||
}
|
const QString uniqueId = idString.remove(" "); // title without whitespaces
|
||||||
if (factory->id() == "Open Documents") {
|
|
||||||
navigationView = factory->createWidget();
|
|
||||||
hideToolButtons(navigationView.dockToolBarWidgets);
|
|
||||||
navigationView.widget->setWindowTitle(tr(factory->id().name()));
|
|
||||||
uniqueId = "OpenDocuments";
|
|
||||||
title = "Open Documents";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (navigationView.widget) {
|
|
||||||
// Apply stylesheet to QWidget
|
// Apply stylesheet to QWidget
|
||||||
QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
|
QByteArray sheet = Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css");
|
||||||
sheet += Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css");
|
sheet += Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css");
|
||||||
@@ -305,7 +294,6 @@ void DesignModeWidget::setup()
|
|||||||
command->setAttribute(Core::Command::CA_Hide);
|
command->setAttribute(Core::Command::CA_Hide);
|
||||||
viewCommands.append(command);
|
viewCommands.append(command);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Afterwards get all the other widgets
|
// Afterwards get all the other widgets
|
||||||
for (const WidgetInfo &widgetInfo : viewManager().widgetInfos()) {
|
for (const WidgetInfo &widgetInfo : viewManager().widgetInfos()) {
|
||||||
@@ -323,7 +311,8 @@ void DesignModeWidget::setup()
|
|||||||
|
|
||||||
// Create menu action
|
// Create menu action
|
||||||
auto command = Core::ActionManager::registerAction(dockWidget->toggleViewAction(),
|
auto command = Core::ActionManager::registerAction(dockWidget->toggleViewAction(),
|
||||||
actionToggle.withSuffix(widgetInfo.uniqueId + "Widget"),
|
actionToggle.withSuffix(
|
||||||
|
widgetInfo.uniqueId + "Widget"),
|
||||||
designContext);
|
designContext);
|
||||||
command->setAttribute(Core::Command::CA_Hide);
|
command->setAttribute(Core::Command::CA_Hide);
|
||||||
viewCommands.append(command);
|
viewCommands.append(command);
|
||||||
@@ -354,7 +343,7 @@ void DesignModeWidget::setup()
|
|||||||
&ADS::DockWidget::toggleView);
|
&ADS::DockWidget::toggleView);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(viewCommands.begin(), viewCommands.end(), [](Core::Command *first, Core::Command *second){
|
std::sort(viewCommands.begin(), viewCommands.end(), [](Core::Command *first, Core::Command *second) {
|
||||||
return first->description() < second->description();
|
return first->description() < second->description();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -367,7 +356,10 @@ void DesignModeWidget::setup()
|
|||||||
|
|
||||||
toolBar->addAction(viewManager().componentViewAction());
|
toolBar->addAction(viewManager().componentViewAction());
|
||||||
toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||||
DesignerActionToolBar *designerToolBar = QmlDesignerPlugin::instance()->viewManager().designerActionManager().createToolBar(m_toolBar);
|
DesignerActionToolBar *designerToolBar = QmlDesignerPlugin::instance()
|
||||||
|
->viewManager()
|
||||||
|
.designerActionManager()
|
||||||
|
.createToolBar(m_toolBar);
|
||||||
|
|
||||||
designerToolBar->layout()->addWidget(toolBar);
|
designerToolBar->layout()->addWidget(toolBar);
|
||||||
|
|
||||||
@@ -376,8 +368,14 @@ void DesignModeWidget::setup()
|
|||||||
m_toolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
|
m_toolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
|
||||||
m_toolBar->setNavigationVisible(true);
|
m_toolBar->setNavigationVisible(true);
|
||||||
|
|
||||||
connect(m_toolBar, &Core::EditorToolBar::goForwardClicked, this, &DesignModeWidget::toolBarOnGoForwardClicked);
|
connect(m_toolBar,
|
||||||
connect(m_toolBar, &Core::EditorToolBar::goBackClicked, this, &DesignModeWidget::toolBarOnGoBackClicked);
|
&Core::EditorToolBar::goForwardClicked,
|
||||||
|
this,
|
||||||
|
&DesignModeWidget::toolBarOnGoForwardClicked);
|
||||||
|
connect(m_toolBar,
|
||||||
|
&Core::EditorToolBar::goBackClicked,
|
||||||
|
this,
|
||||||
|
&DesignModeWidget::toolBarOnGoBackClicked);
|
||||||
|
|
||||||
QToolBar* toolBarWrapper = new QToolBar();
|
QToolBar* toolBarWrapper = new QToolBar();
|
||||||
toolBarWrapper->addWidget(m_toolBar);
|
toolBarWrapper->addWidget(m_toolBar);
|
||||||
@@ -436,7 +434,8 @@ void DesignModeWidget::setup()
|
|||||||
|
|
||||||
void DesignModeWidget::aboutToShowWorkspaces()
|
void DesignModeWidget::aboutToShowWorkspaces()
|
||||||
{
|
{
|
||||||
Core::ActionContainer *aci = Core::ActionManager::actionContainer(QmlDesigner::Constants::M_VIEW_WORKSPACES);
|
Core::ActionContainer *aci = Core::ActionManager::actionContainer(
|
||||||
|
QmlDesigner::Constants::M_VIEW_WORKSPACES);
|
||||||
QMenu *menu = aci->menu();
|
QMenu *menu = aci->menu();
|
||||||
menu->clear();
|
menu->clear();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user