// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void PipelineFilterWidget::layoutWidgets()
{
    // Make sure the m_Filter is Non NULL
    if (NULL == m_Filter.get())
    {
        return;
    }

    // If the filter is valid then instantiate all the FilterParameterWidgets
    // Create the Widget that will be placed into the Variables Scroll Area
    m_VariablesWidget = new QWidget(this);

    QString variablesName = QString::fromUtf8("variablesScrollWidget1_") + m_Filter->getNameOfClass();
    m_VariablesWidget->setObjectName(variablesName);
    m_VariablesWidget->setGeometry(QRect(0, 0, 250, 267));
    m_VariablesVerticalLayout = new QVBoxLayout(m_VariablesWidget);
    m_VariablesVerticalLayout->setSpacing(30);
    variablesName = QString::fromUtf8("verticalLayout1") + m_Filter->getNameOfClass();
    m_VariablesVerticalLayout->setObjectName(variablesName);

    QString groupBoxStyle;
    QTextStream ss(&groupBoxStyle);
    ss << "QGroupBox {";
    ss << "    font-weight: bold;";
    ss << "}";
    ss << "QGroupBox::title {";
    ss << "    subcontrol-origin: margin;";
    ss << "    subcontrol-position: top left;";
    ss << "    padding: 0 5px;";
    ss << "    font-weight: bold;";
    ss << "}";


    QGroupBox* parametersGroupBox = new QGroupBox("Parameters", this);
    QVBoxLayout* pLayout = new QVBoxLayout(parametersGroupBox);
    parametersGroupBox->setStyleSheet(groupBoxStyle);

    QGroupBox* requiredGroupBox = new QGroupBox("Required Objects", this);
    QVBoxLayout* rLayout = new QVBoxLayout(requiredGroupBox);
    requiredGroupBox->setStyleSheet(groupBoxStyle);

    QGroupBox* createdGroupBox = new QGroupBox("Created Objects", this);
    QVBoxLayout* cLayout = new QVBoxLayout(createdGroupBox);
    createdGroupBox->setStyleSheet(groupBoxStyle);

    QGroupBox* noCategoryGroupBox = new QGroupBox("Uncategorized", this);
    QVBoxLayout* nLayout = new QVBoxLayout(noCategoryGroupBox);
    noCategoryGroupBox->setStyleSheet(groupBoxStyle);

    // Set the Name of the filter into the FilterWidget
    filterName->setText(m_Filter->getHumanLabel() );

    // Get the FilterWidgetManagere instance so we can instantiate new FilterParameterWidgets
    FilterWidgetManager* fwm = FilterWidgetManager::Instance();
    // Get a list of all the filterParameters from the filter.
    QVector<FilterParameter::Pointer> filterParameters = m_Filter->getFilterParameters();
    // Create all the FilterParameterWidget objects that can be displayed where ever the developer needs

    int pCount = 0, rCount = 0, cCount = 0;
    for (QVector<FilterParameter::Pointer>::iterator iter = filterParameters.begin(); iter != filterParameters.end(); ++iter )
    {
        FilterParameter* parameter = (*iter).get();

        // Check to make sure that this is in fact a file system filter parameter
        if (NULL != dynamic_cast<InputFileFilterParameter*>(parameter) || NULL != dynamic_cast<InputPathFilterParameter*>(parameter) || NULL != dynamic_cast<DataContainerReaderFilterParameter*>(parameter))
        {
            validateFileSystemFilterParameter(parameter);
        }

        QWidget* filterParameterWidget = fwm->createWidget(parameter, m_Filter.get());
        m_PropertyToWidget.insert(parameter->getPropertyName(), filterParameterWidget); // Update our Map of Filter Parameter Properties to the Widget

        if (NULL == filterParameterWidget)
        {
            continue;
        }
        m_FilterParameterWidgets.push_back(filterParameterWidget);

        // Determine which group box to add the widget into
        if(parameter->getCategory() == FilterParameter::Parameter)
        {
            filterParameterWidget->setParent(m_VariablesWidget);
            pLayout->addWidget(filterParameterWidget);
            pCount++;
        }
        else if(parameter->getCategory() == FilterParameter::RequiredArray)
        {
            filterParameterWidget->setParent(m_VariablesWidget);
            rLayout->addWidget(filterParameterWidget);
            rCount++;
        }
        else if(parameter->getCategory() == FilterParameter::CreatedArray)
        {
            filterParameterWidget->setParent(m_VariablesWidget);
            cLayout->addWidget(filterParameterWidget);
            cCount++;
        }
        else
        {
            filterParameterWidget->setParent(m_VariablesWidget);
            nLayout->addWidget(filterParameterWidget);
        }

        // Connect up some signals and slots
        connect(filterParameterWidget, SIGNAL(parametersChanged() ),
                parent(), SLOT(preflightPipeline() ) );

        connect(filterParameterWidget, SIGNAL(parametersChanged() ),
                parent(), SLOT(handleFilterParameterChanged() ) );

        connect(filterParameterWidget, SIGNAL(errorSettingFilterParameter(const QString&)),
                this, SLOT(displayFilterParameterWidgetError(const QString&)));

    }

    // Now link any boolean widgets to any conditional Widgets that they might control.
    linkConditionalWidgets(filterParameters);

    // If there are widgets in the parameters group box, add it to the overall layout.  If not, remove the group box.
    if (pLayout->isEmpty() == false || pCount > 0)
    {
        m_VariablesVerticalLayout->addWidget(parametersGroupBox);
    }
    else
    {
        delete parametersGroupBox;
    }

    // If there are widgets in the required arrays group box, add it to the overall layout.  If not, remove the group box.
    if (rLayout->isEmpty() == false || rCount > 0)
    {
        m_VariablesVerticalLayout->addWidget(requiredGroupBox);
    }
    else
    {
        delete requiredGroupBox;
    }

    // If there are widgets in the created arrays group box, add it to the overall layout.  If not, remove the group box.
    if (cLayout->isEmpty() == false || cCount > 0)
    {
        m_VariablesVerticalLayout->addWidget(createdGroupBox);
    }
    else
    {
        delete createdGroupBox;
    }

    // If there are widgets in the uncategorized group box, add it to the overall layout.  If not, remove the group box.
    if (nLayout->isEmpty() == false)
    {
        m_VariablesVerticalLayout->addWidget(noCategoryGroupBox);
    }
    else
    {
        delete noCategoryGroupBox;
    }

    // Now layout the Current Structure widget
    m_CurrentStructureWidget = new DataContainerArrayWidget(m_Filter.get(), this);
    QString curStructName = QString::fromUtf8("advancedInputsScrollWidget_CurrStructWidget");
    m_CurrentStructureWidget->setObjectName(curStructName);
    m_CurrentStructureWidget->setGeometry(QRect(0, 0, 250, 267));
}