Attention une mise à jour du service Gitlab va être effectuée le mardi 30 novembre entre 17h30 et 18h00. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes. Cette mise à jour intermédiaire en version 14.0.12 nous permettra de rapidement pouvoir mettre à votre disposition une version plus récente.

Commit 4280364e authored by Julien Wintz's avatar Julien Wintz
Browse files

Merge branch...

Merge branch '66-improvement-factorize-the-code-of-dtkwidgetsparameterfilesave-and-dtkwidgetsparameterfilebrowser' into 'develop'

Resolve "[improvement]factorize the code of dtkWidgetsParameterFileSave and dtkWidgetsParameterFileBrowser"

Closes #66

See merge request !69
parents 6c1c30f7 b12e5739
Pipeline #173579 pending with stage
......@@ -91,6 +91,8 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsParameterBoolCheckBox.h
dtkWidgetsParameterBoolPushButton
dtkWidgetsParameterBoolPushButton.h
dtkWidgetsParameterBrowse
dtkWidgetsParameterBrowse.h
dtkWidgetsParameterDirBrowse
dtkWidgetsParameterDirBrowse.h
dtkWidgetsParameterDoubleSlider
......@@ -165,6 +167,7 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsParameter.cpp
dtkWidgetsParameterBoolCheckBox.cpp
dtkWidgetsParameterBoolPushButton.cpp
dtkWidgetsParameterBrowse.cpp
dtkWidgetsParameterDirBrowse.cpp
dtkWidgetsParameterDoubleSlider.cpp
dtkWidgetsParameterDoubleSpinBox.cpp
......
#include "dtkWidgetsParameterBrowse.h"
\ No newline at end of file
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkWidgetsParameterBrowse.h"
#include <QtWidgets>
#include <QStringBuilder>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterBrowsePrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterBrowsePrivate
{
public:
QPushButton *push_button = nullptr;
public:
void setToolTip(const QString& doc, const QString& path)
{
QString tooltip;
if (!doc.isEmpty()) {
tooltip += QString("Doc: %1").arg(doc);
}
if (!path.isEmpty()) {
if (!tooltip.isEmpty()) {
tooltip += "\n";
}
tooltip += QString("Path: %1").arg(path);
}
push_button->setToolTip( tooltip );
}
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterBrowse implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterBrowse::dtkWidgetsParameterBrowse(QWidget* parent) : dtkWidgetsParameterBase<dtk::d_path>(parent), d(new dtkWidgetsParameterBrowsePrivate)
{
d->push_button = new QPushButton;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(d->push_button);
this->setLayout(layout);
}
dtkWidgetsParameterBrowse::~dtkWidgetsParameterBrowse(void)
{
delete d;
}
void dtkWidgetsParameterBrowse::setReadOnly(bool val)
{
this->dtkWidgetsParameter::m_readonly = val;
d->push_button->setEnabled(!this->dtkWidgetsParameter::m_readonly);
d->push_button->setFocusPolicy((this->dtkWidgetsParameter::m_readonly? Qt::NoFocus : Qt::WheelFocus));
}
bool dtkWidgetsParameterBrowse::connect(dtkCoreParameter *p)
{
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
m_parameter = dynamic_cast<dtk::d_path *>(p);
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterBrowse.";
return false;
}
QString text = "Browse";
QString base_name = m_parameter->baseName();
if(!base_name.isEmpty()) {
text = base_name;
}
d->push_button->setText(text);
d->setToolTip( m_parameter->documentation(), m_parameter->path() );
m_parameter->connect([=] (QVariant v) {
d->push_button->blockSignals(true);
QString value = v.value<dtk::d_path>().baseName();
if (value.isEmpty()) {
value = "Browse";
}
d->push_button->setText(value);
d->push_button->blockSignals(false);
QString tip = v.value<dtk::d_path>().path();
if(!tip.isEmpty()) {
d->setToolTip( m_parameter->documentation(), tip );
}
});
QObject::connect(d->push_button, &QPushButton::clicked, [=] ()
{
QString v = QFileDialog::getOpenFileName(this, "Open file", m_parameter->dirName(), m_parameter->filters().join(";;"));
m_parameter->shareValue(QVariant::fromValue(v));
});
return true;
}
//
// dtkWidgetsParameterBrowse.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkWidgetsExport>
#include "dtkWidgetsParameter.h"
#include <dtkCore/dtkCoreParameter>
#include <dtkCore/dtkCoreParameterPath>
class DTKWIDGETS_EXPORT dtkWidgetsParameterBrowse : public dtkWidgetsParameterBase<dtk::d_path>
{
Q_OBJECT
public:
dtkWidgetsParameterBrowse(QWidget* parent = nullptr);
~dtkWidgetsParameterBrowse(void);
public:
bool connect(dtkCoreParameter *) override;
void setReadOnly(bool) override;
protected:
virtual QString browse(void) = 0;
protected:
using dtkWidgetsParameterBase<dtk::d_path>::m_parameter;
private:
class dtkWidgetsParameterBrowsePrivate *d;
};
//
// dtkWidgetsParameterBrowse.h ends here
//
// dtkWidgetsParameterDirBrowse.cpp ends here
// Version: $Id$
//
//
......@@ -16,68 +18,11 @@
#include <QtWidgets>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterDirBrowsePrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterDirBrowsePrivate
{
public:
QPushButton *push_button = nullptr;
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterDirBrowse implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterDirBrowse::dtkWidgetsParameterDirBrowse(QWidget* parent) : dtkWidgetsParameterBase<dtk::d_path>(parent), d(new dtkWidgetsParameterDirBrowsePrivate)
{
d->push_button = new QPushButton;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(d->push_button);
this->setLayout(layout);
}
dtkWidgetsParameterDirBrowse::~dtkWidgetsParameterDirBrowse(void)
{
delete d;
}
bool dtkWidgetsParameterDirBrowse::connect(dtkCoreParameter *p)
{
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
m_parameter = dynamic_cast<dtk::d_path *>(p);
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterDirBrowse.";
return false;
}
d->push_button->setText("Browse");
m_parameter->connect([=] (QVariant v) {
d->push_button->blockSignals(true);
QString value = v.value<dtk::d_path>().baseName();
if (value.isEmpty()) {
value = "Browse";
}
d->push_button->setText(value);
d->push_button->blockSignals(false);
});
QObject::connect(d->push_button, &QPushButton::clicked, [=] ()
{
QString v = QFileDialog::getExistingDirectory(this, "Open Directory", m_parameter->dirName());
m_parameter->shareValue(QVariant::fromValue(v));
});
dtkWidgetsParameterDirBrowse::dtkWidgetsParameterDirBrowse(QWidget* parent) : dtkWidgetsParameterBrowse(parent)
{}
return true;
QString dtkWidgetsParameterDirBrowse::browse(void) {
return QFileDialog::getExistingDirectory(this, "Open Directory", dtkWidgetsParameterBrowse::m_parameter->dirName());
}
//
......
......@@ -16,25 +16,19 @@
#include <dtkWidgetsExport>
#include "dtkWidgetsParameter.h"
#include "dtkWidgetsParameterBrowse.h"
#include <dtkCore/dtkCoreParameterPath>
class DTKWIDGETS_EXPORT dtkWidgetsParameterDirBrowse : public dtkWidgetsParameterBase<dtk::d_path>
class DTKWIDGETS_EXPORT dtkWidgetsParameterDirBrowse : public dtkWidgetsParameterBrowse
{
Q_OBJECT
public:
dtkWidgetsParameterDirBrowse(QWidget* parent = 0);
~dtkWidgetsParameterDirBrowse(void);
public:
bool connect(dtkCoreParameter *) override;
dtkWidgetsParameterDirBrowse(QWidget* parent = nullptr);
private:
using dtkWidgetsParameterBase<dtk::d_path>::m_parameter;
class dtkWidgetsParameterDirBrowsePrivate *d;
QString browse(void) override;
};
// ///////////////////////////////////////////////////////////////////
......
......@@ -17,102 +17,11 @@
#include <QtWidgets>
#include <QStringBuilder>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterFileBrowsePrivate declaration
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterFileBrowse::dtkWidgetsParameterFileBrowse(QWidget* parent) : dtkWidgetsParameterBrowse(parent)
{}
class dtkWidgetsParameterFileBrowsePrivate
{
public:
QPushButton *push_button = nullptr;
public:
void setToolTip(const QString& doc, const QString& path)
{
QString tooltip;
if (!doc.isEmpty()) {
tooltip += QString("Doc: %1").arg(doc);
}
if (!path.isEmpty()) {
if (!tooltip.isEmpty())
tooltip += "\n";
tooltip += QString("Path: %1").arg(path);
}
push_button->setToolTip( tooltip );
}
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterFileBrowse implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterFileBrowse::dtkWidgetsParameterFileBrowse(QWidget* parent) : dtkWidgetsParameterBase<dtk::d_path>(parent), d(new dtkWidgetsParameterFileBrowsePrivate)
{
d->push_button = new QPushButton;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(d->push_button);
this->setLayout(layout);
}
dtkWidgetsParameterFileBrowse::~dtkWidgetsParameterFileBrowse(void)
{
delete d;
}
void dtkWidgetsParameterFileBrowse::setReadOnly(bool val)
{
this->dtkWidgetsParameter::m_readonly = val;
d->push_button->setEnabled(!this->dtkWidgetsParameter::m_readonly);
d->push_button->setFocusPolicy((this->dtkWidgetsParameter::m_readonly? Qt::NoFocus : Qt::WheelFocus));
}
bool dtkWidgetsParameterFileBrowse::connect(dtkCoreParameter *p)
{
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
m_parameter = dynamic_cast<dtk::d_path *>(p);
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterFileBrowse.";
return false;
}
QString text = "Browse";
QString base_name = m_parameter->baseName();
if(!base_name.isEmpty()) {
text = base_name;
}
d->push_button->setText(text);
d->setToolTip( m_parameter->documentation(), m_parameter->path() );
m_parameter->connect([=] (QVariant v) {
d->push_button->blockSignals(true);
QString value = v.value<dtk::d_path>().baseName();
if (value.isEmpty()) {
value = "Browse";
}
d->push_button->setText(value);
d->push_button->blockSignals(false);
QString tip = v.value<dtk::d_path>().path();
if(!tip.isEmpty()) {
d->setToolTip( m_parameter->documentation(), tip );
}
});
QObject::connect(d->push_button, &QPushButton::clicked, [=] ()
{
QString v = QFileDialog::getOpenFileName(this, "Open file", m_parameter->dirName(), m_parameter->filters().join(";;"));
m_parameter->shareValue(QVariant::fromValue(v));
});
return true;
QString dtkWidgetsParameterFileBrowse::browse(void) {
return QFileDialog::getOpenFileName(this, "Open file", dtkWidgetsParameterBrowse::m_parameter->dirName(), dtkWidgetsParameterBrowse::m_parameter->filters().join(";;"));
}
//
......
......@@ -16,27 +16,20 @@
#include <dtkWidgetsExport>
#include "dtkWidgetsParameter.h"
#include "dtkWidgetsParameterBrowse.h"
#include <dtkCore/dtkCoreParameter>
#include <dtkCore/dtkCoreParameterPath>
class DTKWIDGETS_EXPORT dtkWidgetsParameterFileBrowse : public dtkWidgetsParameterBase<dtk::d_path>
class DTKWIDGETS_EXPORT dtkWidgetsParameterFileBrowse : public dtkWidgetsParameterBrowse
{
Q_OBJECT
public:
dtkWidgetsParameterFileBrowse(QWidget* parent = nullptr);
~dtkWidgetsParameterFileBrowse(void);
public:
bool connect(dtkCoreParameter *) override;
void setReadOnly(bool) override;
private:
using dtkWidgetsParameterBase<dtk::d_path>::m_parameter;
class dtkWidgetsParameterFileBrowsePrivate *d;
QString browse(void) override;
};
// ///////////////////////////////////////////////////////////////////
......
//
// dtkWidgetsParameterFileSave.cpp ends here
// Version: $Id$
//
//
......@@ -17,99 +19,11 @@
#include <QtWidgets>
#include <QStringBuilder>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterFileSavePrivate declaration
// ///////////////////////////////////////////////////////////////////
class dtkWidgetsParameterFileSavePrivate
{
public:
QPushButton *push_button = nullptr;
public:
void setToolTip(const QString& doc, const QString& path)
{
QString tooltip;
if (!doc.isEmpty()) {
tooltip += QString("Doc: %1").arg( doc );
}
if (!path.isEmpty()) {
if (!tooltip.isEmpty())
tooltip += "\n";
tooltip += QString("Path: %1").arg( path );
}
push_button->setToolTip( tooltip );
}
};
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterFileSave implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterFileSave::dtkWidgetsParameterFileSave(QWidget* parent) : dtkWidgetsParameterBase<dtk::d_path>(parent), d(new dtkWidgetsParameterFileSavePrivate)
{
d->push_button = new QPushButton;
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(d->push_button);
this->setLayout(layout);
}
dtkWidgetsParameterFileSave::~dtkWidgetsParameterFileSave(void)
{
delete d;
}
void dtkWidgetsParameterFileSave::setReadOnly(bool val)
{
this->dtkWidgetsParameter::m_readonly = val;
d->push_button->setEnabled(!this->dtkWidgetsParameter::m_readonly);
d->push_button->setFocusPolicy((this->dtkWidgetsParameter::m_readonly? Qt::NoFocus : Qt::WheelFocus));
}
bool dtkWidgetsParameterFileSave::connect(dtkCoreParameter *p)
{
if (!p) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done.";
return false;
}
m_parameter = dynamic_cast<dtk::d_path *>(p);
if(!m_parameter) {
qWarning() << Q_FUNC_INFO << "The type of the parameter is not compatible with the widget dtkWidgetsParameterFileSave.";
return false;
}
QString text = "Save";
QString base_name = m_parameter->baseName();
if(!base_name.isEmpty()) {
text = base_name;
}
d->push_button->setText(text);
d->setToolTip( m_parameter->documentation(), m_parameter->path() );
m_parameter->connect([=] (QVariant v) {
d->push_button->blockSignals(true);
QString value = v.value<dtk::d_path>().baseName();
if (value.isEmpty()) {
value = "Save";
}
d->push_button->setText(value);
d->setToolTip( m_parameter->documentation(), value );
d->push_button->blockSignals(false);
});
QObject::connect(d->push_button, &QPushButton::clicked, [=] ()
{
QString v = QFileDialog::getSaveFileName(this, "Save file", m_parameter->dirName(), m_parameter->filters().join(";;"));
m_parameter->shareValue(QVariant::fromValue(v));
});
dtkWidgetsParameterFileSave::dtkWidgetsParameterFileSave(QWidget* parent) : dtkWidgetsParameterBrowse(parent)
{}
return true;
QString dtkWidgetsParameterFileSave::browse(void) {
return QFileDialog::getSaveFileName(this, "Save file", m_parameter->dirName(), m_parameter->filters().join(";;"));
}
//
......
......@@ -16,26 +16,19 @@
#include <dtkWidgetsExport>
#include "dtkWidgetsParameter.h"
#include "dtkWidgetsParameterBrowse.h"
#include <dtkCore/dtkCoreParameterPath>
class DTKWIDGETS_EXPORT dtkWidgetsParameterFileSave : public dtkWidgetsParameterBase<dtk::d_path>
class DTKWIDGETS_EXPORT dtkWidgetsParameterFileSave : public dtkWidgetsParameterBrowse
{
Q_OBJECT
public:
dtkWidgetsParameterFileSave(QWidget* parent = nullptr);
~dtkWidgetsParameterFileSave(void);
public:
bool connect(dtkCoreParameter *) override;
void setReadOnly(bool val) override;
dtkWidgetsParameterFileSave(QWidget* parent = nullptr);
private:
using dtkWidgetsParameterBase<dtk::d_path>::m_parameter;
class dtkWidgetsParameterFileSavePrivate *d;
QString browse(void) override;
};
// ///////////////////////////////////////////////////////////////////
......
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