<commit_before>/*=========================================================================

 medInria

 Copyright (c) INRIA 2013. All rights reserved.
 See LICENSE.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.

=========================================================================*/

#include <medTabbedViewContainers.h>

#include <QtCore>
#include <QShortcut>

#include <medViewContainer.h>
#include <medViewContainerSplitter.h>
#include <medViewContainerManager.h>
#include <medAbstractView.h>
#include <medAbstractNavigator.h>
#include <medAbstractViewNavigator.h>
#include <medAbstractParameter.h>
#include <medParameterPoolManager.h>
#include <medParameterPool.h>
#include <medStringListParameter.h>


class medTabbedViewContainersPrivate
{
public:
    QShortcut *closeShortcut;
    QPushButton *addTabButton;
    QHash <int, QList<QUuid> > containerSelectedForTabIndex;
    medParameterPool *pool;

    int currentIdx;
};

medTabbedViewContainers::medTabbedViewContainers(QWidget *parent) : QTabWidget(parent), d(new medTabbedViewContainersPrivate)
{
    this->setTabsClosable(true);
    this->setMovable(true);



    d->addTabButton = new QPushButton(this);
    d->addTabButton->setObjectName("addTabButton");
    d->addTabButton->setShortcut(Qt::ControlModifier + Qt::Key_T);
    this->setCornerWidget(d->addTabButton);

    d->closeShortcut = new QShortcut(this);
    d->closeShortcut->setKey(Qt::ControlModifier + Qt::Key_W);

    connect(d->addTabButton,SIGNAL(clicked()), this, SLOT(addContainerInTab()));
    connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(disconnectTabFromSplitter(int)));
    connect(this,SIGNAL(tabCloseRequested(int)),this,SLOT(closeTab(int)));
    connect(d->closeShortcut,SIGNAL(activated()),this,SLOT(closeCurrentTab()));
    connect(medViewContainerManager::instance(), SIGNAL(containerAboutToBeDestroyed(QUuid)), this, SLOT(removeContainerFromSelection(QUuid)));
    connect(this, SIGNAL(containersSelectedChanged()), this, SLOT(buildTemporaryPool()));
    connect(this, SIGNAL(currentChanged(int)), this, SLOT(connectContainerSelectedForCurrentTab()));

    d->pool = new medParameterPool(this);
}

medTabbedViewContainers::~medTabbedViewContainers(void)
{
    delete d;
    d = NULL;
}

QList <QUuid> medTabbedViewContainers::containersSelected()
{
    return d->containerSelectedForTabIndex.value(this->currentIndex());
}

void medTabbedViewContainers::lockTabs()
{
    this->setTabsClosable(false);
    this->setMovable(false);
    d->addTabButton->hide();
}

void medTabbedViewContainers::unlockTabs()
{
    this->setTabsClosable(true);
    this->setMovable(true);
    d->addTabButton->show();
}

void medTabbedViewContainers::closeCurrentTab()
{
    this->closeTab(this->currentIndex());
}

void medTabbedViewContainers::closeTab(int index)
{
    // Repopopulate would be called because of the destruction of the root
    // splitter after closing all the container in it.
    // We don't want to repopulate the tab, we want to close it.
    this->widget(index)->disconnect(this, SLOT(repopulateCurrentTab()));

    foreach(medViewContainer* container, containersInTab(index))
        container->close();

    resetTabState();
}

void medTabbedViewContainers::resetTabState()
{
    for(int i = 0; i < this->count(); ++i)
        if(this->tabText(i).isEmpty() || this->tabText(i).startsWith("Tab", Qt::CaseSensitive))
            this->setTabText(i, "Tab" +  QString::number(i+1));

    if(this->count() < 1)
        this->addContainerInTab();
}

medViewContainer* medTabbedViewContainers::addContainerInTab()
{
    return this->addContainerInTab("Tab" + QString::number(this->count()+1));
}

medViewContainer* medTabbedViewContainers::addContainerInTab(const QString &name)<commit_msg>fix typo<commit_after>/*=========================================================================

 medInria

 Copyright (c) INRIA 2013. All rights reserved.
 See LICENSE.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.

=========================================================================*/

