/**************************************************************************** ** ** Copyright (C) 2020 Minnesota Department of Transportation ** Office of Materials & Road Research ** 1400 Gervais Avenue ** Saint Paul, Minnesota 55109-2044 ** USA ** http://www.dot.state.mn.us/app/pavecool ** ** ** $QT_BEGIN_LICENSE:GPL$ ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** If you did not receive a copy of the GNU General Public License ** see http://www.gnu.org/licenses ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "pcfiledlg.h" #include "ui_pcfiledlg.h" pcFileDlg::pcFileDlg(QWidget *parent) : QDialog(parent), ui(new Ui::pcFileDlg) { ui->setupUi(this); tfilters << "*.xls" << "*.csv" << "*.txt" << "*.pc3" << "*.pdf"; } pcFileDlg::~pcFileDlg() { delete ui; } void pcFileDlg::updateView() { tdisp = dispName(tdisp); ui->fileEdit->setText(tdisp); ui->dirLabel->setText(tdir); if(ntype > 2) // cs3 or pdf { ui->typeLabel->setHidden(true); ui->typeCombo->setHidden(true); } else ui->typeCombo->setCurrentIndex(ntype); tfilt.clear(); tfilt << tfilters[ntype]; pdir.setCurrent(tdir); pdir.setNameFilters(tfilt); pdir.setSorting(QDir::Name); if(bopen) ui->fileButtonBox->setStandardButtons(QDialogButtonBox::Open | QDialogButtonBox::Cancel); ui->fileList->clear(); ui->fileList->addItems(pdir.entryList()); } void pcFileDlg::on_fileEdit_textEdited(const QString &arg1) { ttmp = arg1; } void pcFileDlg::on_fileEdit_editingFinished() { if(!ttmp.isEmpty()) { tdisp = dispName(ttmp); ui->fileEdit->setText(tdisp); } } void pcFileDlg::on_fileList_itemClicked(QListWidgetItem *item) { tdisp = dispName(item->text()); ui->fileEdit->setText(tdisp); } void pcFileDlg::on_fileButtonBox_clicked(QAbstractButton *button) { tsave = tdir + "/" + tfilt[0]; tsave = tsave.replace("*", tdisp); QFileInfo mInfo(tsave); if(button->text() == "Save" && mInfo.exists()) { QMessageBox msg; msg.setText(mInfo.fileName() + " " + tr("already exists.")); msg.setInformativeText(tr("Replace") + " " + mInfo.fileName() + "?"); msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); msg.setDefaultButton(QMessageBox::No); int nret = msg.exec(); if(nret == QMessageBox::Yes) accept(); else if(nret == QMessageBox::Cancel) reject(); } else if(button->text() != "Cancel") accept(); } void pcFileDlg::on_typeCombo_currentIndexChanged(int index) { ntype = index; updateView(); } QString pcFileDlg::dispName(const QString &fName) {// remove extension QString ttmp = fName; int nlen = ttmp.length(); if(nlen > 4 && ttmp.at(nlen-4) == '.') ttmp = ttmp.left(nlen-4); return ttmp; }