Example #1
0
void PlugInModel::removePlugIn(Subject& subject, const string& signal, const boost::any& value)
{
   PlugIn* pPlugIn = boost::any_cast<PlugIn*>(value);

   SessionItem* pItem = dynamic_cast<SessionItem*>(pPlugIn);
   if (pItem != NULL)
   {
      string plugInName = pItem->getName();

      PlugInDescriptor* pDescriptor = mpManager->getPlugInDescriptor(plugInName);
      if (pDescriptor != NULL)
      {
         SessionItemWrapper* pDescriptorWrapper = getWrapper(pDescriptor);
         if (pDescriptorWrapper != NULL)
         {
            pDescriptorWrapper->removeChild(pItem);
         }
      }
   }
}
Example #2
0
ExportOptionsDlg::ExportOptionsDlg(ExporterResource& pExporter, QWidget* pParent) :
   QDialog(pParent),
   mpExporter(pExporter),
   mpTabWidget(NULL),
   mpSubsetPage(NULL),
   mpExporterPage(NULL)
{
   // Options widget
   QStackedWidget* pStack = new QStackedWidget(this);

   // Subset page
   RasterElement* pRasterElement = dynamic_cast<RasterElement*>(mpExporter->getItem());
   RasterFileDescriptor* pRasterWholeCubeFileDescriptor = NULL;
   RasterDataDescriptor* pRasterOrgDataDescriptor = NULL;
   if (pRasterElement != NULL)
   {
      pRasterOrgDataDescriptor = dynamic_cast<RasterDataDescriptor*>(pRasterElement->getDataDescriptor());
      if (pRasterOrgDataDescriptor != NULL)
      {
         // we are creating a file descriptor for export from the original cube, because the SubsetWidget
         // uses DimensionDescriptor::operator= compare's to determine selection which dictate that on-disk,
         // original and active numbers need to be identical, this guarantees that DimensionDescriptors will
         // compare correctly.
         pRasterWholeCubeFileDescriptor = dynamic_cast<RasterFileDescriptor*>(
            RasterUtilities::generateFileDescriptorForExport(pRasterOrgDataDescriptor, "foobar"));
      }
   }
   RasterFileDescriptor* pRasterFileDescriptor = dynamic_cast<RasterFileDescriptor*>(mpExporter->getFileDescriptor());
   if ((pRasterFileDescriptor != NULL) && (pRasterWholeCubeFileDescriptor != NULL) &&
      (pRasterOrgDataDescriptor != NULL))
   {
      mpSubsetPage = new SubsetWidget();
      mpSubsetPage->setExportMode(true);

      // Rows
      const vector<DimensionDescriptor>& orgRows = pRasterWholeCubeFileDescriptor->getRows();
      const vector<DimensionDescriptor>& selectedRows = pRasterFileDescriptor->getRows();
      mpSubsetPage->setRows(orgRows, selectedRows);

      // Columns
      const vector<DimensionDescriptor>& orgColumns = pRasterWholeCubeFileDescriptor->getColumns();
      const vector<DimensionDescriptor>& selectedColumns = pRasterFileDescriptor->getColumns();
      mpSubsetPage->setColumns(orgColumns, selectedColumns);

      // Bands
      const vector<DimensionDescriptor>& orgBands = pRasterWholeCubeFileDescriptor->getBands();
      const vector<DimensionDescriptor>& selectedBands = pRasterFileDescriptor->getBands();
      vector<string> bandNames = RasterUtilities::getBandNames(pRasterOrgDataDescriptor);
      mpSubsetPage->setBands(orgBands, bandNames, selectedBands);

      // Initial bad band file directory
      QString strDirectory;

      string filename = pRasterFileDescriptor->getFilename();
      if (filename.empty() == false)
      {
         QFileInfo fileInfo(QString::fromStdString(filename));
         strDirectory = fileInfo.absolutePath();
      }

      mpSubsetPage->setBadBandFileDirectory(strDirectory);
   }

   // Exporter page
   if (mpExporter->getPlugIn() != NULL)
   {
      mpExporterPage = mpExporter->getExportOptionsWidget();
   }

   // Horizontal line
   QFrame* pLine = new QFrame(this);
   pLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);

   // Buttons
   QDialogButtonBox* pButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
      Qt::Horizontal, this);

   // Layout
   QVBoxLayout* pLayout = new QVBoxLayout(this);
   pLayout->setMargin(10);
   pLayout->setSpacing(10);
   pLayout->addWidget(pStack, 10);
   pLayout->addWidget(pLine);
   pLayout->addWidget(pButtonBox);

   // Initialization
   QString strWindowTitle = "Export Options";

   SessionItem* pSessionItem = mpExporter->getItem();
   if (pSessionItem != NULL)
   {
      string name = pSessionItem->getDisplayName();
      if (name.empty() == true)
      {
         name = pSessionItem->getName();
      }

      if (name.empty() == false)
      {
         strWindowTitle += ": " + QString::fromStdString(name);
      }
   }

   setWindowTitle(strWindowTitle);
   setModal(true);

   if ((mpSubsetPage != NULL) || (mpExporterPage != NULL))
   {
      QWidget* pSubsetWidget = NULL;
      if (mpSubsetPage != NULL)
      {
         pSubsetWidget = new QWidget();
         mpSubsetPage->setParent(pSubsetWidget);

         QVBoxLayout* pSubsetLayout = new QVBoxLayout(pSubsetWidget);
         if (mpExporterPage != NULL)
         {
            pSubsetLayout->setMargin(10);
         }
         else
         {
            pSubsetLayout->setMargin(0);
         }

         pSubsetLayout->setSpacing(10);
         pSubsetLayout->addWidget(mpSubsetPage);
      }

      QWidget* pExporterWidget = NULL;
      if (mpExporterPage != NULL)
      {
         pExporterWidget = new QWidget();
         mpExporterPage->setParent(pExporterWidget);

         QVBoxLayout* pExporterLayout = new QVBoxLayout(pExporterWidget);
         if (mpSubsetPage != NULL)
         {
            pExporterLayout->setMargin(10);
         }
         else
         {
            pExporterLayout->setMargin(0);
         }

         pExporterLayout->setSpacing(10);
         pExporterLayout->addWidget(mpExporterPage);
      }

      if ((pSubsetWidget != NULL) && (pExporterWidget != NULL))
      {
         QString strExporterCaption = mpExporterPage->windowTitle();
         if (strExporterCaption.isEmpty() == true)
         {
            PlugIn* pPlugIn = mpExporter->getPlugIn();
            if (pPlugIn != NULL)
            {
               strExporterCaption = QString::fromStdString(pPlugIn->getName());
            }

            if (strExporterCaption.isEmpty() == true)
            {
               strExporterCaption = "Exporter";
            }
         }

         mpTabWidget = new QTabWidget(this);
         mpTabWidget->setTabPosition(QTabWidget::North);
         mpTabWidget->addTab(pSubsetWidget, "Subset");
         mpTabWidget->addTab(pExporterWidget, strExporterCaption);
         pStack->addWidget(mpTabWidget);
      }
      else if (pSubsetWidget != NULL)
      {
         pStack->addWidget(pSubsetWidget);
         pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
      }
      else if (pExporterWidget != NULL)
      {
         pStack->addWidget(pExporterWidget);
      }
   }

   if (pStack->count() == 0)
   {
      QLabel* pNoOptionsLabel = new QLabel("No options are available", this);
      pNoOptionsLabel->setAlignment(Qt::AlignCenter);
      pNoOptionsLabel->setMinimumSize(250, 100);

      pStack->addWidget(pNoOptionsLabel);
   }

   // Connections
   VERIFYNR(connect(pButtonBox, SIGNAL(accepted()), this, SLOT(accept())));
   VERIFYNR(connect(pButtonBox, SIGNAL(rejected()), this, SLOT(reject())));
}
QVariant SessionItemModel::data(const QModelIndex& index, int role) const
{
   if (index.isValid() == false)
   {
      return QVariant();
   }

   SessionItemWrapper* pWrapper = reinterpret_cast<SessionItemWrapper*>(index.internalPointer());
   if (pWrapper != NULL)
   {
      SessionItem* pItem = pWrapper->getSessionItem();
      if (role == Qt::CheckStateRole)
      {
         if (flags(index) & Qt::ItemIsUserCheckable)
         {
            Qt::CheckState checkState = pWrapper->getCheckState();
            return QVariant(checkState);
         }
      }
      else if (role == Qt::DecorationRole)
      {
         if (pItem != NULL)
         {
            const QIcon& itemIcon = pItem->getIcon();
            return QVariant(itemIcon);
         }
      }
      else if (role == Qt::DisplayRole || role == Qt::EditRole)
      {
         QString strItemName = pWrapper->getDisplayName();
         if ((strItemName.isEmpty() == true) && (pItem != NULL))
         {
            string itemName = pItem->getDisplayName();
            if (itemName.empty() == true)
            {
               itemName = pItem->getName();
            }

            strItemName = QString::fromStdString(itemName);
         }

         if (strItemName.isEmpty() == false)
         {
            return QVariant(strItemName);
         }
      }
      else if (role == Qt::FontRole)
      {
         QFont itemFont = pWrapper->getDisplayFont();
         return QVariant(itemFont);
      }
      else if (role == Qt::ForegroundRole)
      {
         QColor itemColor = pWrapper->getDisplayColor();
         return QVariant(itemColor);
      }
      else if (role == Qt::BackgroundRole)
      {
         QColor itemColor = pWrapper->getBackgroundColor();
         return QVariant(itemColor);
      }
      else if (role == Qt::ToolTipRole)
      {
         if (pItem != NULL)
         {
            const string& displayText = pItem->getDisplayText();
            if (displayText.empty() == false)
            {
               return QVariant(QString::fromStdString(displayText));
            }
         }
      }
      else if (role == SessionItemModel::SessionItemRole)
      {
         return QVariant::fromValue(pItem);
      }
   }

   return QVariant();
}
Example #4
0
ExportDlg::ExportDlg(ExporterResource& pExporter,
                     const vector<PlugInDescriptor*>& availablePlugins,
                     QWidget* pParent) :
   FilePlugInDlg(availablePlugins, ConfigurationSettings::getSettingPluginWorkingDirectoryKey("Exporter"), pParent),
   mpExporter(pExporter),
   mValidated(false)
{
   // Initializtion
   setWindowTitle("Export");
   setFileMode(QFileDialog::AnyFile);
   setAcceptMode(QFileDialog::AcceptSave);
   setConfirmOverwrite(true);
   setLabelText(QFileDialog::LookIn, "Save in:");
   setPlugInLabel("Exporter");
   enableOptions(true);

   // Set the initial directory
   Service<ConfigurationSettings> pSettings;
   const Filename* pWorkingDir = pSettings->getSetting(
      ConfigurationSettings::getSettingPluginWorkingDirectoryKey("Exporter")).getPointerToValue<Filename>();
   if (pWorkingDir == NULL)
   {
      pWorkingDir = ConfigurationSettings::getSettingExportPath();
   }

   string directory;
   if (pWorkingDir != NULL)
   {
      directory = pWorkingDir->getFullPathAndName();
   }

   if (!directory.empty())
   {
      setDirectory(QString::fromStdString(directory));
   }

   if (isDefaultPlugIn())
   {
      setSelectedPlugIn("Ice Exporter");
   }
   updateFromExporter(getSelectedPlugIn());

   // Set the initially selected file
   QString strFilename;

   SessionItem* pSessionItem = mpExporter->getItem();
   if (pSessionItem != NULL)
   {
      DataElement* pDataElement = dynamic_cast<DataElement*>(pSessionItem);
      if (pDataElement != NULL)
      {
         strFilename = QString::fromStdString(pDataElement->getFilename());
      }

      if (strFilename.isEmpty() == true)
      {
         strFilename = QString::fromStdString(pSessionItem->getName());
      }

      strFilename = updateExtension(strFilename);
      selectFile(strFilename);
   }

   updateFromFile(strFilename);

   // Connections
   VERIFYNR(connect(this, SIGNAL(plugInSelected(const QString&)), this, SLOT(updateFromExporter(const QString&))));
   VERIFYNR(connect(this, SIGNAL(optionsClicked()), this, SLOT(invokeOptionsDialog())));
}