2014-09-10 17:27:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vfileproperty.cpp
|
|
|
|
** @author hedgeware <internal(at)hedgeware.net>
|
|
|
|
** @date
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** All rights reserved. This program and the accompanying materials
|
|
|
|
** are made available under the terms of the GNU Lesser General Public License
|
|
|
|
** (LGPL) version 2.1 which accompanies this distribution, and is available at
|
|
|
|
** http://www.gnu.org/licenses/lgpl-2.1.html
|
|
|
|
**
|
|
|
|
** This library 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
|
|
|
|
** Lesser General Public License for more details.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vfileproperty.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2014-09-10 17:27:45 +02:00
|
|
|
#include <QAbstractItemDelegate>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QWidget>
|
2014-09-10 17:27:45 +02:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../vfileproperty_p.h"
|
2014-09-10 17:27:45 +02:00
|
|
|
#include "vfilepropertyeditor.h"
|
2016-08-09 11:28:34 +02:00
|
|
|
#include "../vproperty_p.h"
|
2014-09-10 17:27:45 +02:00
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
VPE::VFileProperty::VFileProperty(const QString& name)
|
2014-09-10 17:27:45 +02:00
|
|
|
: VProperty(new VFilePropertyPrivate(name, QVariant::String))
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
VPE::VFileProperty::~VFileProperty()
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VFileProperty::setFileFilters(const QString& filefilters)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
static_cast<VFilePropertyPrivate*>(d_ptr)->FileFilters = filefilters;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QString VPE::VFileProperty::getFileFilters() const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
return static_cast<VFilePropertyPrivate*>(d_ptr)->FileFilters;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VFileProperty::setFile(const QString& file)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
d_ptr->VariantValue.setValue(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QString VPE::VFileProperty::getFile() const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
return d_ptr->VariantValue.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QVariant VPE::VFileProperty::data (int column, int role) const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
QFileInfo tmpFile(d_ptr->VariantValue.toString());
|
|
|
|
return tmpFile.fileName();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return VProperty::data(column, role);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QWidget* VPE::VFileProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
|
2014-09-10 19:57:08 +02:00
|
|
|
const QAbstractItemDelegate* delegate)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2016-12-20 20:19:21 +01:00
|
|
|
Q_UNUSED(options)
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
VFileEditWidget* tmpWidget = new VFileEditWidget(parent);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (delegate)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
VFileEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*)));
|
2014-09-10 19:57:08 +02:00
|
|
|
|
|
|
|
}
|
2015-02-11 11:33:13 +01:00
|
|
|
tmpWidget->setLocale(parent->locale());
|
2014-09-10 19:57:08 +02:00
|
|
|
tmpWidget->setFilter(static_cast<VFilePropertyPrivate*>(d_ptr)->FileFilters); // todo: parse this string
|
2014-09-10 17:27:45 +02:00
|
|
|
tmpWidget->setFile(d_ptr->VariantValue.toString());
|
|
|
|
tmpWidget->setDirectory(static_cast<VFilePropertyPrivate*>(d_ptr)->Directory);
|
|
|
|
return tmpWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
bool VPE::VFileProperty::setEditorData(QWidget* editor)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
VFileEditWidget* tmpWidget = qobject_cast<VFileEditWidget*>(editor);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpWidget)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
tmpWidget->setFile(d_ptr->VariantValue.toString());
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QVariant VPE::VFileProperty::getEditorData(const QWidget *editor) const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2014-09-14 11:16:59 +02:00
|
|
|
const VFileEditWidget* tmpWidget = qobject_cast<const VFileEditWidget*>(editor);
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpWidget)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return tmpWidget->getFile();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VFileProperty::setSetting(const QString& key, const QVariant& value)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (key == "FileFilters")
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
setFileFilters(value.toString());
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
|
|
|
else if (key == "Directory")
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
setDirectory(value.toBool());
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QVariant VPE::VFileProperty::getSetting(const QString& key) const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (key == "FileFilters")
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return getFileFilters();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
|
|
|
else if (key == "Directory")
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return isDirectory();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
return VProperty::getSetting(key);
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QStringList VPE::VFileProperty::getSettingKeys() const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
return QStringList("FileFilters") << "Directory";
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QString VPE::VFileProperty::type() const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
return "file";
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
VPE::VProperty* VPE::VFileProperty::clone(bool include_children, VProperty* container) const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
return VProperty::clone(include_children, container ? container : new VFileProperty(getName()));
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
bool VPE::VFileProperty::isDirectory() const
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
return static_cast<VFilePropertyPrivate*>(d_ptr)->Directory;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VFileProperty::setDirectory(bool is_directory)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
static_cast<VFilePropertyPrivate*>(d_ptr)->Directory = is_directory;
|
|
|
|
}
|