void PreviewWidget::setCurrentFile(const QString& filename) { // Always clear the current file even if the filename is the same as the current filename // to ensure that the previous and next dataset buttons are enabled properly mCurrentFile.clear(); // Activate the label indicating that no preview is available mpStack->setCurrentIndex(0); // Get a data set to activate ImportDescriptor* pDataset = NULL; if (filename.isEmpty() == false) { // Do not update the preview if the file does not exist in the map QMap<QString, vector<ImportDescriptor*> >::iterator iter = mDatasets.find(filename); if (iter != mDatasets.end()) { mCurrentFile = filename; // Activate the file widget mpStack->setCurrentIndex(1); // Update the file label updateFileNumber(); // Activate the label indicating that no file preview is available mpFileStack->setCurrentIndex(0); // Update the preview with the first imported data set in the file unsigned int numImportedDatasets = 0; vector<ImportDescriptor*> fileDatasets = iter.value(); for (vector<ImportDescriptor*>::iterator datasetIter = fileDatasets.begin(); datasetIter != fileDatasets.end(); ++datasetIter) { ImportDescriptor* pCurrentDataset = *datasetIter; if ((pCurrentDataset != NULL) && (pCurrentDataset->isImported() == true)) { if (pDataset == NULL) { pDataset = pCurrentDataset; } ++numImportedDatasets; // Activate the data set widget mpFileStack->setCurrentIndex(1); } } // Enable the data set buttons mpPreviousDatasetButton->setEnabled(numImportedDatasets > 1); mpNextDatasetButton->setEnabled(numImportedDatasets > 1); } } setCurrentDataset(pDataset); }
void PreviewWidget::displayPreviousDataset() { // Get the descriptor of the previous imported data set in the vector ImportDescriptor* pCurrentDataset = getCurrentDataset(); ImportDescriptor* pPreviousDataset = NULL; ImportDescriptor* pLastDataset = NULL; bool bNextDataset = (pCurrentDataset == NULL); QMap<QString, vector<ImportDescriptor*> >::iterator fileIter = mDatasets.find(mCurrentFile); VERIFYNRV(fileIter != mDatasets.end()); vector<ImportDescriptor*> fileDatasets = fileIter.value(); vector<ImportDescriptor*>::reverse_iterator iter; for (iter = fileDatasets.rbegin(); iter != fileDatasets.rend(); ++iter) { ImportDescriptor* pDataset = *iter; if ((pDataset != NULL) && (pDataset->isImported() == true)) { if (pLastDataset == NULL) { pLastDataset = pDataset; } if (bNextDataset == true) { pPreviousDataset = pDataset; break; } if (pDataset == pCurrentDataset) { bNextDataset = true; } } } // The previous imported data set was not found so cycle around to the last imported data set if (pPreviousDataset == NULL) { pPreviousDataset = pLastDataset; } // Update the active data set setCurrentDataset(pPreviousDataset); }
ImportOptionsDlg::ImportOptionsDlg(Importer* pImporter, const QMap<QString, vector<ImportDescriptor*> >& files, QWidget* pParent) : QDialog(pParent), mpImporter(pImporter), mpCurrentDataset(NULL), mpEditDescriptor(NULL), mEditDataDescriptorModified(false), mPromptForChanges(true), mAllowDeselectedFiles(true), mpDatasetTree(NULL), mpClassificationLabel(NULL), mpTabWidget(NULL), mpDataPage(NULL), mpFilePage(NULL), mpClassificationPage(NULL), mpSubsetPage(NULL), mpMetadataPage(NULL), mpWavelengthsPage(NULL), mpImporterPage(NULL), mpValidationLabel(NULL) { QSplitter* pSplitter = new QSplitter(this); // Dataset list QWidget* pDatasetWidget = new QWidget(pSplitter); QLabel* pDatasetLabel = new QLabel("Data Sets:", pDatasetWidget); mpDatasetTree = new QTreeWidget(pDatasetWidget); mpDatasetTree->setSelectionMode(QAbstractItemView::SingleSelection); mpDatasetTree->setSelectionBehavior(QAbstractItemView::SelectItems); mpDatasetTree->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); mpDatasetTree->setTextElideMode(Qt::ElideLeft); mpDatasetTree->setMinimumWidth(225); mpDatasetTree->setHeaderHidden(true); QPushButton* pImportAllButton = new QPushButton("Import All", pDatasetWidget); QPushButton* pImportNoneButton = new QPushButton("Import None", pDatasetWidget); // Classification label QWidget* pInfoWidget = new QWidget(pSplitter); QFont labelFont = font(); labelFont.setBold(true); mpClassificationLabel = new QLabel(pInfoWidget); mpClassificationLabel->setFont(labelFont); mpClassificationLabel->setAlignment(Qt::AlignCenter); // Tab widget mpTabWidget = new QTabWidget(pInfoWidget); mpDataPage = new DataDescriptorWidget(); mpFilePage = new FileDescriptorWidget(); mpClassificationPage = new ClassificationWidget(); mpSubsetPage = new SubsetWidget(); mpMetadataPage = new MetadataWidget(); mpWavelengthsPage = new WavelengthsWidget(); mpTabWidget->addTab(mpDataPage, "Data"); mpTabWidget->addTab(mpFilePage, "File"); mpTabWidget->addTab(mpClassificationPage, "Classification"); mpTabWidget->addTab(mpSubsetPage, "Subset"); mpTabWidget->addTab(mpMetadataPage, "Metadata"); // Validation label mpValidationLabel = new QLabel(this); mpValidationLabel->setWordWrap(true); QFont validationFont = mpValidationLabel->font(); validationFont.setBold(true); mpValidationLabel->setFont(validationFont); // Dialog buttons mpOkButton = new QPushButton("&OK", this); QPushButton* pCancelButton = new QPushButton("&Cancel", this); // Layout QLayout* pDataLayout = mpDataPage->layout(); if (pDataLayout != NULL) { pDataLayout->setMargin(10); } QLayout* pFileLayout = mpFilePage->layout(); if (pFileLayout != NULL) { pFileLayout->setMargin(10); } QLayout* pClassificationLayout = mpClassificationPage->layout(); if (pClassificationLayout != NULL) { pClassificationLayout->setMargin(10); } QLayout* pSubsetLayout = mpSubsetPage->layout(); if (pSubsetLayout != NULL) { pSubsetLayout->setMargin(10); } QLayout* pMetadataLayout = mpMetadataPage->layout(); if (pMetadataLayout != NULL) { pMetadataLayout->setMargin(10); } QLayout* pWavelengthsLayout = mpWavelengthsPage->layout(); if (pWavelengthsLayout != NULL) { pWavelengthsLayout->setMargin(10); } QGridLayout* pDatasetLayout = new QGridLayout(pDatasetWidget); pDatasetLayout->setMargin(0); pDatasetLayout->setSpacing(5); pDatasetLayout->addWidget(pDatasetLabel, 0, 0, 1, 2); pDatasetLayout->addWidget(mpDatasetTree, 1, 0, 1, 2); pDatasetLayout->addWidget(pImportAllButton, 2, 0, Qt::AlignRight); pDatasetLayout->addWidget(pImportNoneButton, 2, 1); pDatasetLayout->setRowStretch(1, 10); pDatasetLayout->setColumnStretch(0, 10); QVBoxLayout* pInfoLayout = new QVBoxLayout(pInfoWidget); pInfoLayout->setMargin(0); pInfoLayout->setSpacing(10); pInfoLayout->addWidget(mpClassificationLabel); pInfoLayout->addWidget(mpTabWidget, 10); QHBoxLayout* pButtonLayout = new QHBoxLayout(); pButtonLayout->setMargin(0); pButtonLayout->setSpacing(5); pButtonLayout->addWidget(mpValidationLabel, 10); pButtonLayout->addWidget(mpOkButton, 0, Qt::AlignBottom); pButtonLayout->addWidget(pCancelButton, 0, Qt::AlignBottom); QVBoxLayout* pVBox = new QVBoxLayout(this); pVBox->setMargin(10); pVBox->setSpacing(10); pVBox->addWidget(pSplitter, 10); pVBox->addLayout(pButtonLayout); // Initialization setWindowTitle("Import Options"); setModal(true); resize(700, 450); pSplitter->addWidget(pDatasetWidget); pSplitter->addWidget(pInfoWidget); // Populate the data set tree widget QTreeWidgetItem* pSelectItem = NULL; QMap<QString, vector<ImportDescriptor*> >::const_iterator fileIter; for (fileIter = files.begin(); fileIter != files.end(); ++fileIter) { // Filename item QString filename = fileIter.key(); if (filename.isEmpty() == true) { continue; } QTreeWidgetItem* pFileItem = new QTreeWidgetItem(mpDatasetTree); QFileInfo fileInfo(filename); pFileItem->setText(0, fileInfo.fileName()); pFileItem->setIcon(0, style()->standardIcon(QStyle::SP_FileIcon)); pFileItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); pFileItem->setToolTip(0, filename); pFileItem->setCheckState(0, Qt::Unchecked); // Dataset items vector<ImportDescriptor*> fileDatasets = fileIter.value(); vector<ImportDescriptor*> datasets; copy(fileDatasets.begin(), fileDatasets.end(), back_inserter(datasets)); stable_sort(datasets.begin(), datasets.end(), ElementDepthComparitor()); map<vector<string>, QTreeWidgetItem*> parentPaths; vector<ImportDescriptor*>::iterator datasetIter; for (datasetIter = datasets.begin(); datasetIter != datasets.end(); ++datasetIter) { ImportDescriptor* pImportDescriptor = *datasetIter; if (pImportDescriptor == NULL) { continue; } DataDescriptor* pDescriptor = pImportDescriptor->getDataDescriptor(); if (pDescriptor == NULL) { continue; } const string& name = pDescriptor->getName(); if (name.empty()) { continue; } QTreeWidgetItem* pItem = new QTreeWidgetItem(static_cast<QTreeWidget*>(NULL), QStringList() << QString::fromStdString(name)); if (pItem == NULL) { continue; } // Tool tip pItem->setToolTip(0, QString::fromStdString(name)); // Check state Qt::ItemFlags itemFlags = pItem->flags(); itemFlags |= Qt::ItemIsUserCheckable; pItem->setFlags(itemFlags); if (pImportDescriptor->isImported()) { pItem->setCheckState(0, Qt::Checked); if (pSelectItem == NULL) { pSelectItem = pItem; } } else { pItem->setCheckState(0, Qt::Unchecked); } // Add to the proper parent map<vector<string>, QTreeWidgetItem*>::iterator parent = parentPaths.find(pDescriptor->getParentDesignator()); if (parent != parentPaths.end()) { parent->second->addChild(pItem); } else { pFileItem->addChild(pItem); } vector<string> myDesignator = pDescriptor->getParentDesignator(); myDesignator.push_back(pDescriptor->getName()); parentPaths[myDesignator] = pItem; mDatasets[pImportDescriptor] = pItem; validateDataset(pDescriptor); enforceSelections(pItem); } } mpDatasetTree->expandAll(); // Update the tab widget for the selected data set if (pSelectItem == NULL) { // No data set is set to import by default so select the first data set in the tree widget for (int i = 0; i < mpDatasetTree->topLevelItemCount() && pSelectItem == NULL; ++i) { QTreeWidgetItem* pParentItem = mpDatasetTree->topLevelItem(i); if ((pParentItem != NULL) && (pParentItem->childCount() > 0)) { pSelectItem = pParentItem->child(0); } } } if (pSelectItem != NULL) { mpDatasetTree->setItemSelected(pSelectItem, true); updateEditDataset(); } // Connections VERIFYNR(connect(mpDatasetTree, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(datasetItemChanged(QTreeWidgetItem*)))); VERIFYNR(connect(mpDatasetTree, SIGNAL(itemSelectionChanged()), this, SLOT(updateEditDataset()))); VERIFYNR(connect(pImportAllButton, SIGNAL(clicked()), this, SLOT(selectAllDatasets()))); VERIFYNR(connect(pImportNoneButton, SIGNAL(clicked()), this, SLOT(deselectAllDatasets()))); VERIFYNR(connect(mpOkButton, SIGNAL(clicked()), this, SLOT(accept()))); VERIFYNR(connect(pCancelButton, SIGNAL(clicked()), this, SLOT(reject()))); updateConnections(true); }