valentina_old/src/libs/vpropertyexplorer/plugins/vfileproperty.cpp

179 lines
4.3 KiB
C++
Raw Normal View History

/************************************************************************
**
** @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"
#include <QAbstractItemDelegate>
#include <QFileInfo>
#include <QLocale>
#include <QWidget>
#include "../vfileproperty_p.h"
#include "vfilepropertyeditor.h"
#include "vproperty_p.h"
class QStyleOptionViewItem;
using namespace VPE;
VFileProperty::VFileProperty(const QString& name)
: VProperty(new VFilePropertyPrivate(name, QVariant::String))
{
}
VFileProperty::~VFileProperty()
{
//
}
void VFileProperty::setFileFilters(const QString& filefilters)
{
static_cast<VFilePropertyPrivate*>(d_ptr)->FileFilters = filefilters;
}
QString VFileProperty::getFileFilters() const
{
return static_cast<VFilePropertyPrivate*>(d_ptr)->FileFilters;
}
void VFileProperty::setFile(const QString& file)
{
d_ptr->VariantValue.setValue(file);
}
QString VFileProperty::getFile() const
{
return d_ptr->VariantValue.toString();
}
QVariant VFileProperty::data (int column, int role) const
{
2014-09-10 19:57:08 +02:00
if (column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role))
{
QFileInfo tmpFile(d_ptr->VariantValue.toString());
return tmpFile.fileName();
}
else
return VProperty::data(column, role);
}
2014-09-10 19:57:08 +02:00
QWidget* VFileProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options,
const QAbstractItemDelegate* delegate)
{
Q_UNUSED(options);
VFileEditWidget* tmpWidget = new VFileEditWidget(parent);
2014-09-10 19:57:08 +02:00
if (delegate)
{
VFileEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*)));
2014-09-10 19:57:08 +02: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
tmpWidget->setFile(d_ptr->VariantValue.toString());
tmpWidget->setDirectory(static_cast<VFilePropertyPrivate*>(d_ptr)->Directory);
return tmpWidget;
}
bool VFileProperty::setEditorData(QWidget* editor)
{
VFileEditWidget* tmpWidget = qobject_cast<VFileEditWidget*>(editor);
2014-09-10 19:57:08 +02:00
if (tmpWidget)
{
tmpWidget->setFile(d_ptr->VariantValue.toString());
2014-09-10 19:57:08 +02:00
}
else
return false;
return true;
}
2014-09-14 11:16:59 +02:00
QVariant VFileProperty::getEditorData(const QWidget *editor) const
{
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)
{
return tmpWidget->getFile();
2014-09-10 19:57:08 +02:00
}
return QVariant();
}
void VFileProperty::setSetting(const QString& key, const QVariant& value)
{
2014-09-10 19:57:08 +02:00
if (key == "FileFilters")
{
setFileFilters(value.toString());
2014-09-10 19:57:08 +02:00
}
else if (key == "Directory")
{
setDirectory(value.toBool());
2014-09-10 19:57:08 +02:00
}
}
QVariant VFileProperty::getSetting(const QString& key) const
{
2014-09-10 19:57:08 +02:00
if (key == "FileFilters")
{
return getFileFilters();
2014-09-10 19:57:08 +02:00
}
else if (key == "Directory")
{
return isDirectory();
2014-09-10 19:57:08 +02:00
}
else
return VProperty::getSetting(key);
}
QStringList VFileProperty::getSettingKeys() const
{
return QStringList("FileFilters") << "Directory";
}
QString VFileProperty::type() const
{
return "file";
}
VProperty* VFileProperty::clone(bool include_children, VProperty* container) const
{
return VProperty::clone(include_children, container ? container : new VFileProperty(getName()));
}
bool VFileProperty::isDirectory() const
{
return static_cast<VFilePropertyPrivate*>(d_ptr)->Directory;
}
void VFileProperty::setDirectory(bool is_directory)
{
static_cast<VFilePropertyPrivate*>(d_ptr)->Directory = is_directory;
}