"Fossies" - the Fresh Open Source Software Archive

Member "labplot-2.8.2/src/kdefrontend/spreadsheet/ExportSpreadsheetDialog.cpp" (24 Feb 2021, 18678 Bytes) of package /linux/privat/labplot-2.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ExportSpreadsheetDialog.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.8.1_vs_2.8.2.

    1 /***************************************************************************
    2     File                 : ExportSpreadsheetDialog.cpp
    3     Project              : LabPlot
    4     Description          : export spreadsheet dialog
    5     --------------------------------------------------------------------
    6     Copyright            : (C) 2014-2019 by Alexander Semke (alexander.semke@web.de)
    7 
    8  ***************************************************************************/
    9 
   10 /***************************************************************************
   11  *                                                                         *
   12  *  This program is free software; you can redistribute it and/or modify   *
   13  *  it under the terms of the GNU General Public License as published by   *
   14  *  the Free Software Foundation; either version 2 of the License, or      *
   15  *  (at your option) any later version.                                    *
   16  *                                                                         *
   17  *  This program is distributed in the hope that it will be useful,        *
   18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
   19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
   20  *  GNU General Public License for more details.                           *
   21  *                                                                         *
   22  *   You should have received a copy of the GNU General Public License     *
   23  *   along with this program; if not, write to the Free Software           *
   24  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
   25  *   Boston, MA  02110-1301  USA                                           *
   26  *                                                                         *
   27  ***************************************************************************/
   28 
   29 #include "ExportSpreadsheetDialog.h"
   30 #include "ui_exportspreadsheetwidget.h"
   31 #include "backend/datasources/filters/AbstractFileFilter.h"
   32 #include "backend/datasources/filters/AsciiFilter.h"
   33 #include "kdefrontend/GuiTools.h"
   34 
   35 #include <QCompleter>
   36 #include <QDirModel>
   37 #include <QFileDialog>
   38 #include <QStandardItemModel>
   39 #include <QDialogButtonBox>
   40 #include <QSqlDatabase>
   41 #include <QWindow>
   42 
   43 #include <KMessageBox>
   44 #include <KLocalizedString>
   45 #include <KConfigGroup>
   46 #include <KSharedConfig>
   47 #include <KWindowConfig>
   48 
   49 /*!
   50     \class ExportSpreadsheetDialog
   51     \brief Dialog for exporting a spreadsheet to a file.
   52 
   53     \ingroup kdefrontend
   54 */
   55 ExportSpreadsheetDialog::ExportSpreadsheetDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ExportSpreadsheetWidget()) {
   56     ui->setupUi(this);
   57 
   58     ui->gbOptions->hide();
   59 
   60     auto* btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
   61     m_showOptionsButton = new QPushButton;
   62 
   63     connect(btnBox, &QDialogButtonBox::clicked, this, &ExportSpreadsheetDialog::slotButtonClicked);
   64 
   65     btnBox->addButton(m_showOptionsButton, QDialogButtonBox::ActionRole);
   66     ui->verticalLayout->addWidget(btnBox);
   67 
   68     m_okButton = btnBox->button(QDialogButtonBox::Ok);
   69     m_cancelButton = btnBox->button(QDialogButtonBox::Cancel);
   70 
   71     ui->leFileName->setCompleter(new QCompleter(new QDirModel, this));
   72 
   73     ui->cbFormat->addItem("ASCII", static_cast<int>(Format::ASCII));
   74     ui->cbFormat->addItem("Binary", static_cast<int>(Format::Binary));
   75     ui->cbFormat->addItem("LaTeX", static_cast<int>(Format::LaTeX));
   76     ui->cbFormat->addItem("FITS", static_cast<int>(Format::FITS));
   77 
   78     const QStringList& drivers = QSqlDatabase::drivers();
   79     if (drivers.contains(QLatin1String("QSQLITE")) || drivers.contains(QLatin1String("QSQLITE3")))
   80         ui->cbFormat->addItem("SQLite", static_cast<int>(Format::SQLite));
   81 
   82     QStringList separators = AsciiFilter::separatorCharacters();
   83     separators.takeAt(0); //remove the first entry "auto"
   84     ui->cbSeparator->addItems(separators);
   85 
   86     //TODO: use general setting for decimal separator?
   87     ui->cbDecimalSeparator->addItem(i18n("Point '.'"));
   88     ui->cbDecimalSeparator->addItem(i18n("Comma ','"));
   89 
   90     ui->cbLaTeXExport->addItem(i18n("Export Spreadsheet"));
   91     ui->cbLaTeXExport->addItem(i18n("Export Selection"));
   92 
   93     ui->bOpen->setIcon( QIcon::fromTheme("document-open") );
   94 
   95     ui->leFileName->setFocus();
   96 
   97     const QString textNumberFormatShort = i18n("This option determines how the convert numbers to strings.");
   98     ui->lDecimalSeparator->setToolTip(textNumberFormatShort);
   99     ui->lDecimalSeparator->setToolTip(textNumberFormatShort);
  100 
  101     connect(ui->bOpen, &QPushButton::clicked, this, &ExportSpreadsheetDialog::selectFile);
  102     connect(ui->leFileName, &QLineEdit::textChanged, this, &ExportSpreadsheetDialog::fileNameChanged );
  103     connect(m_showOptionsButton, &QPushButton::clicked, this, &ExportSpreadsheetDialog::toggleOptions);
  104     connect(ui->cbFormat, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &ExportSpreadsheetDialog::formatChanged);
  105     connect(ui->cbExportToFITS, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &ExportSpreadsheetDialog::fitsExportToChanged);
  106 
  107     setWindowTitle(i18nc("@title:window", "Export Spreadsheet"));
  108     setWindowIcon(QIcon::fromTheme("document-export-database"));
  109 
  110     //restore saved settings if available
  111     KConfigGroup conf(KSharedConfig::openConfig(), "ExportSpreadsheetDialog");
  112     KWindowConfig::restoreWindowSize(windowHandle(), conf);
  113     ui->cbFormat->setCurrentIndex(conf.readEntry("Format", 0));
  114     ui->chkExportHeader->setChecked(conf.readEntry("Header", true));
  115     ui->cbSeparator->setCurrentItem(conf.readEntry("Separator", "TAB"));
  116 
  117     //TODO: use general setting for decimal separator?
  118     const QChar decimalSeparator = QLocale().decimalPoint();
  119     int index = (decimalSeparator == '.') ? 0 : 1;
  120     ui->cbDecimalSeparator->setCurrentIndex(conf.readEntry("DecimalSeparator", index));
  121 
  122     ui->chkHeaders->setChecked(conf.readEntry("LaTeXHeaders", true));
  123     ui->chkGridLines->setChecked(conf.readEntry("LaTeXGridLines", true));
  124     ui->chkCaptions->setChecked(conf.readEntry("LaTeXCaptions", true));
  125     ui->chkEmptyRows->setChecked(conf.readEntry("LaTeXSkipEmpty", false));
  126     ui->cbLaTeXExport->setCurrentIndex(conf.readEntry("ExportOnly", 0));
  127     ui->chkMatrixHHeader->setChecked(conf.readEntry("MatrixHorizontalHeader", true));
  128     ui->chkMatrixVHeader->setChecked(conf.readEntry("MatrixVerticalHeader", true));
  129     ui->chkMatrixVHeader->setChecked(conf.readEntry("FITSSpreadsheetColumnsUnits", true));
  130     ui->cbExportToFITS->setCurrentIndex(conf.readEntry("FITSTo", 0));
  131     m_showOptions = conf.readEntry("ShowOptions", false);
  132     ui->gbOptions->setVisible(m_showOptions);
  133     m_showOptions ? m_showOptionsButton->setText(i18n("Hide Options")) :
  134             m_showOptionsButton->setText(i18n("Show Options"));
  135 
  136     create(); // ensure there's a window created
  137     if (conf.exists()) {
  138         KWindowConfig::restoreWindowSize(windowHandle(), conf);
  139         resize(windowHandle()->size()); // workaround for QTBUG-40584
  140     } else
  141         resize(QSize(0, 0).expandedTo(minimumSize()));
  142 }
  143 
  144 ExportSpreadsheetDialog::~ExportSpreadsheetDialog() {
  145     //save current settings
  146     KConfigGroup conf(KSharedConfig::openConfig(), "ExportSpreadsheetDialog");
  147     conf.writeEntry("Format", ui->cbFormat->currentIndex());
  148     conf.writeEntry("Header", ui->chkExportHeader->isChecked());
  149     conf.writeEntry("Separator", ui->cbSeparator->currentText());
  150     conf.writeEntry("DecimalSeparator", ui->cbDecimalSeparator->currentIndex());
  151     conf.writeEntry("ShowOptions", m_showOptions);
  152     conf.writeEntry("LaTeXHeaders", ui->chkHeaders->isChecked());
  153     conf.writeEntry("LaTeXGridLines", ui->chkGridLines->isChecked());
  154     conf.writeEntry("LaTeXCaptions", ui->chkCaptions->isChecked());
  155     conf.writeEntry("LaTeXSkipEmpty", ui->chkEmptyRows->isChecked());
  156     conf.writeEntry("ExportOnly", ui->cbLaTeXExport->currentIndex());
  157     conf.writeEntry("MatrixVerticalHeader", ui->chkMatrixVHeader->isChecked());
  158     conf.writeEntry("MatrixHorizontalHeader", ui->chkMatrixHHeader->isChecked());
  159     conf.writeEntry("FITSTo", ui->cbExportToFITS->currentIndex());
  160     conf.writeEntry("FITSSpreadsheetColumnsUnits", ui->chkColumnsAsUnits->isChecked());
  161 
  162     KWindowConfig::saveWindowSize(windowHandle(), conf);
  163 }
  164 
  165 void ExportSpreadsheetDialog::setFileName(const QString& name) {
  166     KConfigGroup conf(KSharedConfig::openConfig(), "ExportSpreadsheetDialog");
  167     QString dir = conf.readEntry("LastDir", "");
  168     if (dir.isEmpty()) {    // use project dir as fallback
  169         KConfigGroup conf2(KSharedConfig::openConfig(), "MainWin");
  170         dir = conf2.readEntry("LastOpenDir", "");
  171         if (dir.isEmpty())
  172             dir = QDir::homePath();
  173     }
  174     ui->leFileName->setText(dir + QLatin1Char('/') + name);
  175     this->formatChanged(ui->cbFormat->currentIndex());
  176 }
  177 
  178 void ExportSpreadsheetDialog::fitsExportToChanged(int idx) {
  179     if (idx == 0) {
  180         ui->chkColumnsAsUnits->hide();
  181         ui->lColumnAsUnits->hide();
  182     } else {
  183         if (!m_matrixMode) {
  184             ui->chkColumnsAsUnits->show();
  185             ui->lColumnAsUnits->show();
  186         }
  187     }
  188 }
  189 
  190 void ExportSpreadsheetDialog::setMatrixMode(bool b) {
  191     if (b) {
  192         setWindowTitle(i18nc("@title:window", "Export Matrix"));
  193         ui->lExportHeader->hide();
  194         ui->chkExportHeader->hide();
  195         ui->lEmptyRows->hide();
  196         ui->chkEmptyRows->hide();
  197         if (ui->cbFormat->currentIndex() != 3) {
  198             ui->chkMatrixHHeader->show();
  199             ui->chkMatrixVHeader->show();
  200             ui->lMatrixHHeader->show();
  201             ui->lMatrixVHeader->show();
  202         }
  203 
  204         ui->lHeader->hide();
  205         ui->chkHeaders->hide();
  206         ui->cbLaTeXExport->setItemText(0,i18n("Export matrix"));
  207         ui->cbExportToFITS->setCurrentIndex(0);
  208 
  209         ui->lColumnAsUnits->hide();
  210         ui->chkColumnsAsUnits->hide();
  211 
  212         m_matrixMode = b;
  213     }
  214 }
  215 
  216 QString ExportSpreadsheetDialog::path() const {
  217     return ui->leFileName->text();
  218 }
  219 
  220 int ExportSpreadsheetDialog::exportToFits() const {
  221     return ui->cbExportToFITS->currentIndex();
  222 }
  223 
  224 bool ExportSpreadsheetDialog::exportHeader() const {
  225     return ui->chkExportHeader->isChecked();
  226 }
  227 
  228 bool ExportSpreadsheetDialog::captions() const {
  229     return ui->chkCaptions->isChecked();
  230 }
  231 
  232 bool ExportSpreadsheetDialog::exportLatexHeader() const {
  233     return ui->chkHeaders->isChecked();
  234 }
  235 
  236 bool ExportSpreadsheetDialog::gridLines() const {
  237     return ui->chkGridLines->isChecked();
  238 }
  239 
  240 bool ExportSpreadsheetDialog::skipEmptyRows() const {
  241     return ui->chkEmptyRows->isChecked();
  242 }
  243 
  244 bool ExportSpreadsheetDialog::exportSelection() const {
  245     return ui->cbLaTeXExport->currentIndex() == 1;
  246 }
  247 
  248 bool ExportSpreadsheetDialog::entireSpreadheet() const {
  249     return ui->cbLaTeXExport->currentIndex() == 0;
  250 }
  251 
  252 bool ExportSpreadsheetDialog::matrixHorizontalHeader() const {
  253     return ui->chkMatrixHHeader->isChecked();
  254 }
  255 
  256 bool ExportSpreadsheetDialog::matrixVerticalHeader() const {
  257     return ui->chkMatrixVHeader->isChecked();
  258 }
  259 
  260 bool ExportSpreadsheetDialog::commentsAsUnitsFits() const {
  261     return ui->chkColumnsAsUnits->isChecked();
  262 }
  263 
  264 QString ExportSpreadsheetDialog::separator() const {
  265     return ui->cbSeparator->currentText();
  266 }
  267 
  268 QLocale::Language ExportSpreadsheetDialog::numberFormat() const {
  269     if (ui->cbDecimalSeparator->currentIndex() == 0)
  270         return QLocale::Language::C;
  271     else
  272         return QLocale::Language::German;
  273 }
  274 
  275 void ExportSpreadsheetDialog::slotButtonClicked(QAbstractButton* button) {
  276     if (button == m_okButton)
  277         okClicked();
  278     else if (button == m_cancelButton) {
  279         reject();
  280     }
  281 }
  282 
  283 void ExportSpreadsheetDialog::setExportToImage(bool possible) {
  284     if (!possible) {
  285         ui->cbExportToFITS->setCurrentIndex(1);
  286         ui->cbExportToFITS->setItemData(0, 0, Qt::UserRole - 1);
  287     }
  288 }
  289 
  290 //SLOTS
  291 void ExportSpreadsheetDialog::okClicked() {
  292     if (format() != Format::FITS)
  293         if ( QFile::exists(ui->leFileName->text()) ) {
  294             int r = KMessageBox::questionYesNo(this, i18n("The file already exists. Do you really want to overwrite it?"), i18n("Export"));
  295             if (r == KMessageBox::No)
  296                 return;
  297         }
  298     KConfigGroup conf(KSharedConfig::openConfig(), "ExportSpreadsheetDialog");
  299     conf.writeEntry("Format", ui->cbFormat->currentIndex());
  300     conf.writeEntry("Header", ui->chkExportHeader->isChecked());
  301     conf.writeEntry("Separator", ui->cbSeparator->currentText());
  302 
  303     QString path = ui->leFileName->text();
  304     if (!path.isEmpty()) {
  305         QString dir = conf.readEntry("LastDir", "");
  306         int pos = path.lastIndexOf(QLatin1String("/"));
  307         if (pos != -1) {
  308             QString newDir = path.left(pos);
  309             if (newDir != dir)
  310                 conf.writeEntry("LastDir", newDir);
  311         }
  312     }
  313 
  314     accept();
  315 }
  316 
  317 /*!
  318     Shows/hides the GroupBox with export options in this dialog.
  319 */
  320 void ExportSpreadsheetDialog::toggleOptions() {
  321     m_showOptions = !m_showOptions;
  322     ui->gbOptions->setVisible(m_showOptions);
  323     m_showOptions ? m_showOptionsButton->setText(i18n("Hide Options")) :
  324             m_showOptionsButton->setText(i18n("Show Options")); //resize the dialog
  325     resize(layout()->minimumSize());
  326     layout()->activate();
  327     resize( QSize(this->width(),0).expandedTo(minimumSize()) );
  328 }
  329 
  330 /*!
  331     opens a file dialog and lets the user select the file.
  332 */
  333 void ExportSpreadsheetDialog::selectFile() {
  334     KConfigGroup conf(KSharedConfig::openConfig(), "ExportSpreadsheetDialog");
  335     QString dir = conf.readEntry("LastDir", "");
  336 
  337     QString extensions;
  338     const Format format = (Format)(ui->cbFormat->itemData(ui->cbFormat->currentIndex()).toInt());
  339     switch (format) {
  340     case Format::ASCII:
  341         extensions = i18n("Text files (*.txt *.dat *.csv)");
  342         break;
  343     case Format::Binary:
  344         extensions = i18n("Binary files (*.*)");
  345         break;
  346     case Format::LaTeX:
  347         extensions = i18n("LaTeX files (*.tex)");
  348         break;
  349     case Format::FITS:
  350         extensions = i18n("FITS files (*.fits *.fit *.fts)");
  351         break;
  352     case Format::SQLite:
  353         extensions = i18n("SQLite databases files (*.db *.sqlite *.sdb *.db2 *.sqlite2 *.sdb2 *.db3 *.sqlite3 *.sdb3)");
  354         break;
  355     }
  356 
  357     const QString path = QFileDialog::getSaveFileName(this, i18n("Export to file"), dir, extensions);
  358     if (!path.isEmpty()) {
  359         ui->leFileName->setText(path);
  360 
  361         int pos = path.lastIndexOf(QLatin1String("/"));
  362         if (pos != -1) {
  363             QString newDir = path.left(pos);
  364             if (newDir != dir)
  365                 conf.writeEntry("LastDir", newDir);
  366         }
  367     }
  368 }
  369 
  370 /*!
  371     called when the output format was changed. Adjusts the extension for the specified file.
  372  */
  373 void ExportSpreadsheetDialog::formatChanged(int index) {
  374     QStringList extensions;
  375     extensions << ".txt" << ".bin" << ".tex" << ".fits" << ".db";
  376     QString path = ui->leFileName->text();
  377     int i = path.indexOf(".");
  378     if (index != -1) {
  379         if (i == -1)
  380             path = path + extensions.at(index);
  381         else
  382             path = path.left(i) + extensions.at(index);
  383     }
  384 
  385     const Format format = Format(ui->cbFormat->itemData(ui->cbFormat->currentIndex()).toInt());
  386     if (format == Format::LaTeX) {
  387         ui->cbSeparator->hide();
  388         ui->lSeparator->hide();
  389         ui->lDecimalSeparator->hide();
  390         ui->cbDecimalSeparator->hide();
  391 
  392         ui->chkCaptions->show();
  393         ui->chkGridLines->show();
  394         ui->lExportArea->show();
  395         ui->lGridLines->show();
  396         ui->lCaptions->show();
  397         ui->cbLaTeXExport->show();
  398 
  399         if (!m_matrixMode) {
  400             ui->lHeader->show();
  401             ui->chkHeaders->show();
  402             ui->lEmptyRows->show();
  403             ui->chkEmptyRows->show();
  404             ui->lMatrixHHeader->hide();
  405             ui->lMatrixVHeader->hide();
  406             ui->chkMatrixHHeader->hide();
  407             ui->chkMatrixVHeader->hide();
  408         } else {
  409             ui->lMatrixHHeader->show();
  410             ui->lMatrixVHeader->show();
  411             ui->chkMatrixHHeader->show();
  412             ui->chkMatrixVHeader->show();
  413         }
  414         ui->cbExportToFITS->hide();
  415         ui->lExportToFITS->hide();
  416         ui->lColumnAsUnits->hide();
  417         ui->chkColumnsAsUnits->hide();
  418     } else if (format == Format::FITS) {
  419         ui->lCaptions->hide();
  420         ui->lEmptyRows->hide();
  421         ui->lExportArea->hide();
  422         ui->lGridLines->hide();
  423         ui->lMatrixHHeader->hide();
  424         ui->lMatrixVHeader->hide();
  425         ui->lSeparator->hide();
  426         ui->lHeader->hide();
  427         ui->chkEmptyRows->hide();
  428         ui->chkHeaders->hide();
  429         ui->chkExportHeader->hide();
  430         ui->lExportHeader->hide();
  431         ui->chkGridLines->hide();
  432         ui->chkMatrixHHeader->hide();
  433         ui->chkMatrixVHeader->hide();
  434         ui->chkCaptions->hide();
  435         ui->cbLaTeXExport->hide();
  436         ui->cbSeparator->hide();
  437         ui->lDecimalSeparator->hide();
  438         ui->cbDecimalSeparator->hide();
  439 
  440         ui->cbExportToFITS->show();
  441         ui->lExportToFITS->show();
  442         if (!m_matrixMode) {
  443             if (ui->cbExportToFITS->currentIndex() == 1) {
  444                 ui->lColumnAsUnits->show();
  445                 ui->chkColumnsAsUnits->show();
  446             }
  447         }
  448     } else if (format == Format::SQLite) {
  449         ui->cbSeparator->hide();
  450         ui->lSeparator->hide();
  451         ui->lDecimalSeparator->hide();
  452         ui->cbDecimalSeparator->hide();
  453 
  454         ui->chkCaptions->hide();
  455         ui->chkEmptyRows->hide();
  456         ui->chkGridLines->hide();
  457         ui->lEmptyRows->hide();
  458         ui->lExportArea->hide();
  459         ui->lGridLines->hide();
  460         ui->lCaptions->hide();
  461         ui->cbLaTeXExport->hide();
  462         ui->cbLaTeXExport->hide();
  463         ui->lMatrixHHeader->hide();
  464         ui->lMatrixVHeader->hide();
  465         ui->chkMatrixHHeader->hide();
  466         ui->chkMatrixVHeader->hide();
  467 
  468         ui->lHeader->hide();
  469         ui->chkHeaders->hide();
  470         ui->chkExportHeader->hide();
  471         ui->lExportHeader->hide();
  472 
  473         ui->cbExportToFITS->hide();
  474         ui->lExportToFITS->hide();
  475         ui->lColumnAsUnits->hide();
  476         ui->chkColumnsAsUnits->hide();
  477     } else {
  478         ui->cbSeparator->show();
  479         ui->lSeparator->show();
  480         ui->lDecimalSeparator->show();
  481         ui->cbDecimalSeparator->show();
  482 
  483         ui->chkCaptions->hide();
  484         ui->chkEmptyRows->hide();
  485         ui->chkGridLines->hide();
  486         ui->lEmptyRows->hide();
  487         ui->lExportArea->hide();
  488         ui->lGridLines->hide();
  489         ui->lCaptions->hide();
  490         ui->cbLaTeXExport->hide();
  491         ui->lMatrixHHeader->hide();
  492         ui->lMatrixVHeader->hide();
  493         ui->chkMatrixHHeader->hide();
  494         ui->chkMatrixVHeader->hide();
  495 
  496         ui->lHeader->hide();
  497         ui->chkHeaders->hide();
  498 
  499         ui->cbExportToFITS->hide();
  500         ui->lExportToFITS->hide();
  501         ui->lColumnAsUnits->hide();
  502         ui->chkColumnsAsUnits->hide();
  503     }
  504 
  505     if (!m_matrixMode && !(format == Format::FITS || format == Format::SQLite)) {
  506         ui->chkExportHeader->show();
  507         ui->lExportHeader->show();
  508     }
  509 
  510     setFormat(static_cast<Format>(index));
  511     ui->leFileName->setText(path);
  512 }
  513 
  514 void ExportSpreadsheetDialog::setExportSelection(bool enable) {
  515     if (!enable) {
  516         const auto* areaToExportModel = qobject_cast<const QStandardItemModel*>(ui->cbLaTeXExport->model());
  517         QStandardItem* item = areaToExportModel->item(1);
  518         item->setFlags(item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled));
  519     }
  520 }
  521 
  522 void ExportSpreadsheetDialog::setFormat(Format format) {
  523     m_format = format;
  524 }
  525 
  526 void ExportSpreadsheetDialog::setExportTo(const QStringList &to) {
  527     ui->cbExportToFITS->addItems(to);
  528 }
  529 
  530 ExportSpreadsheetDialog::Format ExportSpreadsheetDialog::format() const {
  531     return m_format;
  532 }
  533 
  534 void ExportSpreadsheetDialog::fileNameChanged(const QString& name) {
  535     if (name.simplified().isEmpty()) {
  536         m_okButton->setEnabled(false);
  537         return;
  538     }
  539     QString path = ui->leFileName->text();
  540     int pos = path.lastIndexOf(QLatin1String("/"));
  541     if (pos != -1) {
  542         QString dir = path.left(pos);
  543         bool invalid = !QDir(dir).exists();
  544         GuiTools::highlight(ui->leFileName, invalid);
  545         if (invalid) {
  546             m_okButton->setEnabled(false);
  547             return;
  548         }
  549     }
  550 
  551     m_okButton->setEnabled(true);
  552 }