#include <medTabbedViewContainers.h>

#include <QtCore>
#include <QShortcut>

#include <medViewContainer.h>
#include <medViewContainerSplitter.h>
#include <medViewContainerManager.h>
#include <medAbstractView.h>
#include <medAbstractNavigator.h>
#include <medAbstractViewNavigator.h>
#include <medAbstractParameter.h>
#include <medParameterPoolManager.h>
#include <medParameterPool.h>
#include <medStringListParameter.h>


class medTabbedViewContainersPrivate
{
public:
    QShortcut *closeShortcut;
    QPushButton *addTabButton;
    QHash <int, QList<QUuid> > containerSelectedForTabIndex;
    medParameterPool *pool;

    int currentIdx;
};

medTabbedViewContainers::medTabbedViewContainers(QWidget *parent) : QTabWidget(parent), d(new medTabbedViewContainersPrivate)
{
    this->setTabsClosable(true);
    this->setMovable(true);



    d->addTabButton = new QPushButton(this);
    d->addTabButton->setObjectName("addTabButton");
    d->addTabButton->setShortcut(Qt::ControlModifier + Qt::Key_T);
    this->setCornerWidget(d->addTabButton);

    d->closeShortcut = new QShortcut(this);
    d->closeShortcut->setKey(Qt::ControlModifier + Qt::Key_W);

    connect(d->addTabButton,SIGNAL(clicked()), this, SLOT(addContainerInTab()));
    connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(disconnectTabFromSplitter(int)));
    connect(this,SIGNAL(tabCloseRequested(int)),this,SLOT(closeTab(int)));
    connect(d->closeShortcut,SIGNAL(activated()),this,SLOT(closeCurrentTab()));
    connect(medViewContainerManager::instance(), SIGNAL(containerAboutToBeDestroyed(QUuid)), this, SLOT(removeContainerFromSelection(QUuid)));
    connect(this, SIGNAL(containersSelectedChanged()), this, SLOT(buildTemporaryPool()));
    connect(this, SIGNAL(currentChanged(int)), this, SLOT(connectContainerSelectedForCurrentTab()));

    d->pool = new medParameterPool(this);
}

medTabbedViewContainers::~medTabbedViewContainers(void)
{
    delete d;
    d = NULL;
}

QList <QUuid> medTabbedViewContainers::containersSelected()
{
    return d->containerSelectedForTabIndex.value(this->currentIndex());
}

void medTabbedViewContainers::lockTabs()
{
    this->setTabsClosable(false);
    this->setMovable(false);
    d->addTabButton->hide();
}

void medTabbedViewContainers::unlockTabs()
{
    this->setTabsClosable(true);
    this->setMovable(true);
    d->addTabButton->show();
}

void medTabbedViewContainers::closeCurrentTab()
{
    this->closeTab(this->currentIndex());
}

void medTabbedViewContainers::closeTab(int index)
{
    // Repopulate would be called because of the destruction of the root
    // splitter after closing all the container in it.
    // We don't want to repopulate the tab, we want to close it.
    this->widget(index)->disconnect(this, SLOT(repopulateCurrentTab()));

    foreach(medViewContainer* container, containersInTab(index))
        container->close();

    this->resetTabState();
}

void medTabbedViewContainers::resetTabState()
{
    for(int i = 0; i < this->count(); ++i)
        if(this->tabText(i).isEmpty() || this->tabText(i).startsWith("Tab", Qt::CaseSensitive))
            this->setTabText(i, "Tab" +  QString::number(i+1));

    if(this->count() < 1)
        this->addContainerInTab();
}

medViewContainer* medTabbedViewContainers::addContainerInTab()
{
    return this->addContainerInTab("Tab" + QString::number(this->count()+1));
}

medViewContainer* medTabbedViewContainers::addContainerInTab(const QString &name)
{'fraction_non_alphanumeric': 0.16724919093851132, 'fraction_numerical': 0.002071197411003236, 'mean_word_length': 6.055707762557078, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 112, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1352858', 'n_tokens_mistral': 2400, 'n_tokens_neox': 2344, 'n_words': 414}