Commit 147d8dbf authored by Alexander Semke's avatar Alexander Semke
Browse files

Minor changes:

* don't show any placeholder text in the help panel - we don't do this nowhere else, neither
* code style fixes in the file browser panel
* for panel plugins, set the plugin id as the object name so we can direclty work with it in LabPlot instead of 18n-ed plugin names
* minor cleanup in worksheet.cpp
parent 75177957
Pipeline #114663 passed with stage
in 18 minutes and 56 seconds
......@@ -42,6 +42,7 @@ void PanelPlugin::setPluginInfo(const KPluginMetaData& info)
{
d->name = info.name();
d->requiredExtensions = info.value(QStringLiteral("RequiredExtensions")).split(QLatin1Char(','));
setObjectName(info.pluginId());
}
QStringList PanelPlugin::requiredExtensions()
......
......@@ -13,7 +13,6 @@
#include <QDesktopServices>
#include <QUrl>
#include <QDebug>
#include <QFileInfo>
#include <QWidget>
#include <QVBoxLayout>
#include <QPushButton>
......@@ -25,11 +24,11 @@
#include <KParts/ReadOnlyPart>
FileBrowserPanelPlugin::FileBrowserPanelPlugin(QObject* parent, const QList<QVariant>& args): Cantor::PanelPlugin(parent),
m_mainWidget(nullptr), m_treeview(nullptr), m_pathEdit(nullptr), m_filterCombobox(nullptr), m_model(nullptr), historyBackCount(0)
m_mainWidget(nullptr), m_treeview(nullptr), m_pathEdit(nullptr), m_filterCombobox(nullptr)
{
Q_UNUSED(args);
KParts::ReadOnlyPart* part = dynamic_cast<KParts::ReadOnlyPart*>(parent->parent());
auto* part = dynamic_cast<KParts::ReadOnlyPart*>(parent->parent());
QString baseRootDir;
if (part && !part->url().isEmpty())
baseRootDir = QFileInfo(part->url().toLocalFile()).absoluteDir().absolutePath();
......@@ -56,10 +55,7 @@ QWidget* FileBrowserPanelPlugin::widget()
{
m_model = new QFileSystemModel();
m_model->setRootPath(m_rootDirsHistory.last());
constructMainWidget();
}
return m_mainWidget;
......@@ -98,71 +94,71 @@ void FileBrowserPanelPlugin::handleDoubleClicked(const QModelIndex& index)
void FileBrowserPanelPlugin::constructMainWidget()
{
m_mainWidget = new QWidget();
m_treeview = new QTreeView(m_mainWidget);
m_treeview->setModel(m_model);
m_treeview->setRootIndex(m_model->index(m_rootDirsHistory.last()));
m_treeview->setExpandsOnDoubleClick(false);
connect(m_treeview, &QTreeView::doubleClicked, this, &FileBrowserPanelPlugin::handleDoubleClicked);
// First column is name with the dir tree
// Show only the first column
for (int i = 1; i < m_model->columnCount(); i++)
m_treeview->setColumnHidden(i, true);
m_treeview->header()->hide();
m_treeview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QWidget* buttonContainer = new QWidget(m_mainWidget);
QPushButton* dirUpButton = new QPushButton(QIcon::fromTheme(QLatin1String("go-up")), QString(), buttonContainer);
dirUpButton->setMinimumSize(40, 40);
connect(dirUpButton, &QPushButton::clicked, this, &FileBrowserPanelPlugin::dirUpButtonHandle);
QPushButton* homeButton = new QPushButton(QIcon::fromTheme(QLatin1String("go-home")), QString(), buttonContainer);
homeButton->setMinimumSize(40, 40);
connect(homeButton, &QPushButton::clicked, this, &FileBrowserPanelPlugin::homeButtonHandle);
QPushButton* dirPreviousButton = new QPushButton(QIcon::fromTheme(QLatin1String("go-previous")), QString(), buttonContainer);
dirPreviousButton->setMinimumSize(40, 40);
connect(dirPreviousButton, &QPushButton::clicked, this, &FileBrowserPanelPlugin::dirPreviousButtonHandle);
QPushButton* dirNextButton = new QPushButton(QIcon::fromTheme(QLatin1String("go-next")), QString(), buttonContainer);
dirNextButton->setMinimumSize(40, 40);
connect(dirNextButton, &QPushButton::clicked, this, &FileBrowserPanelPlugin::dirNextButtonHandle);
m_pathEdit = new QLineEdit(m_rootDirsHistory.last(), buttonContainer);
connect(m_pathEdit, &QLineEdit::returnPressed, this, &FileBrowserPanelPlugin::setNewRootPath);
m_pathEdit->setMinimumHeight(40);
m_pathEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_filterCombobox = new QComboBox(buttonContainer);
m_filterCombobox->addItem(i18n("Cantor files"), QLatin1String("*.cws")); //Default value
m_filterCombobox->addItem(i18n("Jupyter files"), QLatin1String("*.ipynb"));
m_filterCombobox->addItem(i18n("All supported files"), QLatin1String("*.cws *.ipynb"));
m_filterCombobox->addItem(i18n("All files"), QLatin1String("*"));
connect(m_filterCombobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &FileBrowserPanelPlugin::handleFilterChanging);
m_model->setNameFilters({QLatin1String("*.cws")});
m_model->setNameFilterDisables(false);
QHBoxLayout* horizontalLayout = new QHBoxLayout();
horizontalLayout->setDirection(QBoxLayout::LeftToRight);
horizontalLayout->addWidget(dirPreviousButton);
horizontalLayout->addWidget(dirUpButton);
horizontalLayout->addWidget(homeButton);
horizontalLayout->addWidget(dirNextButton);
horizontalLayout->addWidget(m_pathEdit);
horizontalLayout->addWidget(m_filterCombobox);
horizontalLayout->setMargin(0);
buttonContainer->setLayout(horizontalLayout);
buttonContainer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(buttonContainer);
layout->addWidget(m_treeview);
m_mainWidget->setLayout(layout);
m_mainWidget = new QWidget();
m_treeview = new QTreeView(m_mainWidget);
m_treeview->setModel(m_model);
m_treeview->setRootIndex(m_model->index(m_rootDirsHistory.last()));
m_treeview->setExpandsOnDoubleClick(false);
connect(m_treeview, &QTreeView::doubleClicked, this, &FileBrowserPanelPlugin::handleDoubleClicked);
// First column is name with the dir tree
// Show only the first column
for (int i = 1; i < m_model->columnCount(); i++)
m_treeview->setColumnHidden(i, true);
m_treeview->header()->hide();
m_treeview->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QWidget* buttonContainer = new QWidget(m_mainWidget);
QPushButton* dirUpButton = new QPushButton(QIcon::fromTheme(QLatin1String("go-up")), QString(), buttonContainer);
dirUpButton->setMinimumSize(40, 40);
connect(dirUpButton, &QPushButton::clicked, this, &FileBrowserPanelPlugin::dirUpButtonHandle);
QPushButton* homeButton = new QPushButton(QIcon::fromTheme(QLatin1String("go-home")), QString(), buttonContainer);
homeButton->setMinimumSize(40, 40);
connect(homeButton, &QPushButton::clicked, this, &FileBrowserPanelPlugin::homeButtonHandle);
QPushButton* dirPreviousButton = new QPushButton(QIcon::fromTheme(QLatin1String("go-previous")), QString(), buttonContainer);
dirPreviousButton->setMinimumSize(40, 40);
connect(dirPreviousButton, &QPushButton::clicked, this, &FileBrowserPanelPlugin::dirPreviousButtonHandle);
QPushButton* dirNextButton = new QPushButton(QIcon::fromTheme(QLatin1String("go-next")), QString(), buttonContainer);
dirNextButton->setMinimumSize(40, 40);
connect(dirNextButton, &QPushButton::clicked, this, &FileBrowserPanelPlugin::dirNextButtonHandle);
m_pathEdit = new QLineEdit(m_rootDirsHistory.last(), buttonContainer);
connect(m_pathEdit, &QLineEdit::returnPressed, this, &FileBrowserPanelPlugin::setNewRootPath);
m_pathEdit->setMinimumHeight(40);
m_pathEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_filterCombobox = new QComboBox(buttonContainer);
m_filterCombobox->addItem(i18n("Cantor files"), QLatin1String("*.cws")); //Default value
m_filterCombobox->addItem(i18n("Jupyter files"), QLatin1String("*.ipynb"));
m_filterCombobox->addItem(i18n("All supported files"), QLatin1String("*.cws *.ipynb"));
m_filterCombobox->addItem(i18n("All files"), QLatin1String("*"));
connect(m_filterCombobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &FileBrowserPanelPlugin::handleFilterChanging);
m_model->setNameFilters({QLatin1String("*.cws")});
m_model->setNameFilterDisables(false);
QHBoxLayout* horizontalLayout = new QHBoxLayout();
horizontalLayout->setDirection(QBoxLayout::LeftToRight);
horizontalLayout->addWidget(dirPreviousButton);
horizontalLayout->addWidget(dirUpButton);
horizontalLayout->addWidget(homeButton);
horizontalLayout->addWidget(dirNextButton);
horizontalLayout->addWidget(m_pathEdit);
horizontalLayout->addWidget(m_filterCombobox);
horizontalLayout->setMargin(0);
buttonContainer->setLayout(horizontalLayout);
buttonContainer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(buttonContainer);
layout->addWidget(m_treeview);
m_mainWidget->setLayout(layout);
}
void FileBrowserPanelPlugin::moveFileBrowserRoot(const QString& path)
......@@ -187,7 +183,6 @@ void FileBrowserPanelPlugin::dirUpButtonHandle()
QDir dir(m_model->rootPath());
if (dir.cdUp())
moveFileBrowserRoot(dir.absolutePath());
}
void FileBrowserPanelPlugin::homeButtonHandle()
......@@ -227,12 +222,8 @@ void FileBrowserPanelPlugin::setNewRootPath()
void FileBrowserPanelPlugin::handleFilterChanging(int index)
{
if (m_model)
{
m_model->setNameFilters(m_filterCombobox->itemData(index).toString().split(QLatin1Char(' ')));
}
}
K_PLUGIN_FACTORY_WITH_JSON(filebrowserpanelplugin, "filebrowserpanelplugin.json", registerPlugin<FileBrowserPanelPlugin>();)
#include "filebrowserpanelplugin.moc"
......@@ -55,9 +55,9 @@ class FileBrowserPanelPlugin : public Cantor::PanelPlugin
QPointer<QTreeView> m_treeview;
QPointer<QLineEdit> m_pathEdit;
QPointer<QComboBox> m_filterCombobox;
QFileSystemModel* m_model;
QFileSystemModel* m_model = nullptr;
QVector<QString> m_rootDirsHistory;
int historyBackCount;
int historyBackCount = 0;
};
#endif /* _FILEBROWSERPANELPLUGIN_H */
......@@ -23,7 +23,7 @@ QWidget* HelpPanelPlugin::widget()
if(!m_edit)
{
m_edit = new KTextEdit(parentWidget());
setHelpHtml(i18n("<h1>Cantor</h1>The KDE way to do Mathematics"));
setHelpHtml(QString());
m_edit->setTextInteractionFlags(Qt::TextBrowserInteraction);
}
......@@ -61,7 +61,7 @@ void HelpPanelPlugin::connectToShell(QObject* cantorShell)
Cantor::PanelPlugin::State HelpPanelPlugin::saveState()
{
Cantor::PanelPlugin::State state = PanelPlugin::saveState();
auto state = PanelPlugin::saveState();
state.inners.append(m_edit->toHtml());
return state;
}
......@@ -72,9 +72,8 @@ void HelpPanelPlugin::restoreState(const Cantor::PanelPlugin::State& state)
if(state.inners.size() > 0)
setHelpHtml(state.inners.first().toString());
else
setHelpHtml(i18n("<h1>Cantor</h1>The KDE way to do Mathematics"));
setHelpHtml(QString());
}
K_PLUGIN_FACTORY_WITH_JSON(helppanelplugin, "helppanelplugin.json", registerPlugin<HelpPanelPlugin>();)
#include "helppanelplugin.moc"
......@@ -1459,19 +1459,15 @@ bool Worksheet::loadCantorWorksheet(const KZip& archive)
qDebug()<<"loading entries";
QDomElement expressionChild = root.firstChildElement();
WorksheetEntry* entry = nullptr;
while (!expressionChild.isNull()) {
QString tag = expressionChild.tagName();
// Don't add focus on load
entry = appendEntry(typeForTagName(tag), false);
auto* entry = appendEntry(typeForTagName(tag), false);
if (entry)
{
entry->setContent(expressionChild, archive);
if (m_readOnly)
{
entry->setAcceptHoverEvents(false);
entry = nullptr;
}
}
expressionChild = expressionChild.nextSiblingElement();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment