void
QvisSourceManagerWidget::UpdateSourceList(bool updateActiveSourceOnly)
{
    const stringVector &sources     = globalAtts->GetSources();
    const std::string &activeSource = windowInfo->GetActiveSource();

    // See if the active source is in the list.
    int sourceIndex = -1;
    size_t i = 0;
    for(i = 0; i < sources.size(); ++i)
    {
        if(activeSource == sources[i])
        {
            sourceIndex = i;
            break;
        }
    }

    sourceComboBox->blockSignals(true);

    //
    // Populate the menu if we were not told to only update the active source.
    //
    if(!updateActiveSourceOnly)
    {
        //
        // Simplify the current source names and put the short names into
        // the source combo box.
        //
        sourceComboBox->clear();
        if(sources.size() == 1)
        {
            QualifiedFilename qfn(sources[0]);
            sourceComboBox->addItem(qfn.filename.c_str());
        }
        else
        {
            NameSimplifier simplifier;
            for(i = 0; i < sources.size(); ++i)
                simplifier.AddName(sources[i]);
            stringVector shortSources;
            simplifier.GetSimplifiedNames(shortSources);
            for(i = 0; i < shortSources.size(); ++i)
                sourceComboBox->addItem(shortSources[i].c_str());
        }
    }

    //
    // Set the current item.
    //
    if(sourceIndex != -1 && sourceIndex != sourceComboBox->currentIndex())
        sourceComboBox->setCurrentIndex(sourceIndex);

    sourceComboBox->blockSignals(false);

    // Set the enabled state on the source combo box.
    bool enabled = (sources.size() > 0);
    sourceLabel->setEnabled(enabled);
    sourceComboBox->setEnabled(enabled);
}
示例#2
0
void
QvisDatabaseCorrelationWindow::actionClicked()
{
    std::string name;
    stringVector dbs;
    int method = correlationMethodComboBox->currentIndex();

    //
    // Get the name from the line edit.
    //
    name = correlationNameLineEdit->displayText().trimmed().toStdString();

    //
    // If we're creating a new correlation, check the name in the line edit.
    //
    if(createMode)
    {
        if(name.size() < 1)
        {
            Warning(tr("A new database correlation must have a name."));
            correlationNameLineEdit->activateWindow();
            correlationNameLineEdit->setFocus();
            correlationNameLineEdit->setSelection(0,
                correlationNameLineEdit->displayText().length());
            return;
        }
        else
        {
            // See if the name is already used.
            DatabaseCorrelationList *cL = GetViewerState()->GetDatabaseCorrelationList();
            if(cL->FindCorrelation(name))
            {
                Warning(tr("The given database correlation name is already "
                        "being used. Please change the name of this "
                        "correlation."));
                correlationNameLineEdit->activateWindow();
                correlationNameLineEdit->setFocus();
                correlationNameLineEdit->setSelection(0,
                    correlationNameLineEdit->displayText().length());
                return;
            }
        }
    }

    //
    // Simplify the current source names.
    //
    NameSimplifier simplifier;
    const stringVector &sources = GetViewerState()->GetGlobalAttributes()->GetSources();
    int i;
    for(i = 0; i < sources.size(); ++i)
        simplifier.AddName(sources[i]);
    stringVector shortSources;
    simplifier.GetSimplifiedNames(shortSources);
    std::map<std::string, std::string> shortToLong;
    for(i = 0; i < sources.size(); ++i)
        shortToLong[shortSources[i]] = sources[i];

    // Get the sources from the correlated source list.
    for(i = 0; i < correlatedSourcesListBox->count(); ++i)
    {
        std::string srcName(correlatedSourcesListBox->item(i)->text().toStdString());
        dbs.push_back(shortToLong[srcName]);
    }
    if(dbs.size() < 1)
    {
        QString msg;
        QString s1(tr("A database correlation must have at least one correlated "
                      "source."));
        QString s2(tr("You must add a correlated source before you can create "
                      "this database correlation."));
        QString s3(tr("You must add a correlated source before you can alter "
                      "this database correlation."));
        msg = s1 + (createMode ? s2 : s3);
        Warning(msg);
    }

    //
    // Do the right thing in the viewer.
    //
    if(createMode)
    {
        GetViewerMethods()->CreateDatabaseCorrelation(name, dbs, method);
    }
    else
    {
        GetViewerMethods()->AlterDatabaseCorrelation(name, dbs, method);
    }

    cancelClicked();
}
示例#3
0
void
QvisDatabaseCorrelationWindow::CreateWidgets(
    const DatabaseCorrelation &correlation)
{
    QWidget *central = new QWidget(this);
    setCentralWidget(central);

    QVBoxLayout *topLayout = new QVBoxLayout(central);
    topLayout->setMargin(10);
    topLayout->setSpacing(5);

    // Create the name line edit.
    QGridLayout *gLayout = new QGridLayout();
    topLayout->addLayout(gLayout);
    correlationNameLineEdit = new QLineEdit(central);
    correlationNameLineEdit->setText(correlation.GetName().c_str());
    correlationNameLineEdit->setEnabled(createMode);
    QLabel *nameLabel = new QLabel(tr("Name"), central);
    nameLabel->setEnabled(createMode);
    gLayout->addWidget(nameLabel, 0, 0);
    gLayout->addWidget(correlationNameLineEdit, 0, 1);

    // Create the correlation method combobox.
    correlationMethodComboBox = new QComboBox(central);
    correlationMethodComboBox->addItem(tr("Padded index"));
    correlationMethodComboBox->addItem(tr("Stretched index"));
    correlationMethodComboBox->addItem(tr("Time"));
    correlationMethodComboBox->addItem(tr("Cycle"));
    int method = (int)correlation.GetMethod();
    correlationMethodComboBox->setCurrentIndex(method);
    gLayout->addWidget(correlationMethodComboBox, 1, 1);
    gLayout->addWidget(new QLabel(tr("Correlation method"), central), 1, 0);
    topLayout->addSpacing(10);

    // Create the widgets that let us add sources to the database correlation.
    QGridLayout *srcLayout = new QGridLayout();
    topLayout->addLayout(srcLayout);
    srcLayout->setSpacing(5);
    const int S[] = {1, 5, 1, 1, 5};
    int i;
    for(i = 0; i < 5; ++i)
        srcLayout->setRowStretch(i, S[i]);
    srcLayout->addWidget(new QLabel(tr("Sources"), central), 0, 0);
    srcLayout->addWidget(new QLabel(tr("Correlated sources"), central), 0, 2);

    //
    // Simplify the source names.
    //
    NameSimplifier simplifier;
    const stringVector &sources = GetViewerState()->GetGlobalAttributes()->GetSources();
    for(i = 0; i < sources.size(); ++i)
        simplifier.AddName(sources[i]);
    stringVector shortSources;
    simplifier.GetSimplifiedNames(shortSources);
    std::map<std::string, std::string> shortToLong, longToShort;
    for(i = 0; i < sources.size(); ++i)
    {
        shortToLong[shortSources[i]] = sources[i];
        longToShort[sources[i]] = shortSources[i];
    }

    // Create and populate the list of sources.
    sourcesListBox = new QListWidget(central);
    sourcesListBox->setSelectionMode(QAbstractItemView::MultiSelection);
    for(i = 0; i < sources.size(); ++i)
    {
        if(!correlation.UsesDatabase(sources[i]))
            sourcesListBox->addItem(shortSources[i].c_str());
    }
    if(sources.size() > 0)
        sourcesListBox->setCurrentItem(0);
    connect(sourcesListBox, SIGNAL(currentRowChanged(int)),
            this, SLOT(setAddButtonEnabled(int)));
    srcLayout->addWidget(sourcesListBox, 1, 0, 5, 1);

    // Create and populate the list of correlated sources.
    correlatedSourcesListBox = new QListWidget(central);
    correlatedSourcesListBox->setSelectionMode(QAbstractItemView::MultiSelection);
    const stringVector &dbs = correlation.GetDatabaseNames();
    for(i = 0; i < correlation.GetNumDatabases(); ++i)
        correlatedSourcesListBox->addItem(longToShort[dbs[i]].c_str());
    if(dbs.size() > 0)
        correlatedSourcesListBox->setCurrentRow(0);
    connect(correlatedSourcesListBox, SIGNAL(currentRowChanged(int)),
            this, SLOT(setRemoveButtonEnabled(int)));
    srcLayout->addWidget(correlatedSourcesListBox, 1, 2, 5, 1);

    // Create the add and remove buttons.
    addButton = new QPushButton("-->", central);
    connect(addButton, SIGNAL(clicked()),
            this, SLOT(addSources()));
    srcLayout->addWidget(addButton, 2, 1);

    removeButton = new QPushButton("<--", central);
    connect(removeButton, SIGNAL(clicked()),
            this, SLOT(removeSources()));
    srcLayout->addWidget(removeButton, 3, 1);

    UpdateAddRemoveButtonsEnabledState();

    // Add the action and cancel buttons.
    //topLayout->addSpacing(10);
    QHBoxLayout *actionButtonLayout = new QHBoxLayout();
    topLayout->addLayout(actionButtonLayout);
    QPushButton *actionButton = new QPushButton(
        createMode?tr("Create database correlation") : tr("Alter database correlation"), central);
    connect(actionButton, SIGNAL(clicked()),
            this, SLOT(actionClicked()));
    actionButtonLayout->addWidget(actionButton);
    actionButtonLayout->addStretch(10);
    QPushButton *cancelButton = new QPushButton(tr("Cancel"), central);
    connect(cancelButton, SIGNAL(clicked()),
            this, SLOT(cancelClicked()));
    actionButtonLayout->addWidget(cancelButton);
}