"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/kdefrontend/datasources/ImportProjectDialog.cpp" between
labplot-2.8.1.tar.gz and labplot-2.8.2.tar.gz

About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.

ImportProjectDialog.cpp  (labplot-2.8.1):ImportProjectDialog.cpp  (labplot-2.8.2)
/*************************************************************************** /***************************************************************************
File : ImportProjectDialog.cpp File : ImportProjectDialog.cpp
Project : LabPlot Project : LabPlot
Description : import project dialog Description : import project dialog
-------------------------------------------------------------------- --------------------------------------------------------------------
Copyright : (C) 2017-2019 Alexander Semke (alexander.semke@web.de ) Copyright : (C) 2017-2021 Alexander Semke (alexander.semke@web.de )
***************************************************************************/ ***************************************************************************/
/*************************************************************************** /***************************************************************************
* * * *
* This program is free software; you can redistribute it and/or modify * * 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 * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
skipping to change at line 52 skipping to change at line 52
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog> #include <QInputDialog>
#include <QProgressBar> #include <QProgressBar>
#include <QStatusBar> #include <QStatusBar>
#include <QWindow> #include <QWindow>
#include <KLocalizedString> #include <KLocalizedString>
#include <KMessageBox> #include <KMessageBox>
#include <KSharedConfig> #include <KSharedConfig>
#include <KUrlComboBox>
#include <KWindowConfig> #include <KWindowConfig>
/*! /*!
\class ImportProjectDialog \class ImportProjectDialog
\brief Dialog for importing project files. \brief Dialog for importing project files.
\ingroup kdefrontend \ingroup kdefrontend
*/ */
ImportProjectDialog::ImportProjectDialog(MainWin* parent, ProjectType type) : QD ialog(parent), ImportProjectDialog::ImportProjectDialog(MainWin* parent, ProjectType type) : QD ialog(parent),
m_mainWin(parent), m_mainWin(parent),
m_projectType(type), m_projectType(type),
m_aspectTreeModel(new AspectTreeModel(parent->project())) { m_aspectTreeModel(new AspectTreeModel(parent->project())) {
auto* vLayout = new QVBoxLayout(this); auto* vLayout = new QVBoxLayout(this);
//main widget //main widget
QWidget* mainWidget = new QWidget(this); QWidget* mainWidget = new QWidget(this);
ui.setupUi(mainWidget); ui.setupUi(mainWidget);
ui.chbUnusedObjects->hide(); ui.chbUnusedObjects->hide();
m_cbFileName = new KUrlComboBox(KUrlComboBox::Mode::Files, this);
m_cbFileName->setMaxItems(7);
auto* l = dynamic_cast<QHBoxLayout*>(ui.gbProject->layout());
if (l)
l->insertWidget(1, m_cbFileName);
vLayout->addWidget(mainWidget); vLayout->addWidget(mainWidget);
ui.tvPreview->setAnimated(true); ui.tvPreview->setAnimated(true);
ui.tvPreview->setAlternatingRowColors(true); ui.tvPreview->setAlternatingRowColors(true);
ui.tvPreview->setSelectionBehavior(QAbstractItemView::SelectRows); ui.tvPreview->setSelectionBehavior(QAbstractItemView::SelectRows);
ui.tvPreview->setSelectionMode(QAbstractItemView::ExtendedSelection); ui.tvPreview->setSelectionMode(QAbstractItemView::ExtendedSelection);
ui.tvPreview->setUniformRowHeights(true); ui.tvPreview->setUniformRowHeights(true);
ui.bOpen->setIcon( QIcon::fromTheme("document-open") ); ui.bOpen->setIcon( QIcon::fromTheme("document-open") );
skipping to change at line 103 skipping to change at line 111
ui.gbImportTo->layout()->addWidget(m_bNewFolder); ui.gbImportTo->layout()->addWidget(m_bNewFolder);
//dialog buttons //dialog buttons
m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBo x::Cancel); m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBo x::Cancel);
vLayout->addWidget(m_buttonBox); vLayout->addWidget(m_buttonBox);
//ok-button is only enabled if some project objects were selected (s.a. I mportProjectDialog::selectionChanged()) //ok-button is only enabled if some project objects were selected (s.a. I mportProjectDialog::selectionChanged())
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
//Signals/Slots //Signals/Slots
connect(ui.leFileName, &QLineEdit::textChanged, this, &ImportProjectDialo connect(m_cbFileName, &KUrlComboBox::urlActivated,
g::fileNameChanged); this, [=](const QUrl &url){fileNameChanged(url.path());})
;
connect(ui.bOpen, &QPushButton::clicked, this, &ImportProjectDialog::sele ctFile); connect(ui.bOpen, &QPushButton::clicked, this, &ImportProjectDialog::sele ctFile);
connect(m_bNewFolder, &QPushButton::clicked, this, &ImportProjectDialog:: newFolder); connect(m_bNewFolder, &QPushButton::clicked, this, &ImportProjectDialog:: newFolder);
connect(ui.chbUnusedObjects, &QCheckBox::stateChanged, this, &ImportProje ctDialog::refreshPreview); connect(ui.chbUnusedObjects, &QCheckBox::stateChanged, this, &ImportProje ctDialog::refreshPreview);
connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept) ; connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept) ;
connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject) ; connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject) ;
QString title; QString title;
switch (m_projectType) { switch (m_projectType) {
case ProjectType::LabPlot: case ProjectType::LabPlot:
m_projectParser = new LabPlotProjectParser(); m_projectParser = new LabPlotProjectParser();
skipping to change at line 130 skipping to change at line 139
#endif #endif
break; break;
} }
//dialog title and icon //dialog title and icon
setWindowTitle(title); setWindowTitle(title);
setWindowIcon(QIcon::fromTheme("document-import")); setWindowIcon(QIcon::fromTheme("document-import"));
//"What's this?" texts //"What's this?" texts
QString info = i18n("Specify the file where the project content has to be imported from."); QString info = i18n("Specify the file where the project content has to be imported from.");
ui.leFileName->setWhatsThis(info); m_cbFileName->setWhatsThis(info);
info = i18n("Select one or several objects to be imported into the curren t project.\n" info = i18n("Select one or several objects to be imported into the curren t project.\n"
"Note, all children of the selected objects as well as all th e dependent objects will be automatically selected.\n" "Note, all children of the selected objects as well as all th e dependent objects will be automatically selected.\n"
"To import the whole project, select the top-level project no de." "To import the whole project, select the top-level project no de."
); );
ui.tvPreview->setWhatsThis(info); ui.tvPreview->setWhatsThis(info);
info = i18n("Specify the target folder in the current project where the s elected objects have to be imported into."); info = i18n("Specify the target folder in the current project where the s elected objects have to be imported into.");
m_cbAddTo->setWhatsThis(info); m_cbAddTo->setWhatsThis(info);
//restore saved settings if available //restore saved settings if available
create(); // ensure there's a window created create(); // ensure there's a window created
KConfigGroup conf(KSharedConfig::openConfig(), "ImportProjectDialog"); KConfigGroup conf(KSharedConfig::openConfig(), "ImportProjectDialog");
if (conf.exists()) { if (conf.exists()) {
KWindowConfig::restoreWindowSize(windowHandle(), conf); KWindowConfig::restoreWindowSize(windowHandle(), conf);
resize(windowHandle()->size()); // workaround for QTBUG-40584 resize(windowHandle()->size()); // workaround for QTBUG-40584
} else } else
resize(QSize(300, 0).expandedTo(minimumSize())); resize(QSize(300, 0).expandedTo(minimumSize()));
QString lastImportedFile; QString file;
QString files;
switch (m_projectType) { switch (m_projectType) {
case ProjectType::LabPlot: case ProjectType::LabPlot:
lastImportedFile = QLatin1String("LastImportedLabPlotProject"); file = QLatin1String("LastImportedLabPlotProject");
files = QLatin1String("LastImportedLabPlotProjects");
break; break;
case ProjectType::Origin: case ProjectType::Origin:
lastImportedFile = QLatin1String("LastImportedOriginProject"); file = QLatin1String("LastImportedOriginProject");
files = QLatin1String("LastImportedOriginProjects");
break; break;
} }
QApplication::processEvents(QEventLoop::AllEvents, 100); QApplication::processEvents(QEventLoop::AllEvents, 100);
ui.leFileName->setText(conf.readEntry(lastImportedFile, "")); m_cbFileName->setUrl(conf.readEntry(file, ""));
QStringList urls = m_cbFileName->urls();
urls.append(conf.readXdgListEntry(files));
m_cbFileName->setUrls(urls);
fileNameChanged(m_cbFileName->currentText());
} }
ImportProjectDialog::~ImportProjectDialog() { ImportProjectDialog::~ImportProjectDialog() {
//save current settings //save current settings
KConfigGroup conf(KSharedConfig::openConfig(), "ImportProjectDialog"); KConfigGroup conf(KSharedConfig::openConfig(), "ImportProjectDialog");
KWindowConfig::saveWindowSize(windowHandle(), conf); KWindowConfig::saveWindowSize(windowHandle(), conf);
QString lastImportedFile; QString file;
QString files;
switch (m_projectType) { switch (m_projectType) {
case ProjectType::LabPlot: case ProjectType::LabPlot:
lastImportedFile = QLatin1String("LastImportedLabPlotProject"); file = QLatin1String("LastImportedLabPlotProject");
files = QLatin1String("LastImportedLabPlotProjects");
break; break;
case ProjectType::Origin: case ProjectType::Origin:
lastImportedFile = QLatin1String("LastImportedOriginProject"); file = QLatin1String("LastImportedOriginProject");
files = QLatin1String("LastImportedOriginProjects");
break; break;
} }
conf.writeEntry(lastImportedFile, ui.leFileName->text()); conf.writeEntry(file, m_cbFileName->currentText());
conf.writeXdgListEntry(files, m_cbFileName->urls());
} }
void ImportProjectDialog::setCurrentFolder(const Folder* folder) { void ImportProjectDialog::setCurrentFolder(const Folder* folder) {
m_cbAddTo->setCurrentModelIndex(m_aspectTreeModel->modelIndexOfAspect(fol der)); m_cbAddTo->setCurrentModelIndex(m_aspectTreeModel->modelIndexOfAspect(fol der));
} }
void ImportProjectDialog::importTo(QStatusBar* statusBar) const { void ImportProjectDialog::importTo(QStatusBar* statusBar) const {
DEBUG("ImportProjectDialog::importTo()"); DEBUG("ImportProjectDialog::importTo()");
//determine the selected objects, convert the model indexes to string pat hes //determine the selected objects, convert the model indexes to string pat hes
skipping to change at line 272 skipping to change at line 292
statusBar->showMessage( i18n("Project data imported in %1 seconds.", (flo at)timer.elapsed()/1000) ); statusBar->showMessage( i18n("Project data imported in %1 seconds.", (flo at)timer.elapsed()/1000) );
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
statusBar->removeWidget(progressBar); statusBar->removeWidget(progressBar);
} }
/*! /*!
* show the content of the project in the tree view * show the content of the project in the tree view
*/ */
void ImportProjectDialog::refreshPreview() { void ImportProjectDialog::refreshPreview() {
QString project = ui.leFileName->text(); const QString& project = m_cbFileName->currentText();
m_projectParser->setProjectFileName(project); m_projectParser->setProjectFileName(project);
#ifdef HAVE_LIBORIGIN #ifdef HAVE_LIBORIGIN
if (m_projectType == ProjectType::Origin) { if (m_projectType == ProjectType::Origin) {
auto* originParser = reinterpret_cast<OriginProjectParser*>(m_pro jectParser); auto* originParser = reinterpret_cast<OriginProjectParser*>(m_pro jectParser);
if (originParser->hasUnusedObjects()) if (originParser->hasUnusedObjects())
ui.chbUnusedObjects->show(); ui.chbUnusedObjects->show();
else else
ui.chbUnusedObjects->hide(); ui.chbUnusedObjects->hide();
skipping to change at line 344 skipping to change at line 364
//determine the dependent objects and select/deselect them too //determine the dependent objects and select/deselect them too
const QModelIndexList& indexes = selected.indexes(); const QModelIndexList& indexes = selected.indexes();
if (indexes.isEmpty()) if (indexes.isEmpty())
return; return;
//for the just selected aspect, determine all the objects it depends on a nd select them, too //for the just selected aspect, determine all the objects it depends on a nd select them, too
//TODO: we need a better "selection", maybe with tri-state check boxes in the tree view //TODO: we need a better "selection", maybe with tri-state check boxes in the tree view
const auto* aspect = static_cast<const AbstractAspect*>(indexes.at(0).int ernalPointer()); const auto* aspect = static_cast<const AbstractAspect*>(indexes.at(0).int ernalPointer());
const QVector<AbstractAspect*> aspects = aspect->dependsOn(); const QVector<AbstractAspect*> aspects = aspect->dependsOn();
const auto* model = reinterpret_cast<AspectTreeModel*>(ui.tvPreview->mode l()); const auto* model = reinterpret_cast<AspectTreeModel*>(ui.tvPreview->mode l());
for (const auto* aspect : aspects) { for (const auto* aspect : aspects) {
QModelIndex index = model->modelIndexOfAspect(aspect, 0); QModelIndex index = model->modelIndexOfAspect(aspect, 0);
ui.tvPreview->selectionModel()->select(index, QItemSelectionModel ::Select | QItemSelectionModel::Rows); ui.tvPreview->selectionModel()->select(index, QItemSelectionModel ::Select | QItemSelectionModel::Rows);
} }
//Ok-button is only enabled if some project objects were selected //Ok-button is only enabled if some project objects were selected
bool enable = (selected.indexes().size() != 0); bool enable = (selected.indexes().size() != 0);
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable); m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(enable);
if (enable) if (enable)
skipping to change at line 396 skipping to change at line 417
if (path.isEmpty()) if (path.isEmpty())
return; //cancel was clicked in the file-dialog return; //cancel was clicked in the file-dialog
int pos = path.lastIndexOf(QLatin1String("/")); int pos = path.lastIndexOf(QLatin1String("/"));
if (pos != -1) { if (pos != -1) {
QString newDir = path.left(pos); QString newDir = path.left(pos);
if (newDir != lastDir) if (newDir != lastDir)
conf.writeEntry(lastDirConfEntryName, newDir); conf.writeEntry(lastDirConfEntryName, newDir);
} }
ui.leFileName->setText(path); QStringList urls = m_cbFileName->urls();
urls.insert(0, QUrl::fromLocalFile(path).url());
m_cbFileName->setUrls(urls);
m_cbFileName->setCurrentText(urls.first());
fileNameChanged(path); // why do I have to call this function separately
refreshPreview(); refreshPreview();
} }
void ImportProjectDialog::fileNameChanged(const QString& name) { void ImportProjectDialog::fileNameChanged(const QString& name) {
QString fileName{name}; QString fileName{name};
// make relative path // make relative path
#ifdef HAVE_WINDOWS #ifdef HAVE_WINDOWS
if ( !fileName.isEmpty() && fileName.at(1) != QLatin1String(":")) if ( !fileName.isEmpty() && fileName.at(1) != QLatin1String(":"))
#else #else
if ( !fileName.isEmpty() && fileName.at(0) != QLatin1String("/")) if ( !fileName.isEmpty() && fileName.at(0) != QLatin1String("/"))
#endif #endif
fileName = QDir::homePath() + QLatin1String("/") + fileName; fileName = QDir::homePath() + QLatin1String("/") + fileName;
bool fileExists = QFile::exists(fileName); bool fileExists = QFile::exists(fileName);
GuiTools::highlight(ui.leFileName, !fileExists);
if (!fileExists) { if (!fileExists) {
//file doesn't exist -> delete the content preview that is still potentially //file doesn't exist -> delete the content preview that is still potentially
//available from the previously selected file //available from the previously selected file
ui.tvPreview->setModel(nullptr); ui.tvPreview->setModel(nullptr);
m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
return; return;
} }
refreshPreview(); refreshPreview();
} }
void ImportProjectDialog::newFolder() { void ImportProjectDialog::newFolder() {
QString path = ui.leFileName->text(); const QString& path = m_cbFileName->currentText();
QString name = path.right( path.length() - path.lastIndexOf(QLatin1String ("/"))-1 ); QString name = path.right( path.length() - path.lastIndexOf(QLatin1String ("/"))-1 );
bool ok; bool ok;
auto* dlg = new QInputDialog(this); auto* dlg = new QInputDialog(this);
name = dlg->getText(this, i18n("Add new folder"), i18n("Folder name:"), Q LineEdit::Normal, name, &ok); name = dlg->getText(this, i18n("Add new folder"), i18n("Folder name:"), Q LineEdit::Normal, name, &ok);
if (ok) { if (ok) {
auto* folder = new Folder(name); auto* folder = new Folder(name);
m_mainWin->addAspectToProject(folder); m_mainWin->addAspectToProject(folder);
m_cbAddTo->setCurrentModelIndex(m_mainWin->model()->modelIndexOfA spect(folder)); m_cbAddTo->setCurrentModelIndex(m_mainWin->model()->modelIndexOfA spect(folder));
} }
 End of changes. 18 change blocks. 
17 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)