<commit_before>#include "gui/navigation/qrnavigation.h"

#include <QtCore/qdebug.h>
#include <QtWidgets/qtabwidget.h>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qpushbutton.h>

#include "gui/navigation/qrnavigationheader.h"
#include "gui/navigation/qrnavigationtabpage.h"
#include "db/qrtblnavigation.h"

NS_CHAOS_BASE_BEGIN

class QrNavigationPrivate {
    QR_DECLARE_PUBLIC(QrNavigation)
public:
    QrNavigationPrivate(QrNavigation *q);

public:
    static QrNavigationPrivate* dInstance();

public:
    void loadUI();
    QPushButton *getButton(const QString &path);

public:
    QrNavigationHeader *header = nullptr;
    QrNavigationTabPage *totalTabPage = nullptr;
    QrNavigationTabPage *customTabPage = nullptr;
    QTabWidget* navigationTab = nullptr;
    QMap<QString, QPushButton*> pathButtonContainer;

public:
    static QrNavigation* qInstance;
};

QrNavigation* QrNavigationPrivate::qInstance = nullptr;

QrNavigationPrivate::QrNavigationPrivate(QrNavigation *q)
    : q_ptr(q) {
    qInstance = q;
}

QrNavigationPrivate *QrNavigationPrivate::dInstance(){
    Q_ASSERT(nullptr != QrNavigationPrivate::qInstance);
    return QrNavigationPrivate::qInstance->d_func();
}

void QrNavigationPrivate::loadUI()
{
    Q_Q(QrNavigation);
    header = new QrNavigationHeader(q);

    QrTblNavigationHelper tblNavigationHelper;
    totalTabPage = new QrNavigationTabPage(q);
    QObject::connect(totalTabPage, &QrNavigationTabPage::addButton,
                     [this](QString path, QPushButton* itemButton){
        this->pathButtonContainer[path] = itemButton;
    });

    totalTabPage->initModelByDbData(tblNavigationHelper.getData());
    QObject::connect(totalTabPage, &QrNavigationTabPage::removeButton,
                     [this](QString path, QPushButton* itemButton){
        auto findIter = this->pathButtonContainer.find(path);
        Q_ASSERT(findIter.value() == itemButton);
        this->pathButtonContainer.erase(findIter);
        qDebug() << "navigation remove item " << path;
    });
    this->header->navigationModelProxy(totalTabPage->modelProxy()); //  default

    customTabPage = new QrNavigationTabPage(q);

    navigationTab = new QTabWidget(q);
    navigationTab->addTab(totalTabPage, "Total");
    navigationTab->addTab(customTabPage, "Custom");

    QVBoxLayout* mainLayout = new QVBoxLayout();
    mainLayout->setContentsMargins(0,0,0,0);
    mainLayout->setSpacing(0);
    mainLayout->addWidget(header);
    mainLayout->addWidget(navigationTab);
    q->setLayout(mainLayout);

    QObject::connect(navigationTab, &QTabWidget::currentChanged, [this](int index){
        auto curNavTab = qobject_cast<QrNavigationTabPage*>(this->navigationTab->widget(index));
        this->header->navigationModelProxy(curNavTab->modelProxy());
    });


    QObject::connect(this->header, &QrNavigationHeader::beginSearch, [this](){
        qobject_cast<QrNavigationTabPage*>(navigationTab->currentWidget())->expandAll();
    });
}

QPushButton *QrNavigationPrivate::getButton(const QString &path)<commit_msg>use db to drive custom tab page of navigation<commit_after>﻿#include "gui/navigation/qrnavigation.h"

#include <QtCore/qdebug.h>
#include <QtWidgets/qtabwidget.h>
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qpushbutton.h>

#include "gui/navigation/qrnavigationheader.h"
#include "gui/navigation/qrnavigationtabpage.h"
#include "db/qrtblnavigation.h"
#include "db/qrtblframeconfig.h"

NS_CHAOS_BASE_BEGIN

