예제 #1
0
QStandardItem * PreferencesDialog::pluginCategoryItem(PluginInfo::Category pCategory)
{
    // Return the given category item, after having created it, if it didn't
    // already exist

    QStandardItem *res = mCategoryItems.value(pCategory);

    if (res == nullptr) {
        // No category item exists for the given category, so create one and add
        // it to our data model (and this in the right place)

        bool inserted = false;
        QStandardItem *rootItem = mModel->invisibleRootItem();
        QString categoryName = pluginCategoryName(pCategory);
        QString nonDiacriticCategoryName = nonDiacriticString(categoryName);

        res = new QStandardItem(categoryName);

        for (int i = 0, iMax = rootItem->rowCount(); i < iMax; ++i) {
            if (nonDiacriticCategoryName.compare(nonDiacriticString(rootItem->child(i)->text())) < 0) {
                inserted = true;

                mModel->invisibleRootItem()->insertRow(i, res);

                break;
            }
        }

        if (!inserted) {
            mModel->invisibleRootItem()->appendRow(res);
        }

        // Keep track of the relationship between our new item and its category

        mCategoryItems.insert(pCategory, res);
        mItemCategories.insert(res, pCategory);
    }

    return res;
}
예제 #2
0
PluginsWindow::PluginsWindow(PluginManager *pPluginManager,
                             MainWindow *pMainWindow) :
    QDialog(pMainWindow),
    mGui(new Ui::PluginsWindow),
    mMainWindow(pMainWindow),
    mPluginManager(pPluginManager),
    mMappedCategories(QMap<QString, QString>()),
    mSelectablePluginItems(QList<QStandardItem *>()),
    mUnselectablePluginItems(QList<QStandardItem *>())
{
    // Set up the GUI

    mGui->setupUi(this);

    // Make sure that all the widgets in our details layout can be resized if
    // necessary and if possible
    // Note: indeed, it's not the case on OS X since the field growth policy is
    //       set to FieldsStayAtSizeHint on that platform and also on Windows
    //       and Linux to make sure that, if anything, we get the same behaviour
    //       on all the platforms we support...

    mGui->detailsLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);

    // Update the note label

    mGui->noteLabel->setText(mGui->noteLabel->text().arg(qAppName()));

    // Set up the tree view widget with a delegate, so that we can select
    // plugins that are shown as 'disabled' (to reflect the fact that users
    // cannot decide whether they should be loaded)

    mModel = new QStandardItemModel(mGui->pluginsTreeView);
    mItemDelegate = new PluginItemDelegate();

#ifdef Q_OS_MAC
    mGui->pluginsTreeView->setAttribute(Qt::WA_MacShowFocusRect, false);
    // Note: the above removes the focus border since it messes up the look of
    //       our plugins tree view widget...
#endif
    mGui->pluginsTreeView->setModel(mModel);
    mGui->pluginsTreeView->setItemDelegate(mItemDelegate);

    // Populate the data model with our different categories of plugins, making
    // sure that they are in alphabetical order, no matter the locale

    mMappedCategories.insert(tr("Analysis"), AnalysisCategory);
    mMappedCategories.insert(tr("API"), ApiCategory);
    mMappedCategories.insert(tr("Data Store"), DataStoreCategory);
    mMappedCategories.insert(tr("Editing"), EditingCategory);
    mMappedCategories.insert(tr("Miscellaneous"), MiscellaneousCategory);
    mMappedCategories.insert(tr("Organisation"), OrganisationCategory);
#ifdef ENABLE_SAMPLES
    mMappedCategories.insert(tr("Sample"), SampleCategory);
#endif
    mMappedCategories.insert(tr("Simulation"), SimulationCategory);
    mMappedCategories.insert(tr("Solver"), SolverCategory);
    mMappedCategories.insert(tr("Support"), SupportCategory);
    mMappedCategories.insert(tr("Third-party"), ThirdPartyCategory);
    mMappedCategories.insert(tr("Tool"), ToolCategory);
    mMappedCategories.insert(tr("Widget"), WidgetCategory);

    QMap<QString, QString> diacriticCategories = QMap<QString, QString>();

    foreach (const QString &diacriticCategory, mMappedCategories.keys())
        diacriticCategories.insert(nonDiacriticString(diacriticCategory), diacriticCategory);

    QStringList nonDiacriticCategories = diacriticCategories.keys();

    nonDiacriticCategories.sort(Qt::CaseInsensitive);

    foreach (const QString &nonDiacriticCategory, nonDiacriticCategories) {
        QString diacriticCategory = diacriticCategories.value(nonDiacriticCategory);

        newPluginCategory(mMappedCategories.value(diacriticCategory), diacriticCategory);
    }