diff --git a/src/translations/Dyt_zh_CN.ts b/src/translations/Dyt_zh_CN.ts index ed070fcc..bbabbc89 100644 --- a/src/translations/Dyt_zh_CN.ts +++ b/src/translations/Dyt_zh_CN.ts @@ -2,90 +2,576 @@ - AddFileDlg + AddCurveFileDlg - - Add File to Workspace + + Add Curve Data File - - File Path + + File Selection - - Select file to add... + + File Path: - + + Select curve data file... + + + + ... - - File Type - - - - - Curve Data - - - - - Surface Data - - - - - Table Data - - - - - Light Data - - - - - File Information - - - - + File Name: - - + + - - + File Size: - + + Chart Properties + + + + + Chart Name: + + + + + Enter chart name... + + + + + X Axis Title: + + + + + Enter X axis title... + + + + + Y Axis Title: + + + + + Enter Y axis title... + + + + + Time Parameter: + + + + + Axis Range Settings + + + + + X Min: + + + + + X Max: + + + + + Y Min: + + + + + Y Max: + + + + + X Tick Count: + + + + + Curve Name: + + + + + Chart 1 + + + + + Curve Management + + + + + Curves: + + + + + Add Curve + + + + + Remove + + + + + Selected Curve Properties + + + + + Enter curve name... + + + + + Curve Color: + + + + + Select Color + + + + + background-color: rgb(255, 0, 0); border: 1px solid black; + + + + + Data Start: + + + + + Data Stop: + + + + + Data Format Parameters + + + + + X Column: + + + + + Y Column: + + + + + Separator: + + + + + Comma (,) + + + + + Tab + + + + + Space + + + + + Semicolon (;) + + + + + File has header row + + + + Description (Optional) - + Enter file description... - + Add File - + + Cancel + + + + + Curve %1 + + + + + + + + + + + + + + + + + + + + + + + + + + + Validation Error + + + + + Please select a data file. + + + + + Selected file does not exist. + + + + + Selected file is not readable. Please check file permissions. + + + + + File is too large (over 100MB). Please select a smaller file. + + + + + At least one curve must be defined. + + + + + Curve %1 name cannot be empty. + + + + + Curve name '%1' is duplicated. Please use different names. + + + + + Curve name '%1' is too long. Please limit to 50 characters. + + + + + Curve '%1' start and stop values must be greater than 0. + + + + + Curve '%1' start value cannot be greater than stop value. + + + + + Curve '%1' data range is too small. At least 2 data points are required. + + + + + Curve '%1' stop value is too large. Please ensure it does not exceed 1000000. + + + + + Chart name cannot be empty. + + + + + Chart name is too long. Please limit to 100 characters. + + + + + X axis title is too long. Please limit to 50 characters. + + + + + Y axis title is too long. Please limit to 50 characters. + + + + + X axis minimum value must be less than maximum value. + + + + + Y axis minimum value must be less than maximum value. + + + + + X column and Y column cannot be the same. + + + + + Data column indices must be greater than 0. + + + + + Time parameter cannot be negative. + + + + + X axis tick count must be at least 2. + + + + + Description is too long. Please limit to 500 characters. + + + + + AddLightFileDlg + + + Add Light Spectrum File + + + + + File Selection + + + + + File Path: + + + + + Select light spectrum file... + + + + + ... + + + + + File Name: + + + + + + - + + + + + File Size: + + + + + Spectrum Parameters + + + + + Wavelength Column: + + + + + Intensity Column: + + + + + Separator: + + + + + Comma (,) + + + + + Tab + + + + + Space + + + + + Semicolon (;) + + + + + Wavelength Unit: + + + + + nm (nanometer) + + + + + μm (micrometer) + + + + + cm⁻¹ (wavenumber) + + + + + eV (electron volt) + + + + + Intensity Unit: + + + + + Arbitrary Units + + + + + Counts + + + + + W/m²/nm + + + + + μW/cm²/nm + + + + + File has header row + + + + + Normalize intensity values + + + + + Wavelength Range (Optional) + + + + + Min Wavelength: + + + + + Max Wavelength: + + + + + Enable wavelength range filtering + + + + + Description (Optional) + + + + + Enter file description... + + + + + Add File + + + + Cancel @@ -176,6 +662,269 @@ + + AddSurfaceFileDlg + + + Add Surface Data File + + + + + File Selection + + + + + File Path: + + + + + Select surface data file... + + + + + ... + + + + + File Name: + + + + + + - + + + + + File Size: + + + + + Surface Parameters + + + + + X Column: + + + + + Y Column: + + + + + Z Column: + + + + + Separator: + + + + + Comma (,) + + + + + Tab + + + + + Space + + + + + Semicolon (;) + + + + + X Grid Size: + + + + + Y Grid Size: + + + + + File has header row + + + + + Description (Optional) + + + + + Enter file description... + + + + + Add File + + + + + Cancel + + + + + AddTableFileDlg + + + Add Table Data File + + + + + File Selection + + + + + File Path: + + + + + Select table data file... + + + + + ... + + + + + File Name: + + + + + + - + + + + + File Size: + + + + + Table Parameters + + + + + Separator: + + + + + Comma (,) + + + + + Tab + + + + + Space + + + + + Semicolon (;) + + + + + Encoding: + + + + + UTF-8 + + + + + GBK + + + + + ASCII + + + + + ISO-8859-1 + + + + + Skip Rows: + + + + + File has header row + + + + + Auto-detect parameters + + + + + Preview + + + + + Description (Optional) + + + + + Enter file description... + + + + + Add File + + + + + Cancel + + + ChartPlotMenuClass @@ -978,90 +1727,88 @@ - + Open Workspace - - + + Dyt Files (*.dyt) - - - - - - - - - - + + + + + + + - - + - - - - - + + - + + + + prompt - - - - + + + - + please create workspace first - + Save Workspace - + + + + Error - + + + + Failed to set file path - - - - - + + + + up to 9 files allowed for this type - - - - - + + + + file already added for this type - - - - - + + + + copy file failed diff --git a/src/ui/Menu/FileManagerMenu.cpp b/src/ui/Menu/FileManagerMenu.cpp index a0b4f18e..b10caebb 100644 --- a/src/ui/Menu/FileManagerMenu.cpp +++ b/src/ui/Menu/FileManagerMenu.cpp @@ -8,7 +8,8 @@ #include "ui/MainFrame.h" #include "ui/WorkSpace/WorkSpaceDlg.h" -#include "ui/WorkSpace/AddFileDlg.h" +#include "ui/WorkSpace/AddFileDialogFactory.h" +#include "ui/WorkSpace/BaseAddFileDlg.h" #include "common/SpdLogger.h" #include "workspace/WorkSpace.h" @@ -81,28 +82,29 @@ void FileManagerMenu::SaveWorkSpace() { LOG_INFO("save workspace: {}", fileName.toLocal8Bit().constData()); } -void FileManagerMenu::AddFile() { +// Removed old AddFile method - replaced by specific type methods + +void FileManagerMenu::AddWaveFile() { auto current = WorkSpaceManager::Get().GetCurrent(); if (nullptr == current) { QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first")); return; } - // Show file addition dialog - AddFileDlg dlg(&MainFrame::Get()); - if (dlg.exec() == QDialog::Accepted) { - FileEntryType selectedType = dlg.getSelectedFileType(); - QString selectedPath = dlg.getSelectedFilePath(); + // Show curve file addition dialog + auto dialog = AddFileDialogFactory::createDialog(FileEntryType::Curve, &MainFrame::Get()); + if (dialog && dialog->exec() == QDialog::Accepted) { + QString selectedPath = dialog->getSelectedFilePath(); // Create file entry - switch (current->CreateFileEntry(selectedType)) { + switch (current->CreateFileEntry(FileEntryType::Curve)) { case WorkSpace::FileEntryResult::Ok: { // Get the index of the newly created file entry - auto entries = current->GetFileEntries(selectedType); + auto entries = current->GetFileEntries(FileEntryType::Curve); int newIndex = static_cast(entries.size()) - 1; // Set file path - if (!current->SetFileEntryPath(selectedType, newIndex, selectedPath)) { + if (!current->SetFileEntryPath(FileEntryType::Curve, newIndex, selectedPath)) { QMessageBox::warning(&MainFrame::Get(), QObject::tr("Error"), QObject::tr("Failed to set file path")); } @@ -124,28 +126,6 @@ void FileManagerMenu::AddFile() { } } -void FileManagerMenu::AddWaveFile() { - auto current = WorkSpaceManager::Get().GetCurrent(); - if (nullptr == current) { - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first")); - return; - } - - switch (current->CreateFileEntry(FileEntryType::Curve)) { - case WorkSpace::FileEntryResult::Ok: - break; - case WorkSpace::FileEntryResult::LimitExceeded: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("up to 9 files allowed for this type")); - break; - case WorkSpace::FileEntryResult::Duplicate: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("file already added for this type")); - break; - case WorkSpace::FileEntryResult::CopyFailed: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("copy file failed")); - break; - } -} - void FileManagerMenu::AddSurfaceFile() { auto current = WorkSpaceManager::Get().GetCurrent(); if (nullptr == current) { @@ -153,18 +133,38 @@ void FileManagerMenu::AddSurfaceFile() { return; } - switch (current->CreateFileEntry(FileEntryType::Surface)) { - case WorkSpace::FileEntryResult::Ok: - break; - case WorkSpace::FileEntryResult::LimitExceeded: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("up to 9 files allowed for this type")); - break; - case WorkSpace::FileEntryResult::Duplicate: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("file already added for this type")); - break; - case WorkSpace::FileEntryResult::CopyFailed: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("copy file failed")); - break; + // Show surface file addition dialog + auto dialog = AddFileDialogFactory::createDialog(FileEntryType::Surface, &MainFrame::Get()); + if (dialog && dialog->exec() == QDialog::Accepted) { + QString selectedPath = dialog->getSelectedFilePath(); + + // Create file entry + switch (current->CreateFileEntry(FileEntryType::Surface)) { + case WorkSpace::FileEntryResult::Ok: { + // Get the index of the newly created file entry + auto entries = current->GetFileEntries(FileEntryType::Surface); + int newIndex = static_cast(entries.size()) - 1; + + // Set file path + if (!current->SetFileEntryPath(FileEntryType::Surface, newIndex, selectedPath)) { + QMessageBox::warning(&MainFrame::Get(), QObject::tr("Error"), + QObject::tr("Failed to set file path")); + } + break; + } + case WorkSpace::FileEntryResult::LimitExceeded: + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), + QObject::tr("up to 9 files allowed for this type")); + break; + case WorkSpace::FileEntryResult::Duplicate: + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), + QObject::tr("file already added for this type")); + break; + case WorkSpace::FileEntryResult::CopyFailed: + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), + QObject::tr("copy file failed")); + break; + } } } @@ -174,18 +174,39 @@ void FileManagerMenu::AddTableFile() { QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("please create workspace first")); return; } - switch (current->CreateFileEntry(FileEntryType::Table)) { - case WorkSpace::FileEntryResult::Ok: - break; - case WorkSpace::FileEntryResult::LimitExceeded: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("up to 9 files allowed for this type")); - break; - case WorkSpace::FileEntryResult::Duplicate: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("file already added for this type")); - break; - case WorkSpace::FileEntryResult::CopyFailed: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("copy file failed")); - break; + + // Show table file addition dialog + auto dialog = AddFileDialogFactory::createDialog(FileEntryType::Table, &MainFrame::Get()); + if (dialog && dialog->exec() == QDialog::Accepted) { + QString selectedPath = dialog->getSelectedFilePath(); + + // Create file entry + switch (current->CreateFileEntry(FileEntryType::Table)) { + case WorkSpace::FileEntryResult::Ok: { + // Get the index of the newly created file entry + auto entries = current->GetFileEntries(FileEntryType::Table); + int newIndex = static_cast(entries.size()) - 1; + + // Set file path + if (!current->SetFileEntryPath(FileEntryType::Table, newIndex, selectedPath)) { + QMessageBox::warning(&MainFrame::Get(), QObject::tr("Error"), + QObject::tr("Failed to set file path")); + } + break; + } + case WorkSpace::FileEntryResult::LimitExceeded: + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), + QObject::tr("up to 9 files allowed for this type")); + break; + case WorkSpace::FileEntryResult::Duplicate: + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), + QObject::tr("file already added for this type")); + break; + case WorkSpace::FileEntryResult::CopyFailed: + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), + QObject::tr("copy file failed")); + break; + } } } @@ -196,17 +217,37 @@ void FileManagerMenu::AddLightFile() { return; } - switch (current->CreateFileEntry(FileEntryType::Light)) { - case WorkSpace::FileEntryResult::Ok: - break; - case WorkSpace::FileEntryResult::LimitExceeded: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("up to 9 files allowed for this type")); - break; - case WorkSpace::FileEntryResult::Duplicate: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("file already added for this type")); - break; - case WorkSpace::FileEntryResult::CopyFailed: - QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), QObject::tr("copy file failed")); - break; + // Show light file addition dialog + auto dialog = AddFileDialogFactory::createDialog(FileEntryType::Light, &MainFrame::Get()); + if (dialog && dialog->exec() == QDialog::Accepted) { + QString selectedPath = dialog->getSelectedFilePath(); + + // Create file entry + switch (current->CreateFileEntry(FileEntryType::Light)) { + case WorkSpace::FileEntryResult::Ok: { + // Get the index of the newly created file entry + auto entries = current->GetFileEntries(FileEntryType::Light); + int newIndex = static_cast(entries.size()) - 1; + + // Set file path + if (!current->SetFileEntryPath(FileEntryType::Light, newIndex, selectedPath)) { + QMessageBox::warning(&MainFrame::Get(), QObject::tr("Error"), + QObject::tr("Failed to set file path")); + } + break; + } + case WorkSpace::FileEntryResult::LimitExceeded: + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), + QObject::tr("up to 9 files allowed for this type")); + break; + case WorkSpace::FileEntryResult::Duplicate: + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), + QObject::tr("file already added for this type")); + break; + case WorkSpace::FileEntryResult::CopyFailed: + QMessageBox::information(&MainFrame::Get(), QObject::tr("prompt"), + QObject::tr("copy file failed")); + break; + } } } diff --git a/src/ui/Menu/FileManagerMenu.h b/src/ui/Menu/FileManagerMenu.h index 3924ffe1..da08123b 100644 --- a/src/ui/Menu/FileManagerMenu.h +++ b/src/ui/Menu/FileManagerMenu.h @@ -20,10 +20,7 @@ protected: void OpenWorkSpace(); void SaveWorkSpace(); - // New unified file addition method - void AddFile(); - - // Keep original methods for backward compatibility + // Type-specific file addition methods void AddWaveFile(); void AddSurfaceFile(); void AddTableFile(); diff --git a/src/ui/WorkSpace/AddCurveFileDlg.cpp b/src/ui/WorkSpace/AddCurveFileDlg.cpp new file mode 100644 index 00000000..a10e49f3 --- /dev/null +++ b/src/ui/WorkSpace/AddCurveFileDlg.cpp @@ -0,0 +1,552 @@ +#include "AddCurveFileDlg.h" + +#include +#include +#include +#include +#include + +#include "ui_AddCurveFileDlg.h" + +AddCurveFileDlg::AddCurveFileDlg(QWidget* parent) + : BaseAddFileDlg(FileEntryType::Curve, parent) + , ui(new Ui::AddCurveFileDlg) + , currentCurveIndex_(-1) + , selectedColor_(255, 0, 0) { // Default to red color + + SetupUI(ui); + SetTitle(getDialogTitle()); + setupSpecificUI(); + setupConnections(); +} + +AddCurveFileDlg::~AddCurveFileDlg() { + delete ui; +} + +void AddCurveFileDlg::setupSpecificUI() { + // Initialize curve properties group as disabled + enableCurveProperties(false); + + // Initialize color preview + updateColorPreview(selectedColor_); + + // Add a default curve + CurveProperties defaultCurve; + defaultCurve.name = generateCurveName(); + defaultCurve.color = generateCurveColor(); + defaultCurve.start = 1; + defaultCurve.stop = 241; + + curves_.append(defaultCurve); + addCurveToList(defaultCurve); + + // Select the first curve + if (ui->curveListWidget->count() > 0) { + ui->curveListWidget->setCurrentRow(0); + onCurveSelectionChanged(); + } +} + +void AddCurveFileDlg::setupConnections() { + // File selection connections + connect(ui->selectFileBtn, &QToolButton::clicked, this, &AddCurveFileDlg::onSelectFileClicked); + connect(ui->filePathEdit, &QLineEdit::textChanged, this, &AddCurveFileDlg::onFilePathChanged); + + // Data format connections + connect(ui->separatorComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &AddCurveFileDlg::onDelimiterChanged); + connect(ui->hasHeaderCheckBox, &QCheckBox::toggled, this, &AddCurveFileDlg::onHeaderToggled); + + // Curve management connections + connect(ui->addCurveBtn, &QPushButton::clicked, this, &AddCurveFileDlg::onAddCurveClicked); + connect(ui->removeCurveBtn, &QPushButton::clicked, this, &AddCurveFileDlg::onRemoveCurveClicked); + connect(ui->curveListWidget, &QListWidget::currentRowChanged, this, &AddCurveFileDlg::onCurveSelectionChanged); + + // Curve properties connections + connect(ui->colorButton, &QPushButton::clicked, this, &AddCurveFileDlg::onColorButtonClicked); + connect(ui->curveNameEdit, &QLineEdit::textChanged, this, &AddCurveFileDlg::onCurveNameChanged); + connect(ui->dataStartSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &AddCurveFileDlg::onCurveDataChanged); + connect(ui->dataStopSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &AddCurveFileDlg::onCurveDataChanged); + + // Dialog buttons + connect(ui->addBtn, &QPushButton::clicked, this, &AddCurveFileDlg::onSure); + connect(ui->cancelBtn, &QPushButton::clicked, this, &QDialog::reject); +} + +void AddCurveFileDlg::onSelectFileClicked() { + QString fileName = QFileDialog::getOpenFileName( + this, + getDialogTitle(), + QString(), + getFileFilter() + ); + + if (!fileName.isEmpty()) { + ui->filePathEdit->setText(fileName); + updateFileInfo(fileName); + } +} + +void AddCurveFileDlg::updateFileInfo(const QString& filePath) { + QFileInfo fileInfo(filePath); + if (fileInfo.exists()) { + ui->fileNameValue->setText(fileInfo.fileName()); + ui->fileSizeValue->setText(QString::number(fileInfo.size()) + " bytes"); + } else { + ui->fileNameValue->setText("-"); + ui->fileSizeValue->setText("-"); + } +} + +void AddCurveFileDlg::onFilePathChanged() { + QString filePath = ui->filePathEdit->text(); + if (!filePath.isEmpty()) { + updateFileInfo(filePath); + } +} + +void AddCurveFileDlg::onAddCurveClicked() { + // Save current curve properties if any curve is selected + if (currentCurveIndex_ >= 0) { + saveCurveProperties(); + } + + // Create new curve with default properties + CurveProperties newCurve; + newCurve.name = generateCurveName(); + newCurve.color = generateCurveColor(); + newCurve.start = 1; + newCurve.stop = 241; + + // Add to curves list and UI + curves_.append(newCurve); + addCurveToList(newCurve); + + // Select the new curve + ui->curveListWidget->setCurrentRow(curves_.size() - 1); +} + +void AddCurveFileDlg::onRemoveCurveClicked() { + int currentRow = ui->curveListWidget->currentRow(); + if (currentRow < 0 || currentRow >= curves_.size()) { + return; + } + + // Don't allow removing the last curve + if (curves_.size() <= 1) { + QMessageBox::information(this, "Information", "At least one curve must remain."); + return; + } + + // Remove from curves list and UI + curves_.removeAt(currentRow); + delete ui->curveListWidget->takeItem(currentRow); + + // Update current index + if (currentRow >= curves_.size()) { + currentRow = curves_.size() - 1; + } + + if (currentRow >= 0) { + ui->curveListWidget->setCurrentRow(currentRow); + } else { + currentCurveIndex_ = -1; + clearCurveProperties(); + enableCurveProperties(false); + } +} + +void AddCurveFileDlg::onCurveSelectionChanged() { + int currentRow = ui->curveListWidget->currentRow(); + + // Save previous curve properties + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) { + saveCurveProperties(); + } + + currentCurveIndex_ = currentRow; + + if (currentRow >= 0 && currentRow < curves_.size()) { + // Load selected curve properties + updateCurveProperties(); + enableCurveProperties(true); + } else { + clearCurveProperties(); + enableCurveProperties(false); + } +} + +void AddCurveFileDlg::onCurveNameChanged() { + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) { + QString newName = ui->curveNameEdit->text(); + curves_[currentCurveIndex_].name = newName; + + // Update list item text + QListWidgetItem* item = ui->curveListWidget->item(currentCurveIndex_); + if (item) { + item->setText(QString("%1 [%2,%3] (%4,%5,%6)") + .arg(newName) + .arg(curves_[currentCurveIndex_].start) + .arg(curves_[currentCurveIndex_].stop) + .arg(curves_[currentCurveIndex_].color.red()) + .arg(curves_[currentCurveIndex_].color.green()) + .arg(curves_[currentCurveIndex_].color.blue())); + } + } +} + +void AddCurveFileDlg::onCurveDataChanged() { + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) { + curves_[currentCurveIndex_].start = ui->dataStartSpinBox->value(); + curves_[currentCurveIndex_].stop = ui->dataStopSpinBox->value(); + + // Update list item text + QListWidgetItem* item = ui->curveListWidget->item(currentCurveIndex_); + if (item) { + item->setText(QString("%1 [%2,%3] (%4,%5,%6)") + .arg(curves_[currentCurveIndex_].name) + .arg(curves_[currentCurveIndex_].start) + .arg(curves_[currentCurveIndex_].stop) + .arg(curves_[currentCurveIndex_].color.red()) + .arg(curves_[currentCurveIndex_].color.green()) + .arg(curves_[currentCurveIndex_].color.blue())); + } + } +} + +void AddCurveFileDlg::onColorButtonClicked() { + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) { + QColor color = QColorDialog::getColor(curves_[currentCurveIndex_].color, this, "Select Curve Color"); + if (color.isValid()) { + curves_[currentCurveIndex_].color = color; + selectedColor_ = color; + updateColorPreview(color); + + // Update list item text + QListWidgetItem* item = ui->curveListWidget->item(currentCurveIndex_); + if (item) { + item->setText(QString("%1 [%2,%3] (%4,%5,%6)") + .arg(curves_[currentCurveIndex_].name) + .arg(curves_[currentCurveIndex_].start) + .arg(curves_[currentCurveIndex_].stop) + .arg(color.red()) + .arg(color.green()) + .arg(color.blue())); + } + } + } +} + +void AddCurveFileDlg::addCurveToList(const CurveProperties& curve) { + QString itemText = QString("%1 [%2,%3] (%4,%5,%6)") + .arg(curve.name) + .arg(curve.start) + .arg(curve.stop) + .arg(curve.color.red()) + .arg(curve.color.green()) + .arg(curve.color.blue()); + + ui->curveListWidget->addItem(itemText); +} + +void AddCurveFileDlg::updateCurveProperties() { + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) { + const CurveProperties& curve = curves_[currentCurveIndex_]; + + ui->curveNameEdit->setText(curve.name); + ui->dataStartSpinBox->setValue(curve.start); + ui->dataStopSpinBox->setValue(curve.stop); + + selectedColor_ = curve.color; + updateColorPreview(curve.color); + } +} + +void AddCurveFileDlg::saveCurveProperties() { + if (currentCurveIndex_ >= 0 && currentCurveIndex_ < curves_.size()) { + curves_[currentCurveIndex_].name = ui->curveNameEdit->text(); + curves_[currentCurveIndex_].start = ui->dataStartSpinBox->value(); + curves_[currentCurveIndex_].stop = ui->dataStopSpinBox->value(); + curves_[currentCurveIndex_].color = selectedColor_; + } +} + +void AddCurveFileDlg::clearCurveProperties() { + ui->curveNameEdit->clear(); + ui->dataStartSpinBox->setValue(1); + ui->dataStopSpinBox->setValue(241); + selectedColor_ = QColor(255, 0, 0); + updateColorPreview(selectedColor_); +} + +void AddCurveFileDlg::enableCurveProperties(bool enabled) { + ui->curvePropertiesGroupBox->setEnabled(enabled); +} + +QString AddCurveFileDlg::generateCurveName() { + return tr("Curve %1").arg(curves_.size() + 1); +} + +QColor AddCurveFileDlg::generateCurveColor() const { + // Generate different colors for each curve + static const QColor colors[] = { + QColor(255, 0, 0), // Red + QColor(0, 255, 0), // Green + QColor(0, 0, 255), // Blue + QColor(255, 255, 0), // Yellow + QColor(255, 0, 255), // Magenta + QColor(0, 255, 255), // Cyan + QColor(255, 128, 0), // Orange + QColor(128, 0, 255), // Purple + }; + + int colorIndex = curves_.size() % (sizeof(colors) / sizeof(colors[0])); + return colors[colorIndex]; +} + +void AddCurveFileDlg::updateColorPreview(const QColor& color) { + QString styleSheet = QString("background-color: rgb(%1, %2, %3); border: 1px solid black;") + .arg(color.red()) + .arg(color.green()) + .arg(color.blue()); + ui->colorPreview->setStyleSheet(styleSheet); +} + +bool AddCurveFileDlg::validateSpecificParams() { + // File path validation + if (ui->filePathEdit->text().isEmpty()) { + QMessageBox::warning(this, tr("Validation Error"), tr("Please select a data file.")); + return false; + } + + // File existence validation + QFileInfo fileInfo(ui->filePathEdit->text()); + if (!fileInfo.exists()) { + QMessageBox::warning(this, tr("Validation Error"), tr("Selected file does not exist.")); + return false; + } + + // File readability validation + if (!fileInfo.isReadable()) { + QMessageBox::warning(this, tr("Validation Error"), tr("Selected file is not readable. Please check file permissions.")); + return false; + } + + // File size validation (avoid memory issues with large files) + if (fileInfo.size() > 100 * 1024 * 1024) { // 100MB limit + QMessageBox::warning(this, tr("Validation Error"), tr("File is too large (over 100MB). Please select a smaller file.")); + return false; + } + + // Curve count validation + if (curves_.isEmpty()) { + QMessageBox::warning(this, tr("Validation Error"), tr("At least one curve must be defined.")); + return false; + } + + // Save current curve properties + if (currentCurveIndex_ >= 0) { + saveCurveProperties(); + } + + // Curve name uniqueness validation + QStringList curveNames; + for (int i = 0; i < curves_.size(); ++i) { + const CurveProperties& curve = curves_[i]; + + if (curve.name.isEmpty()) { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve %1 name cannot be empty.").arg(i + 1)); + return false; + } + + if (curveNames.contains(curve.name)) { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve name '%1' is duplicated. Please use different names.").arg(curve.name)); + return false; + } + curveNames.append(curve.name); + + // Curve name length validation + if (curve.name.length() > 50) { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve name '%1' is too long. Please limit to 50 characters.").arg(curve.name)); + return false; + } + + // Data range validation + if (curve.start < 1 || curve.stop < 1) { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve '%1' start and stop values must be greater than 0.").arg(curve.name)); + return false; + } + + if (curve.start > curve.stop) { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve '%1' start value cannot be greater than stop value.").arg(curve.name)); + return false; + } + + // Data range reasonableness validation + if (curve.stop - curve.start < 1) { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve '%1' data range is too small. At least 2 data points are required.").arg(curve.name)); + return false; + } + + if (curve.stop > 1000000) { + QMessageBox::warning(this, tr("Validation Error"), + tr("Curve '%1' stop value is too large. Please ensure it does not exceed 1000000.").arg(curve.name)); + return false; + } + } + + // Chart properties validation + if (ui->chartNameEdit->text().isEmpty()) { + QMessageBox::warning(this, tr("Validation Error"), tr("Chart name cannot be empty.")); + return false; + } + + if (ui->chartNameEdit->text().length() > 100) { + QMessageBox::warning(this, tr("Validation Error"), tr("Chart name is too long. Please limit to 100 characters.")); + return false; + } + + // Axis title validation + if (ui->xTitleEdit->text().length() > 50) { + QMessageBox::warning(this, tr("Validation Error"), tr("X axis title is too long. Please limit to 50 characters.")); + return false; + } + + if (ui->yTitleEdit->text().length() > 50) { + QMessageBox::warning(this, tr("Validation Error"), tr("Y axis title is too long. Please limit to 50 characters.")); + return false; + } + + // Axis range validation + double xMin = ui->xMinSpinBox->value(); + double xMax = ui->xMaxSpinBox->value(); + double yMin = ui->yMinSpinBox->value(); + double yMax = ui->yMaxSpinBox->value(); + + if (xMin >= xMax) { + QMessageBox::warning(this, tr("Validation Error"), tr("X axis minimum value must be less than maximum value.")); + return false; + } + + if (yMin >= yMax) { + QMessageBox::warning(this, tr("Validation Error"), tr("Y axis minimum value must be less than maximum value.")); + return false; + } + + // Data column validation + int xColumn = ui->xColumnSpinBox->value(); + int yColumn = ui->yColumnSpinBox->value(); + + if (xColumn == yColumn) { + QMessageBox::warning(this, tr("Validation Error"), tr("X column and Y column cannot be the same.")); + return false; + } + + if (xColumn < 1 || yColumn < 1) { + QMessageBox::warning(this, tr("Validation Error"), tr("Data column indices must be greater than 0.")); + return false; + } + + // Time parameter validation + double timeParam = ui->timeParamSpinBox->value(); + if (timeParam < 0) { + QMessageBox::warning(this, tr("Validation Error"), tr("Time parameter cannot be negative.")); + return false; + } + + // X axis tick count validation + int xTickCount = ui->xCountSpinBox->value(); + if (xTickCount < 2) { + QMessageBox::warning(this, tr("Validation Error"), tr("X axis tick count must be at least 2.")); + return false; + } + + // Description length validation + if (ui->descriptionEdit->toPlainText().length() > 500) { + QMessageBox::warning(this, tr("Validation Error"), tr("Description is too long. Please limit to 500 characters.")); + return false; + } + + return true; +} + +QString AddCurveFileDlg::getFileFilter() const { + return "Data Files (*.txt *.csv *.dat);;All Files (*.*)"; +} + +QString AddCurveFileDlg::getDialogTitle() const { + return "Add Curve Data File"; +} + +AddCurveFileDlg::CurveParams AddCurveFileDlg::getCurveParams() const { + CurveParams params; + params.chart = getChartProperties(); + params.curves = getCurveProperties(); + params.format = getDataFormatParams(); + return params; +} + +AddCurveFileDlg::ChartProperties AddCurveFileDlg::getChartProperties() const { + ChartProperties chart; + chart.name = ui->chartNameEdit->text(); + chart.path = ui->filePathEdit->text(); + chart.xTitle = ui->xTitleEdit->text(); + chart.yTitle = ui->yTitleEdit->text(); + chart.xMin = ui->xMinSpinBox->value(); + chart.xMax = ui->xMaxSpinBox->value(); + chart.xCount = ui->xCountSpinBox->value(); + chart.yMin = ui->yMinSpinBox->value(); + chart.yMax = ui->yMaxSpinBox->value(); + chart.timeParam = ui->timeParamSpinBox->value(); + return chart; +} + +QList AddCurveFileDlg::getCurveProperties() const { + return curves_; +} + +AddCurveFileDlg::DataFormatParams AddCurveFileDlg::getDataFormatParams() const { + DataFormatParams format; + + // Get delimiter based on combo box selection + QString delimiterText = ui->separatorComboBox->currentText(); + if (delimiterText.contains("Comma")) { + format.delimiter = ","; + } else if (delimiterText.contains("Tab")) { + format.delimiter = "\t"; + } else if (delimiterText.contains("Space")) { + format.delimiter = " "; + } else if (delimiterText.contains("Semicolon")) { + format.delimiter = ";"; + } else { + format.delimiter = ","; // Default + } + + format.hasHeader = ui->hasHeaderCheckBox->isChecked(); + format.xColumn = ui->xColumnSpinBox->value(); + format.yColumn = ui->yColumnSpinBox->value(); + format.description = ui->descriptionEdit->toPlainText(); + + return format; +} + +void AddCurveFileDlg::onDelimiterChanged() { + // This slot can be used for future delimiter-related logic +} + +void AddCurveFileDlg::onHeaderToggled(bool hasHeader) { + // This slot can be used for future header-related logic +} + +void AddCurveFileDlg::onSure() { + if (validateSpecificParams()) { + accept(); + } +} \ No newline at end of file diff --git a/src/ui/WorkSpace/AddCurveFileDlg.h b/src/ui/WorkSpace/AddCurveFileDlg.h new file mode 100644 index 00000000..e9c20631 --- /dev/null +++ b/src/ui/WorkSpace/AddCurveFileDlg.h @@ -0,0 +1,108 @@ +#pragma once + +#include "BaseAddFileDlg.h" +#include +#include + +class QLineEdit; +class QCheckBox; +class QSpinBox; +class QDoubleSpinBox; +class QComboBox; +class QTextEdit; +class QToolButton; +class QLabel; +class QPushButton; +class QListWidget; +class QListWidgetItem; + +namespace Ui { + class AddCurveFileDlg; +} + +class AddCurveFileDlg : public BaseAddFileDlg { + Q_OBJECT + +public: + // Chart properties structure + struct ChartProperties { + QString name; + QString path; + QString xTitle; + QString yTitle; + double xMin; + double xMax; + int xCount; + double yMin; + double yMax; + double timeParam; + }; + + // Curve properties structure + struct CurveProperties { + QString name; + QColor color; + int start; + int stop; + }; + + // Data format parameters structure + struct DataFormatParams { + QString delimiter; + bool hasHeader; + int xColumn; + int yColumn; + QString description; + }; + + // Combined parameters structure + struct CurveParams { + ChartProperties chart; + QList curves; // Changed to support multiple curves + DataFormatParams format; + }; + + explicit AddCurveFileDlg(QWidget* parent = nullptr); + ~AddCurveFileDlg() override; + + CurveParams getCurveParams() const; + ChartProperties getChartProperties() const; + QList getCurveProperties() const; // Changed to return list + DataFormatParams getDataFormatParams() const; + +protected: + QString getFileFilter() const override; + QString getDialogTitle() const override; + void setupSpecificUI() override; + bool validateSpecificParams() override; + +private slots: + void onDelimiterChanged(); + void onHeaderToggled(bool hasHeader); + void onSelectFileClicked(); + void onFilePathChanged(); + void onColorButtonClicked(); + void onAddCurveClicked(); + void onRemoveCurveClicked(); + void onCurveSelectionChanged(); + void onCurveNameChanged(); + void onCurveDataChanged(); + void onSure(); + +private: + void setupConnections(); + void updateFileInfo(const QString& filePath); + void updateColorPreview(const QColor& color); + void addCurveToList(const CurveProperties& curve); + void updateCurveProperties(); + void saveCurveProperties(); + void clearCurveProperties(); + void enableCurveProperties(bool enabled); + QString generateCurveName(); + QColor generateCurveColor() const; + + Ui::AddCurveFileDlg* ui; + QList curves_; + int currentCurveIndex_; + QColor selectedColor_; +}; \ No newline at end of file diff --git a/src/ui/WorkSpace/AddCurveFileDlg.ui b/src/ui/WorkSpace/AddCurveFileDlg.ui new file mode 100644 index 00000000..27208739 --- /dev/null +++ b/src/ui/WorkSpace/AddCurveFileDlg.ui @@ -0,0 +1,615 @@ + + + AddCurveFileDlg + + + + 0 + 0 + 600 + 700 + + + + Add Curve Data File + + + + + + File Selection + + + + + + File Path: + + + + + + + Select curve data file... + + + true + + + + + + + ... + + + + + + + File Name: + + + + + + + - + + + + + + + File Size: + + + + + + + - + + + + + + + + + + Chart Properties + + + + + + Chart Name: + + + + + + + Chart 1 + + + Enter chart name... + + + + + + + X Axis Title: + + + + + + + Enter X axis title... + + + + + + + Y Axis Title: + + + + + + + Enter Y axis title... + + + + + + + Time Parameter: + + + + + + + 0.000000000000000 + + + 999999.000000000000000 + + + 0.000000000000000 + + + + + + + + + + Axis Range Settings + + + + + + X Min: + + + + + + + -999999.000000000000000 + + + 999999.000000000000000 + + + 0.000000000000000 + + + + + + + X Max: + + + + + + + -999999.000000000000000 + + + 999999.000000000000000 + + + 250.000000000000000 + + + + + + + Y Min: + + + + + + + -999999.000000000000000 + + + 999999.000000000000000 + + + -800.000000000000000 + + + + + + + Y Max: + + + + + + + -999999.000000000000000 + + + 999999.000000000000000 + + + 800.000000000000000 + + + + + + + X Tick Count: + + + + + + + 2 + + + 50 + + + 6 + + + + + + + + + + Curve Management + + + + + + + + Curves: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add Curve + + + + 80 + 16777215 + + + + + + + + Remove + + + + 60 + 16777215 + + + + + + + + + + + 16777215 + 120 + + + + true + + + + + + + Selected Curve Properties + + + false + + + + + + Curve Name: + + + + + + + Enter curve name... + + + + + + + Curve Color: + + + + + + + + + Select Color + + + + 100 + 16777215 + + + + + + + + + 50 + 25 + + + + background-color: rgb(255, 0, 0); border: 1px solid black; + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Data Start: + + + + + + + 1 + + + 999999 + + + 1 + + + + + + + Data Stop: + + + + + + + 1 + + + 999999 + + + 241 + + + + + + + + + + + + + Data Format Parameters + + + + + + X Column: + + + + + + + 1 + + + 100 + + + 1 + + + + + + + Y Column: + + + + + + + 1 + + + 100 + + + 2 + + + + + + + Separator: + + + + + + + + Comma (,) + + + + + Tab + + + + + Space + + + + + Semicolon (;) + + + + + + + + File has header row + + + true + + + + + + + + + + Description (Optional) + + + + + + + 16777215 + 60 + + + + Enter file description... + + + + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add File + + + true + + + + + + + Cancel + + + + + + + + + + \ No newline at end of file diff --git a/src/ui/WorkSpace/AddFileDialogFactory.cpp b/src/ui/WorkSpace/AddFileDialogFactory.cpp new file mode 100644 index 00000000..b9bf66bf --- /dev/null +++ b/src/ui/WorkSpace/AddFileDialogFactory.cpp @@ -0,0 +1,22 @@ +#include "AddFileDialogFactory.h" + +#include "BaseAddFileDlg.h" +#include "AddCurveFileDlg.h" +#include "AddSurfaceFileDlg.h" +#include "AddTableFileDlg.h" +#include "AddLightFileDlg.h" + +BaseAddFileDlg* AddFileDialogFactory::createDialog(FileEntryType type, QWidget* parent) { + switch (type) { + case FileEntryType::Curve: + return new AddCurveFileDlg(parent); + case FileEntryType::Surface: + return new AddSurfaceFileDlg(parent); + case FileEntryType::Table: + return new AddTableFileDlg(parent); + case FileEntryType::Light: + return new AddLightFileDlg(parent); + default: + return nullptr; + } +} \ No newline at end of file diff --git a/src/ui/WorkSpace/AddFileDialogFactory.h b/src/ui/WorkSpace/AddFileDialogFactory.h new file mode 100644 index 00000000..2fda1ec9 --- /dev/null +++ b/src/ui/WorkSpace/AddFileDialogFactory.h @@ -0,0 +1,15 @@ +#pragma once + +#include "workspace/FileEntry.h" +#include + +class BaseAddFileDlg; +class QWidget; + +class AddFileDialogFactory { +public: + static BaseAddFileDlg* createDialog(FileEntryType fileType, QWidget* parent = nullptr); + +private: + AddFileDialogFactory() = default; +}; \ No newline at end of file diff --git a/src/ui/WorkSpace/AddFileDlg.cpp b/src/ui/WorkSpace/AddFileDlg.cpp deleted file mode 100644 index 6502137b..00000000 --- a/src/ui/WorkSpace/AddFileDlg.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "AddFileDlg.h" -#include "ui_AddFileDlg.h" - -#include -#include -#include -#include - -#include "app/Application.h" -#include "common/SpdLogger.h" - -AddFileDlg::AddFileDlg(QWidget* parent) - : Dialog(parent) - , ui(new Ui::AddFileDlg) - , selectedFileType_(FileEntryType::Curve) { - ui->setupUi(this); - - // 设置对话框标题 - SetTitle(QStringLiteral("Add File to Workspace")); - - InitConnect(); - UpdateUI(); -} - -AddFileDlg::~AddFileDlg() { - delete ui; -} - -void AddFileDlg::InitConnect() { - connect(ui->tbSelectFile, &QToolButton::clicked, this, &AddFileDlg::OnSelectFile); - connect(ui->cbFileType, QOverload::of(&QComboBox::currentIndexChanged), - this, &AddFileDlg::OnFileTypeChanged); - connect(ui->pbAdd, &QPushButton::clicked, this, &AddFileDlg::OnSure); - connect(ui->pbCancel, &QPushButton::clicked, this, &AddFileDlg::reject); -} - -void AddFileDlg::OnSelectFile() { - const QString workspacePath = Application::GetWorkSpacePath(); - QString filePath = QFileDialog::getOpenFileName( - this, - QStringLiteral("Select File"), - workspacePath, - QStringLiteral("Text Files (*.txt);;All Files (*.*)") - ); - - if (filePath.isEmpty()) { - return; - } - - selectedFilePath_ = filePath; - ui->leFilePath->setText(filePath); - - QFileInfo fileInfo(filePath); - ui->lblFileName->setText(fileInfo.fileName()); - - qint64 size = fileInfo.size(); - QString sizeText; - if (size < 1024) { - sizeText = QString("%1 B").arg(size); - } else if (size < 1024 * 1024) { - sizeText = QString("%1 KB").arg(size / 1024.0, 0, 'f', 1); - } else { - sizeText = QString("%1 MB").arg(size / (1024.0 * 1024.0), 0, 'f', 1); - } - ui->lblFileSize->setText(sizeText); - - LOG_INFO("Selected file: {}", filePath.toStdString()); -} - -void AddFileDlg::OnFileTypeChanged() { - int index = ui->cbFileType->currentIndex(); - switch (index) { - case 0: selectedFileType_ = FileEntryType::Curve; break; - case 1: selectedFileType_ = FileEntryType::Surface; break; - case 2: selectedFileType_ = FileEntryType::Table; break; - case 3: selectedFileType_ = FileEntryType::Light; break; - default: selectedFileType_ = FileEntryType::Curve; break; - } - - LOG_INFO("File type changed to: {}", static_cast(selectedFileType_)); -} - -void AddFileDlg::OnSure() { - if (!ValidateInput()) { - return; - } - - accept(); -} - -void AddFileDlg::UpdateUI() { - ui->lblFileName->setText(QStringLiteral("-")); - ui->lblFileSize->setText(QStringLiteral("-")); - ui->cbFileType->setCurrentIndex(0); - selectedFileType_ = FileEntryType::Curve; -} - -bool AddFileDlg::ValidateInput() { - if (selectedFilePath_.isEmpty()) { - QMessageBox::warning(this, QStringLiteral("Warning"), - QStringLiteral("Please select a file first.")); - return false; - } - - QFileInfo fileInfo(selectedFilePath_); - if (!fileInfo.exists()) { - QMessageBox::warning(this, QStringLiteral("Warning"), - QStringLiteral("Selected file does not exist.")); - return false; - } - - return true; -} - -FileEntryType AddFileDlg::getSelectedFileType() const { - return selectedFileType_; -} - -QString AddFileDlg::getSelectedFilePath() const { - return selectedFilePath_; -} - -QString AddFileDlg::getDescription() const { - return ui->teDescription->toPlainText().trimmed(); -} \ No newline at end of file diff --git a/src/ui/WorkSpace/AddFileDlg.h b/src/ui/WorkSpace/AddFileDlg.h deleted file mode 100644 index 25d4734d..00000000 --- a/src/ui/WorkSpace/AddFileDlg.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "ui/Dialog.h" -#include "workspace/FileEntry.h" - -namespace Ui { - class AddFileDlg; -} - -class AddFileDlg : public Dialog { - Q_OBJECT - -public: - AddFileDlg(QWidget* parent = nullptr); - ~AddFileDlg() override; - - FileEntryType getSelectedFileType() const; - - QString getSelectedFilePath() const; - - QString getDescription() const; - -protected: - void InitConnect(); - void OnSure(); - void OnSelectFile(); - void OnFileTypeChanged(); - -private: - void UpdateUI(); - bool ValidateInput(); - -private: - Ui::AddFileDlg* ui; - QString selectedFilePath_; - FileEntryType selectedFileType_; -}; \ No newline at end of file diff --git a/src/ui/WorkSpace/AddFileDlg.ui b/src/ui/WorkSpace/AddFileDlg.ui deleted file mode 100644 index 0af1c6ad..00000000 --- a/src/ui/WorkSpace/AddFileDlg.ui +++ /dev/null @@ -1,266 +0,0 @@ - - - AddFileDlg - - - - 0 - 0 - 480 - 320 - - - - Add File to Workspace - - - - - - - - File Path - - - - 80 - 0 - - - - - - - - true - - - Select file to add... - - - - - - - ... - - - - 30 - 25 - - - - - - - - - - - - File Type - - - - 80 - 0 - - - - - - - - - Curve Data - - - - - Surface Data - - - - - Table Data - - - - - Light Data - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - File Information - - - - - - - - File Name: - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - File Size: - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - - - Description (Optional) - - - - - - - - 16777215 - 60 - - - - Enter file description... - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Add File - - - - 80 - 30 - - - - - - - - Cancel - - - - 80 - 30 - - - - - - - - - - - \ No newline at end of file diff --git a/src/ui/WorkSpace/AddLightFileDlg.cpp b/src/ui/WorkSpace/AddLightFileDlg.cpp new file mode 100644 index 00000000..f67844ee --- /dev/null +++ b/src/ui/WorkSpace/AddLightFileDlg.cpp @@ -0,0 +1,70 @@ +#include "AddLightFileDlg.h" + +#include +#include + +#include "ui_AddLightFileDlg.h" + +AddLightFileDlg::AddLightFileDlg(QWidget* parent) + : BaseAddFileDlg(FileEntryType::Light, parent) + , ui(new Ui::AddLightFileDlg) { + + ui->setupUi(this); + SetTitle(getDialogTitle()); + setupSpecificUI(); +} + +AddLightFileDlg::~AddLightFileDlg() { + delete ui; +} + +void AddLightFileDlg::setupSpecificUI() { +} + +bool AddLightFileDlg::validateSpecificParams() { + LightParams params = getLightParams(); + + if (params.delimiter.isEmpty()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("Please specify a delimiter for light data.")); + return false; + } + + return true; +} + +QString AddLightFileDlg::getFileFilter() const { + return QStringLiteral("Light Spectrum Files (*.txt *.csv *.dat *.spe *.asc);;All Files (*.*)"); +} + +QString AddLightFileDlg::getDialogTitle() const { + return QStringLiteral("Add Light Spectrum File"); +} + +void AddLightFileDlg::onDelimiterChanged() { + // Handle delimiter change if needed +} + +void AddLightFileDlg::onHeaderToggled(bool hasHeader) { + // Handle header toggle if needed +} + +AddLightFileDlg::LightParams AddLightFileDlg::getLightParams() const { + LightParams params; + params.wavelengthColumn = ui->wavelengthColumnSpinBox->value(); + params.intensityColumn = ui->intensityColumnSpinBox->value(); + + // Get delimiter from combo box + int index = ui->separatorComboBox->currentIndex(); + switch (index) { + case 0: params.delimiter = ","; break; + case 1: params.delimiter = "\t"; break; + case 2: params.delimiter = " "; break; + case 3: params.delimiter = ";"; break; + default: params.delimiter = ","; break; + } + + params.hasHeader = ui->hasHeaderCheckBox->isChecked(); + params.description = ui->descriptionEdit->toPlainText().trimmed(); + return params; +} \ No newline at end of file diff --git a/src/ui/WorkSpace/AddLightFileDlg.h b/src/ui/WorkSpace/AddLightFileDlg.h new file mode 100644 index 00000000..04588887 --- /dev/null +++ b/src/ui/WorkSpace/AddLightFileDlg.h @@ -0,0 +1,39 @@ +#pragma once + +namespace Ui { + class AddLightFileDlg; +} + +#include "BaseAddFileDlg.h" + + +class AddLightFileDlg : public BaseAddFileDlg { + Q_OBJECT + +public: + struct LightParams { + QString delimiter; + bool hasHeader; + int wavelengthColumn; + int intensityColumn; + QString description; + }; + + explicit AddLightFileDlg(QWidget* parent = nullptr); + ~AddLightFileDlg() override; + + LightParams getLightParams() const; + +protected: + QString getFileFilter() const override; + QString getDialogTitle() const override; + void setupSpecificUI() override; + bool validateSpecificParams() override; + +private slots: + void onDelimiterChanged(); + void onHeaderToggled(bool hasHeader); + +private: + Ui::AddLightFileDlg* ui; +}; \ No newline at end of file diff --git a/src/ui/WorkSpace/AddLightFileDlg.ui b/src/ui/WorkSpace/AddLightFileDlg.ui new file mode 100644 index 00000000..9e10051a --- /dev/null +++ b/src/ui/WorkSpace/AddLightFileDlg.ui @@ -0,0 +1,372 @@ + + + AddLightFileDlg + + + + 0 + 0 + 500 + 480 + + + + Add Light Spectrum File + + + + + + File Selection + + + + + + File Path: + + + + + + + Select light spectrum file... + + + true + + + + + + + ... + + + + + + + File Name: + + + + + + + - + + + + + + + File Size: + + + + + + + - + + + + + + + + + + Spectrum Parameters + + + + + + Wavelength Column: + + + + + + + 1 + + + 100 + + + 1 + + + + + + + Intensity Column: + + + + + + + 1 + + + 100 + + + 2 + + + + + + + Separator: + + + + + + + + Comma (,) + + + + + Tab + + + + + Space + + + + + Semicolon (;) + + + + + + + + Wavelength Unit: + + + + + + + + nm (nanometer) + + + + + μm (micrometer) + + + + + cm⁻¹ (wavenumber) + + + + + eV (electron volt) + + + + + + + + Intensity Unit: + + + + + + + + Arbitrary Units + + + + + Counts + + + + + W/m²/nm + + + + + μW/cm²/nm + + + + + + + + File has header row + + + true + + + + + + + Normalize intensity values + + + false + + + + + + + + + + Wavelength Range (Optional) + + + + + + Min Wavelength: + + + + + + + 0.000000000000000 + + + 10000.000000000000000 + + + 380.000000000000000 + + + + + + + Max Wavelength: + + + + + + + 0.000000000000000 + + + 10000.000000000000000 + + + 780.000000000000000 + + + + + + + Enable wavelength range filtering + + + false + + + + + + + + + + Description (Optional) + + + + + + + 16777215 + 60 + + + + Enter file description... + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add File + + + true + + + + + + + Cancel + + + + + + + + + + \ No newline at end of file diff --git a/src/ui/WorkSpace/AddSurfaceFileDlg.cpp b/src/ui/WorkSpace/AddSurfaceFileDlg.cpp new file mode 100644 index 00000000..65faa002 --- /dev/null +++ b/src/ui/WorkSpace/AddSurfaceFileDlg.cpp @@ -0,0 +1,140 @@ +#include "AddSurfaceFileDlg.h" + +#include +#include +#include +#include "app/Application.h" +#include "common/SpdLogger.h" + +#include "ui_AddSurfaceFileDlg.h" + +AddSurfaceFileDlg::AddSurfaceFileDlg(QWidget* parent) + : BaseAddFileDlg(FileEntryType::Surface, parent) + , ui_(new Ui::AddSurfaceFileDlg) { + + ui_->setupUi(this); + SetTitle(getDialogTitle()); + setupSpecificUI(); + setupConnections(); +} + +AddSurfaceFileDlg::~AddSurfaceFileDlg() { + delete ui_; +} + +void AddSurfaceFileDlg::setupSpecificUI() { + // UI is already set up in constructor +} + +void AddSurfaceFileDlg::setupConnections() { + connect(ui_->selectFileBtn, &QToolButton::clicked, this, &AddSurfaceFileDlg::onSelectFileClicked); + connect(ui_->filePathEdit, &QLineEdit::textChanged, this, &AddSurfaceFileDlg::onFilePathChanged); + connect(ui_->addBtn, &QPushButton::clicked, this, [this]() { OnSure(); }); + connect(ui_->cancelBtn, &QPushButton::clicked, this, &QDialog::reject); +} + +void AddSurfaceFileDlg::onSelectFileClicked() { + const QString workspacePath = Application::GetWorkSpacePath(); + QString filePath = QFileDialog::getOpenFileName( + this, + QStringLiteral("Select Surface Data File"), + workspacePath, + getFileFilter() + ); + + if (filePath.isEmpty()) { + return; + } + + ui_->filePathEdit->setText(filePath); + updateFileInfo(filePath); + + LOG_INFO("Selected surface file: {}", filePath.toStdString()); +} + +void AddSurfaceFileDlg::onFilePathChanged() { + QString filePath = ui_->filePathEdit->text(); + if (!filePath.isEmpty()) { + updateFileInfo(filePath); + } +} + +void AddSurfaceFileDlg::updateFileInfo(const QString& filePath) { + QFileInfo fileInfo(filePath); + ui_->fileNameValue->setText(fileInfo.fileName()); + + qint64 size = fileInfo.size(); + QString sizeText; + if (size < 1024) { + sizeText = QString("%1 B").arg(size); + } else if (size < 1024 * 1024) { + sizeText = QString("%1 KB").arg(size / 1024.0, 0, 'f', 1); + } else { + sizeText = QString("%1 MB").arg(size / (1024.0 * 1024.0), 0, 'f', 1); + } + ui_->fileSizeValue->setText(sizeText); +} + +bool AddSurfaceFileDlg::validateSpecificParams() { + if (ui_->filePathEdit->text().isEmpty()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("Please select a surface data file.")); + return false; + } + + QFileInfo fileInfo(ui_->filePathEdit->text()); + if (!fileInfo.exists()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("The selected file does not exist.")); + return false; + } + + if (ui_->xColumnSpinBox->value() == ui_->yColumnSpinBox->value() || + ui_->xColumnSpinBox->value() == ui_->zColumnSpinBox->value() || + ui_->yColumnSpinBox->value() == ui_->zColumnSpinBox->value()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("X, Y, and Z columns must be different.")); + return false; + } + + return true; +} + +QString AddSurfaceFileDlg::getFileFilter() const { + return QStringLiteral("Surface Data Files (*.txt *.csv *.dat *.xyz);;All Files (*.*)"); +} + +QString AddSurfaceFileDlg::getDialogTitle() const { + return QStringLiteral("Add Surface Data File"); +} + +QString AddSurfaceFileDlg::getSelectedFilePath() const { + return ui_->filePathEdit->text(); +} + +QString AddSurfaceFileDlg::getDescription() const { + return ui_->descriptionEdit->toPlainText().trimmed(); +} + +AddSurfaceFileDlg::SurfaceParams AddSurfaceFileDlg::getSurfaceParams() const { + SurfaceParams params; + params.xColumn = ui_->xColumnSpinBox->value(); + params.yColumn = ui_->yColumnSpinBox->value(); + params.zColumn = ui_->zColumnSpinBox->value(); + params.xGridSize = ui_->xGridSizeSpinBox->value(); + params.yGridSize = ui_->yGridSizeSpinBox->value(); + params.hasHeader = ui_->hasHeaderCheckBox->isChecked(); + params.description = ui_->descriptionEdit->toPlainText().trimmed(); + + // Get delimiter from combo box + int index = ui_->separatorComboBox->currentIndex(); + switch (index) { + case 0: params.delimiter = ","; break; + case 1: params.delimiter = "\t"; break; + case 2: params.delimiter = " "; break; + case 3: params.delimiter = ";"; break; + default: params.delimiter = ","; break; + } + + return params; +} \ No newline at end of file diff --git a/src/ui/WorkSpace/AddSurfaceFileDlg.h b/src/ui/WorkSpace/AddSurfaceFileDlg.h new file mode 100644 index 00000000..367ba2e2 --- /dev/null +++ b/src/ui/WorkSpace/AddSurfaceFileDlg.h @@ -0,0 +1,57 @@ +#pragma once + +#include "BaseAddFileDlg.h" + +QT_BEGIN_NAMESPACE +class QLineEdit; +class QCheckBox; +class QSpinBox; +class QComboBox; +class QTextEdit; +class QToolButton; +class QLabel; +QT_END_NAMESPACE + +namespace Ui { + class AddSurfaceFileDlg; +} + +class AddSurfaceFileDlg : public BaseAddFileDlg { + Q_OBJECT + +public: + struct SurfaceParams { + QString delimiter; + bool hasHeader; + int xColumn; + int yColumn; + int zColumn; + int xGridSize; + int yGridSize; + QString description; + }; + + explicit AddSurfaceFileDlg(QWidget* parent = nullptr); + ~AddSurfaceFileDlg() override; + + SurfaceParams getSurfaceParams() const; + QString getSelectedFilePath() const; + QString getDescription() const; + +protected: + QString getFileFilter() const override; + QString getDialogTitle() const override; + void setupSpecificUI() override; + bool validateSpecificParams() override; + +private slots: + void onSelectFileClicked(); + void onFilePathChanged(); + +private: + void setupConnections(); + void updateFileInfo(const QString& filePath); + +private: + Ui::AddSurfaceFileDlg* ui_; +}; \ No newline at end of file diff --git a/src/ui/WorkSpace/AddSurfaceFileDlg.ui b/src/ui/WorkSpace/AddSurfaceFileDlg.ui new file mode 100644 index 00000000..e7446dae --- /dev/null +++ b/src/ui/WorkSpace/AddSurfaceFileDlg.ui @@ -0,0 +1,301 @@ + + + AddSurfaceFileDlg + + + + 0 + 0 + 500 + 520 + + + + Add Surface Data File + + + + + + File Selection + + + + + + File Path: + + + + + + + Select surface data file... + + + true + + + + + + + ... + + + + + + + File Name: + + + + + + + - + + + + + + + File Size: + + + + + + + - + + + + + + + + + + Surface Parameters + + + + + + X Column: + + + + + + + 1 + + + 100 + + + 1 + + + + + + + Y Column: + + + + + + + 1 + + + 100 + + + 2 + + + + + + + Z Column: + + + + + + + 1 + + + 100 + + + 3 + + + + + + + Separator: + + + + + + + + Comma (,) + + + + + Tab + + + + + Space + + + + + Semicolon (;) + + + + + + + + X Grid Size: + + + + + + + 1 + + + 10000 + + + 10 + + + + + + + Y Grid Size: + + + + + + + 1 + + + 10000 + + + 10 + + + + + + + File has header row + + + true + + + + + + + + + + Description (Optional) + + + + + + + 16777215 + 80 + + + + Enter file description... + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add File + + + true + + + + + + + Cancel + + + + + + + + + + \ No newline at end of file diff --git a/src/ui/WorkSpace/AddTableFileDlg.cpp b/src/ui/WorkSpace/AddTableFileDlg.cpp new file mode 100644 index 00000000..ef6f9181 --- /dev/null +++ b/src/ui/WorkSpace/AddTableFileDlg.cpp @@ -0,0 +1,135 @@ +#include "AddTableFileDlg.h" + +#include +#include +#include + +#include "app/Application.h" +#include "common/SpdLogger.h" + +#include "ui_AddTableFileDlg.h" + + +AddTableFileDlg::AddTableFileDlg(QWidget* parent) + : BaseAddFileDlg(FileEntryType::Table, parent) + , ui(new Ui::AddTableFileDlg) { + + ui->setupUi(this); + SetTitle(getDialogTitle()); + setupSpecificUI(); + setupConnections(); +} + +AddTableFileDlg::~AddTableFileDlg() { + delete ui; +} + +void AddTableFileDlg::setupSpecificUI() { + // UI is already set up in constructor +} + +void AddTableFileDlg::setupConnections() { + // Connect file selection + connect(ui->selectFileBtn, &QToolButton::clicked, this, &AddTableFileDlg::onSelectFileClicked); + connect(ui->filePathEdit, &QLineEdit::textChanged, this, &AddTableFileDlg::onFilePathChanged); + connect(ui->separatorComboBox, QOverload::of(&QComboBox::currentIndexChanged), + this, &AddTableFileDlg::onDelimiterChanged); + connect(ui->hasHeaderCheckBox, &QCheckBox::toggled, this, &AddTableFileDlg::onHeaderToggled); + connect(ui->addBtn, &QPushButton::clicked, this, [this]() { OnSure(); }); + connect(ui->cancelBtn, &QPushButton::clicked, this, &QDialog::reject); +} + +void AddTableFileDlg::onSelectFileClicked() { + const QString workspacePath = Application::GetWorkSpacePath(); + QString filePath = QFileDialog::getOpenFileName( + this, + QStringLiteral("Select Table File"), + workspacePath, + getFileFilter() + ); + + if (!filePath.isEmpty()) { + ui->filePathEdit->setText(filePath); + } +} + +void AddTableFileDlg::onFilePathChanged(const QString& filePath) { + updateFileInfo(filePath); +} + +void AddTableFileDlg::updateFileInfo(const QString& filePath) { + QFileInfo fileInfo(filePath); + ui->fileNameValue->setText(fileInfo.fileName()); + + qint64 size = fileInfo.size(); + QString sizeText; + if (size < 1024) { + sizeText = QString("%1 B").arg(size); + } else if (size < 1024 * 1024) { + sizeText = QString("%1 KB").arg(size / 1024.0, 0, 'f', 1); + } else { + sizeText = QString("%1 MB").arg(size / (1024.0 * 1024.0), 0, 'f', 1); + } + ui->fileSizeValue->setText(sizeText); +} + +void AddTableFileDlg::onDelimiterChanged() { + // Handle delimiter change if needed +} + +void AddTableFileDlg::onHeaderToggled(bool hasHeader) { + // Handle header toggle if needed +} + +bool AddTableFileDlg::validateSpecificParams() { + if (ui->filePathEdit->text().isEmpty()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("Please select a table file first.")); + return false; + } + + QFileInfo fileInfo(ui->filePathEdit->text()); + if (!fileInfo.exists()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("Selected file does not exist.")); + return false; + } + + return true; +} + +QString AddTableFileDlg::getFileFilter() const { + return QStringLiteral("Table Files (*.txt *.csv *.tsv *.dat);;All Files (*.*)"); +} + +QString AddTableFileDlg::getDialogTitle() const { + return QStringLiteral("Add Table Data File"); +} + +QString AddTableFileDlg::getSelectedFilePath() const { + return ui->filePathEdit->text(); +} + +QString AddTableFileDlg::getDescription() const { + return ui->descriptionEdit->toPlainText().trimmed(); +} + +AddTableFileDlg::TableParams AddTableFileDlg::getTableParams() const { + TableParams params; + + // Get delimiter from combo box + int index = ui->separatorComboBox->currentIndex(); + switch (index) { + case 0: params.delimiter = ","; break; + case 1: params.delimiter = "\t"; break; + case 2: params.delimiter = " "; break; + case 3: params.delimiter = ";"; break; + default: params.delimiter = ","; break; + } + + params.hasHeader = ui->hasHeaderCheckBox->isChecked(); + params.xColumn = 1; // Default values + params.yColumn = 2; + params.description = ui->descriptionEdit->toPlainText().trimmed(); + return params; +} \ No newline at end of file diff --git a/src/ui/WorkSpace/AddTableFileDlg.h b/src/ui/WorkSpace/AddTableFileDlg.h new file mode 100644 index 00000000..f91de097 --- /dev/null +++ b/src/ui/WorkSpace/AddTableFileDlg.h @@ -0,0 +1,45 @@ +#pragma once + +namespace Ui { + class AddTableFileDlg; +} + +#include "BaseAddFileDlg.h" + +class AddTableFileDlg : public BaseAddFileDlg { + Q_OBJECT + +public: + struct TableParams { + QString delimiter; + bool hasHeader; + int xColumn; + int yColumn; + QString description; + }; + + explicit AddTableFileDlg(QWidget* parent = nullptr); + ~AddTableFileDlg() override; + + TableParams getTableParams() const; + QString getSelectedFilePath() const; + QString getDescription() const; + +protected: + QString getFileFilter() const override; + QString getDialogTitle() const override; + void setupSpecificUI() override; + bool validateSpecificParams() override; + +private slots: + void onSelectFileClicked(); + void onFilePathChanged(const QString& filePath); + void onDelimiterChanged(); + void onHeaderToggled(bool hasHeader); + +private: + void setupConnections(); + void updateFileInfo(const QString& filePath); + + Ui::AddTableFileDlg* ui; +}; \ No newline at end of file diff --git a/src/ui/WorkSpace/AddTableFileDlg.ui b/src/ui/WorkSpace/AddTableFileDlg.ui new file mode 100644 index 00000000..9dac6bdc --- /dev/null +++ b/src/ui/WorkSpace/AddTableFileDlg.ui @@ -0,0 +1,293 @@ + + + AddTableFileDlg + + + + 0 + 0 + 480 + 450 + + + + Add Table Data File + + + + + + File Selection + + + + + + File Path: + + + + + + + Select table data file... + + + true + + + + + + + ... + + + + + + + File Name: + + + + + + + - + + + + + + + File Size: + + + + + + + - + + + + + + + + + + Table Parameters + + + + + + Separator: + + + + + + + + Comma (,) + + + + + Tab + + + + + Space + + + + + Semicolon (;) + + + + + + + + Encoding: + + + + + + + + UTF-8 + + + + + GBK + + + + + ASCII + + + + + ISO-8859-1 + + + + + + + + Skip Rows: + + + + + + + 0 + + + 1000 + + + 0 + + + + + + + File has header row + + + true + + + + + + + Auto-detect parameters + + + true + + + + + + + + + + Preview + + + + + + + 16777215 + 120 + + + + true + + + QAbstractItemView::NoSelection + + + 5 + + + 5 + + + + + + + + + + Description (Optional) + + + + + + + 16777215 + 60 + + + + Enter file description... + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Add File + + + true + + + + + + + Cancel + + + + + + + + + + \ No newline at end of file diff --git a/src/ui/WorkSpace/BaseAddFileDlg.cpp b/src/ui/WorkSpace/BaseAddFileDlg.cpp new file mode 100644 index 00000000..8efc49c7 --- /dev/null +++ b/src/ui/WorkSpace/BaseAddFileDlg.cpp @@ -0,0 +1,161 @@ +#include "BaseAddFileDlg.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "app/Application.h" +#include "common/SpdLogger.h" + +BaseAddFileDlg::BaseAddFileDlg(FileEntryType fileType, QWidget* parent) + : Dialog(parent) + , fileType_(fileType) + , leFilePath_(nullptr) + , tbSelectFile_(nullptr) + , lblFileName_(nullptr) + , lblFileSize_(nullptr) + , teDescription_(nullptr) { + + //setupBaseUI(); + initBaseConnect(); +} + +BaseAddFileDlg::~BaseAddFileDlg() { +} + +FileEntryType BaseAddFileDlg::getSelectedFileType() const { + return fileType_; +} + +QString BaseAddFileDlg::getSelectedFilePath() const { + return selectedFilePath_; +} + +QString BaseAddFileDlg::getDescription() const { + return teDescription_->toPlainText().trimmed(); +} + +void BaseAddFileDlg::setupBaseUI() { + setFixedSize(500, 400); + + QVBoxLayout* mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(20, 20, 20, 20); + mainLayout->setSpacing(15); + + QGroupBox* fileGroup = new QGroupBox(QStringLiteral("File Selection"), this); + QGridLayout* fileLayout = new QGridLayout(fileGroup); + + QLabel* pathLabel = new QLabel(QStringLiteral("File Path:"), this); + leFilePath_ = new QLineEdit(this); + leFilePath_->setReadOnly(true); + tbSelectFile_ = new QToolButton(this); + tbSelectFile_->setText(QStringLiteral("...")); + tbSelectFile_->setFixedSize(30, 25); + + fileLayout->addWidget(pathLabel, 0, 0); + fileLayout->addWidget(leFilePath_, 0, 1); + fileLayout->addWidget(tbSelectFile_, 0, 2); + + mainLayout->addWidget(fileGroup); + + QGroupBox* infoGroup = new QGroupBox(QStringLiteral("File Information"), this); + QGridLayout* infoLayout = new QGridLayout(infoGroup); + + QLabel* nameLabel = new QLabel(QStringLiteral("File Name:"), this); + lblFileName_ = new QLabel(QStringLiteral("No file selected"), this); + QLabel* sizeLabel = new QLabel(QStringLiteral("File Size:"), this); + lblFileSize_ = new QLabel(QStringLiteral("0 bytes"), this); + + infoLayout->addWidget(nameLabel, 0, 0); + infoLayout->addWidget(lblFileName_, 0, 1); + infoLayout->addWidget(sizeLabel, 1, 0); + infoLayout->addWidget(lblFileSize_, 1, 1); + + mainLayout->addWidget(infoGroup); + + QGroupBox* descGroup = new QGroupBox(QStringLiteral("Description"), this); + QVBoxLayout* descLayout = new QVBoxLayout(descGroup); + teDescription_ = new QTextEdit(this); + teDescription_->setMaximumHeight(80); + descLayout->addWidget(teDescription_); + mainLayout->addWidget(descGroup); + +} + +void BaseAddFileDlg::initBaseConnect() { + connect(tbSelectFile_, &QToolButton::clicked, this, &BaseAddFileDlg::OnSelectFile); +} + +void BaseAddFileDlg::OnSelectFile() { + const QString workspacePath = Application::GetWorkSpacePath(); + QString filePath = QFileDialog::getOpenFileName( + this, + QStringLiteral("Select File"), + workspacePath, + getFileFilter() + ); + + if (filePath.isEmpty()) { + return; + } + + selectedFilePath_ = filePath; + leFilePath_->setText(filePath); + updateFileInfo(filePath); + + LOG_INFO("Selected file: {}", filePath.toStdString()); +} + +void BaseAddFileDlg::OnSure() { + if (!validateBaseInput() || !validateSpecificParams()) { + return; + } + + accept(); +} + +void BaseAddFileDlg::updateFileInfo(const QString& filePath) { + QFileInfo fileInfo(filePath); + lblFileName_->setText(fileInfo.fileName()); + + qint64 size = fileInfo.size(); + QString sizeText; + if (size < 1024) { + sizeText = QString("%1 B").arg(size); + } else if (size < 1024 * 1024) { + sizeText = QString("%1 KB").arg(size / 1024.0, 0, 'f', 1); + } else { + sizeText = QString("%1 MB").arg(size / (1024.0 * 1024.0), 0, 'f', 1); + } + lblFileSize_->setText(sizeText); +} + +bool BaseAddFileDlg::validateBaseInput() { + if (selectedFilePath_.isEmpty()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("Please select a file first.")); + return false; + } + + QFileInfo fileInfo(selectedFilePath_); + if (!fileInfo.exists()) { + QMessageBox::warning(this, QStringLiteral("Warning"), + QStringLiteral("Selected file does not exist.")); + return false; + } + + return true; +} + +void BaseAddFileDlg::SetTitle(const QString& title) { + Dialog::SetTitle(title); +} \ No newline at end of file diff --git a/src/ui/WorkSpace/BaseAddFileDlg.h b/src/ui/WorkSpace/BaseAddFileDlg.h new file mode 100644 index 00000000..4de55b03 --- /dev/null +++ b/src/ui/WorkSpace/BaseAddFileDlg.h @@ -0,0 +1,52 @@ +#pragma once + +#include "ui/Dialog.h" +#include "workspace/FileEntry.h" + +#include +#include + + +class QLineEdit; +class QLabel; +class QTextEdit; +class QToolButton; + +class BaseAddFileDlg : public Dialog { + Q_OBJECT + +public: + explicit BaseAddFileDlg(FileEntryType fileType, QWidget* parent = nullptr); + virtual ~BaseAddFileDlg(); + + FileEntryType getSelectedFileType() const; + QString getSelectedFilePath() const; + QString getDescription() const; + + virtual bool validateSpecificParams() = 0; + virtual QString getFileFilter() const = 0; + virtual QString getDialogTitle() const = 0; + +protected slots: + void OnSelectFile(); + void OnSure(); + +protected: + QLineEdit* leFilePath_; + QToolButton* tbSelectFile_; + QLabel* lblFileName_; + QLabel* lblFileSize_; + QTextEdit* teDescription_; + + void setupBaseUI(); + void initBaseConnect(); + void updateFileInfo(const QString& filePath); + bool validateBaseInput(); + void SetTitle(const QString& title); + + virtual void setupSpecificUI() = 0; + +private: + FileEntryType fileType_; + QString selectedFilePath_; +}; \ No newline at end of file