class QrNavigationPrivate {
    QR_DECLARE_PUBLIC(QrNavigation)
public:
    QrNavigationPrivate(QrNavigation *q);

public:
    static QrNavigationPrivate* dInstance();

public:
    void loadUI();
    void addTotalTabPage();
    void addCustomTabPage();
    QPushButton *getButton(const QString &path);

public:
    QrNavigationHeader *header = nullptr;
    QrNavigationTabPage *totalTabPage = nullptr;
    QrNavigationTabPage *customTabPage = nullptr;
    QTabWidget* navigationTab = nullptr;
    QMap<QString, QPushButton*> pathButtonContainer;

public:
    static QrNavigation* qInstance;
};

QrNavigation* QrNavigationPrivate::qInstance = nullptr;

QrNavigationPrivate::QrNavigationPrivate(QrNavigation *q)
    : q_ptr(q) {
    qInstance = q;
}

QrNavigationPrivate *QrNavigationPrivate::dInstance(){
    Q_ASSERT(nullptr != QrNavigationPrivate::qInstance);
    return QrNavigationPrivate::qInstance->d_func();
}

void QrNavigationPrivate::addTotalTabPage(){
    Q_Q(QrNavigation);
    QrTblNavigationHelper tblNavigationHelper;
    totalTabPage = new QrNavigationTabPage(q);
    QObject::connect(totalTabPage, &QrNavigationTabPage::addButton,
                     [this](QString path, QPushButton* itemButton){
        this->pathButtonContainer[path] = itemButton;
    });

    totalTabPage->initModelByDbData(tblNavigationHelper.getData());
    QObject::connect(totalTabPage, &QrNavigationTabPage::removeButton,
                     [this](QString path, QPushButton* itemButton){
        auto findIter = this->pathButtonContainer.find(path);
        Q_ASSERT(findIter.value() == itemButton);
        this->pathButtonContainer.erase(findIter);
        qDebug() << "navigation remove item " << path;
    });
    this->header->navigationModelProxy(totalTabPage->modelProxy()); //  default

    navigationTab->addTab(totalTabPage, "Total");
}

void QrNavigationPrivate::addCustomTabPage(){
    static QString type = "gui";
    static QString key = "custom_nav";

    Q_Q(QrNavigation);
    QString needCusttomNavigation;
    if ( ! Qters::QrFrame::QrTblFrameConfigHelper::getValueBy(type, key, &needCusttomNavigation) ) {
        needCusttomNavigation = "false";
    }
    if ( "true" == needCusttomNavigation ) {
        customTabPage = new QrNavigationTabPage(q);
        navigationTab->addTab(customTabPage, "Custom");
    }
}

void QrNavigationPrivate::loadUI()
{
    Q_Q(QrNavigation);
    header = new QrNavigationHeader(q);

    navigationTab = new QTabWidget(q);
    addTotalTabPage();
    addCustomTabPage();

    QVBoxLayout* mainLayout = new QVBoxLayout();
    mainLayout->setContentsMargins(0,0,0,0);
    mainLayout->setSpacing(0);
    mainLayout->addWidget(header);
    mainLayout->addWidget(navigationTab);
    q->setLayout(mainLayout);

    QObject::connect(navigationTab, &QTabWidget::currentChanged, [this](int index){
        auto curNavTab = qobject_cast<QrNavigationTabPage*>(this->navigationTab->widget(index));
        this->header->navigationModelProxy(curNavTab->modelProxy());
    });

    QObject::connect(this->header, &QrNavigationHeader::beginSearch, [this](){
        qobject_cast<QrNavigationTabPage*>(navigationTab->currentWidget())->expandAll();
    });
}

QPushButton *QrNavigationPrivate::getButton(const QString &path)
{'fraction_non_alphanumeric': 0.12257968424188263, 'fraction_numerical': 0.0014894250819183796, 'mean_word_length': 4.9007029876977155, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 63, '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': '5822514', 'n_tokens_mistral': 2076, 'n_tokens_neox': 2039, 'n_words': 324}