Commit 952c3253 authored by Christoph Cullmann's avatar Christoph Cullmann 🍨
Browse files

remove double storage

only have one storage for the toolviews
avoids any linear search for them
ensure id is constant
ensure we don't insert nullptr by [] usage
parent be881677
Pipeline #256610 passed with stage
in 14 minutes and 28 seconds
......@@ -244,11 +244,12 @@ void GUIClient::updateActions()
// BEGIN TOOLVIEW
ToolView::ToolView(MainWindow *mainwin, Sidebar *sidebar, QWidget *parent)
ToolView::ToolView(MainWindow *mainwin, Sidebar *sidebar, QWidget *parent, const QString &identifier)
: QFrame(parent)
, m_mainWin(mainwin)
, m_sidebar(sidebar)
, m_toolbar(nullptr)
, id(identifier)
, m_toolVisible(false)
{
// try to fix resize policy
......@@ -716,10 +717,9 @@ ToolView *Sidebar::addToolView(const QIcon &icon, const QString &text, const QSt
widget->sidebar()->removeToolView(widget);
} else {
widget = new ToolView(m_mainWin, this, nullptr);
widget = new ToolView(m_mainWin, this, nullptr, identifier);
widget->icon = icon;
widget->text = text;
widget->id = identifier;
}
widget->m_sidebar = this;
......@@ -1340,12 +1340,9 @@ MainWindow::~MainWindow()
{
// kill all toolviews, they will deregister themself
while (!m_toolviews.empty()) {
delete m_toolviews.back();
delete m_toolviews.begin()->second;
}
// cleanup of toolviews should have de-registered all of them
Q_ASSERT(m_idToWidget.empty());
// seems like we really should delete this by hand ;)
delete m_centralWidget;
}
......@@ -1375,8 +1372,7 @@ ToolView *MainWindow::createToolView(KTextEditor::Plugin *plugin,
ToolView *v = m_sidebars[pos]->addToolView(icon, text, identifier, nullptr);
v->plugin = plugin;
m_idToWidget.emplace(identifier, v);
m_toolviews.push_back(v);
m_toolviews.emplace(identifier, v);
// register for menu stuff
m_guiClient->registerToolView(v);
......@@ -1386,8 +1382,8 @@ ToolView *MainWindow::createToolView(KTextEditor::Plugin *plugin,
ToolView *MainWindow::toolView(const QString &identifier) const
{
auto it = m_idToWidget.find(identifier);
if (it != m_idToWidget.end()) {
auto it = m_toolviews.find(identifier);
if (it != m_toolviews.end()) {
return it->second;
}
return nullptr;
......@@ -1408,9 +1404,7 @@ void MainWindow::toolViewDeleted(ToolView *widget)
widget->sidebar()->removeToolView(widget);
m_idToWidget.erase(widget->id);
m_toolviews.erase(std::remove(m_toolviews.begin(), m_toolviews.end(), widget), m_toolviews.end());
m_toolviews.erase(widget->id);
}
void MainWindow::setSidebarsVisibleInternal(bool visible, bool noWarning)
......@@ -1515,9 +1509,7 @@ QWidget *MainWindow::toolviewToggleButton(ToolView *tv)
void MainWindow::hideToolViews()
{
for (const auto &tv : m_toolviews) {
if (tv) {
tv->sidebar()->hideToolView(tv);
}
tv.second->sidebar()->hideToolView(tv.second);
}
triggerFocusForCentralWidget();
}
......@@ -1559,9 +1551,9 @@ void MainWindow::finishRestore()
applyMainWindowSettings(cg);
// reshuffle toolviews only if needed
for (const auto tv : m_toolviews) {
for (const auto &[id, tv] : m_toolviews) {
KMultiTabBar::KMultiTabBarPosition newPos = static_cast<KMultiTabBar::KMultiTabBarPosition>(
cg.readEntry(QStringLiteral("Kate-MDI-ToolView-%1-Position").arg(tv->id), int(tv->sidebar()->position())));
cg.readEntry(QStringLiteral("Kate-MDI-ToolView-%1-Position").arg(id), int(tv->sidebar()->position())));
if (tv->sidebar()->position() != newPos) {
moveToolView(tv, newPos);
......
......@@ -101,8 +101,9 @@ protected:
* @param mainwin main window for this toolview
* @param sidebar sidebar of this toolview
* @param parent parent widget, e.g. the splitter of one of the sidebars
* @param identifier unique id
*/
ToolView(class MainWindow *mainwin, class Sidebar *sidebar, QWidget *parent);
ToolView(class MainWindow *mainwin, class Sidebar *sidebar, QWidget *parent, const QString &identifier);
public:
/**
......@@ -163,7 +164,7 @@ private:
/**
* unique id
*/
QString id;
const QString id;
/**
* is visible in sidebar
......@@ -588,14 +589,11 @@ public:
*/
private:
/**
* map identifiers to widgets
* all existing tool views
* mapped by their constant identifier, to have some stable order
* tool views de-register them self on destruction
*/
std::map<QString, ToolView *> m_idToWidget;
/**
* list of all toolviews around
*/
std::vector<ToolView *> m_toolviews;
std::map<QString, ToolView *> m_toolviews;
/**
* widget, which is the central part of the
......
Supports Markdown
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