Commit 7a99ec1d authored by Halla Rempt's avatar Halla Rempt

Add a "clear" parameter and a return bool to fromXML

This way, we can create a default properties object and read
a configuration that might overwrite some properties.
parent b5936ec4
......@@ -54,14 +54,19 @@ KisPropertiesConfiguration::KisPropertiesConfiguration(const KisPropertiesConfig
{
}
void KisPropertiesConfiguration::fromXML(const QString & s)
bool KisPropertiesConfiguration::fromXML(const QString & xml, bool clear)
{
clearProperties();
if (clear) {
clearProperties();
}
QDomDocument doc;
doc.setContent(s);
QDomElement e = doc.documentElement();
fromXML(e);
bool retval = doc.setContent(xml);
if (retval) {
QDomElement e = doc.documentElement();
fromXML(e);
}
return retval;
}
void KisPropertiesConfiguration::fromXML(const QDomElement& e)
......
......@@ -61,11 +61,17 @@ public:
/**
* Fill the properties configuration object from the XML encoded representation in s.
* This function use the "Legacy" style XML of the 1.x .kra file format.
* @param xml the string that will be parsed as xml
* @param clear if true, the properties map will be emptied.
* @return true is the xml document could be parsed
*/
virtual void fromXML(const QString&);
virtual bool fromXML(const QString& xml, bool clear = true);
/**
* Fill the properties configuration object from the XML encoded representation in s.
* This function use the "Legacy" style XML of the 1.x .kra file format.
*
* Note: the existing properties will not be cleared
*/
virtual void fromXML(const QDomElement&);
......
......@@ -31,12 +31,15 @@ KisSerializableConfiguration::KisSerializableConfiguration(const KisSerializable
{
}
void KisSerializableConfiguration::fromXML(const QString & s)
bool KisSerializableConfiguration::fromXML(const QString &s, bool)
{
QDomDocument doc;
doc.setContent(s);
QDomElement e = doc.documentElement();
fromXML(e);
bool rv = doc.setContent(s);
if (rv) {
QDomElement e = doc.documentElement();
fromXML(e);
}
return rv;
}
QString KisSerializableConfiguration::toXML() const
......
......@@ -44,7 +44,7 @@ public:
/**
* Fill the object from the XML encoded representation in s.
*/
virtual void fromXML(const QString&);
virtual bool fromXML(const QString&, bool);
/**
* Fill the object from the XML encoded representation in s.
......
......@@ -61,11 +61,11 @@ KisPropertiesConfigurationSP exrExport::defaultConfiguration(const QByteArray &/
return cfg;
}
KisPropertiesConfigurationSP exrExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
KisPropertiesConfigurationSP exrExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
QString filterConfig = KisConfig().exportConfiguration("EXR");
cfg->fromXML(filterConfig);
cfg->fromXML(filterConfig, false);
return cfg;
}
......
......@@ -62,11 +62,11 @@ KisPropertiesConfigurationSP KisHeightMapExport::defaultConfiguration(const QByt
return cfg;
}
KisPropertiesConfigurationSP KisHeightMapExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
KisPropertiesConfigurationSP KisHeightMapExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
QString filterConfig = KisConfig().exportConfiguration("HeightMap");
cfg->fromXML(filterConfig);
cfg->fromXML(filterConfig, false);
return cfg;
}
......
......@@ -62,11 +62,11 @@ KisPropertiesConfigurationSP jp2Export::defaultConfiguration(const QByteArray &/
return cfg;
}
KisPropertiesConfigurationSP jp2Export::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
KisPropertiesConfigurationSP jp2Export::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
QString filterConfig = KisConfig().exportConfiguration("JP2");
cfg->fromXML(filterConfig);
cfg->fromXML(filterConfig, false);
return cfg;
}
......
......@@ -185,11 +185,11 @@ KisPropertiesConfigurationSP KisJPEGExport::defaultConfiguration(const QByteArra
return cfg;
}
KisPropertiesConfigurationSP KisJPEGExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
KisPropertiesConfigurationSP KisJPEGExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
QString filterConfig = KisConfig().exportConfiguration("JPEG");
cfg->fromXML(filterConfig);
cfg->fromXML(filterConfig, false);
return cfg;
}
......
......@@ -202,11 +202,11 @@ KisPropertiesConfigurationSP KisPNGExport::defaultConfiguration(const QByteArray
return cfg;
}
KisPropertiesConfigurationSP KisPNGExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
KisPropertiesConfigurationSP KisPNGExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
{
QString filterConfig = KisConfig().exportConfiguration("PNG");
KisPropertiesConfigurationSP cfg(new KisPropertiesConfiguration());
cfg->fromXML(filterConfig);
KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
cfg->fromXML(filterConfig, false);
return cfg;
}
......
......@@ -288,11 +288,11 @@ KisPropertiesConfigurationSP KisPPMExport::defaultConfiguration(const QByteArray
return cfg;
}
KisPropertiesConfigurationSP KisPPMExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
KisPropertiesConfigurationSP KisPPMExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
{
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
QString filterConfig = KisConfig().exportConfiguration("PPM");
cfg->fromXML(filterConfig);
cfg->fromXML(filterConfig, false);
return cfg;
}
......
......@@ -151,11 +151,11 @@ KisPropertiesConfigurationSP KisTIFFExport::defaultConfiguration(const QByteArra
return cfg;
}
KisPropertiesConfigurationSP KisTIFFExport::lastSavedConfiguration(const QByteArray &/*from*/, const QByteArray &/*to*/) const
KisPropertiesConfigurationSP KisTIFFExport::lastSavedConfiguration(const QByteArray &from, const QByteArray &to) const
{
QString filterConfig = KisConfig().exportConfiguration("TIFF");
KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
cfg->fromXML(filterConfig);
KisPropertiesConfigurationSP cfg = defaultConfiguration(from, to);
cfg->fromXML(filterConfig, false);
return cfg;
}
......
......@@ -142,8 +142,7 @@ KisImportExportFilter::ConversionStatus KisVideoExport::convert(const QByteArray
KisPropertiesConfigurationSP KisVideoExport::defaultConfiguration(const QByteArray &from, const QByteArray &to) const
{
Q_UNUSED(from);
Q_UNUSED(to);
KisPropertiesConfigurationSP cfg(new KisPropertiesConfiguration());
KisPropertiesConfigurationSP cfg(new KisPropertiesConfiguration());
cfg->setProperty("h264PresetIndex", 5);
cfg->setProperty("h264ConstantRateFactor", 23);
......@@ -152,14 +151,24 @@ KisPropertiesConfigurationSP KisVideoExport::defaultConfiguration(const QByteArr
cfg->setProperty("TheoraBitrate", 5000);
cfg->setProperty("CustomLineValue", "");
if (to == "video/ogg") {
cfg->setProperty("CodecIndex", VideoExportOptionsDialog::CODEC_THEORA);
}
else if (to == "video/x-matroska" || to == "video/mp4") {
cfg->setProperty("CodecIndex", VideoExportOptionsDialog::CODEC_H264);
}
return cfg;
}
KisConfigWidget *KisVideoExport::createConfigurationWidget(QWidget *parent, const QByteArray &from, const QByteArray &to) const
{
Q_UNUSED(from);
Q_UNUSED(to);
return new VideoExportOptionsDialog(parent);
KisConfigWidget *w;
if (to != "image/gif") {
w = new VideoExportOptionsDialog(parent);
}
return w;
}
#include "kis_video_export.moc"
......@@ -107,8 +107,7 @@ VideoExportOptionsDialog::VideoExportOptionsDialog(QWidget *parent) :
ui->intBitrate->setValue(5000);
ui->intBitrate->setSuffix(i18nc("kilo-bits-per-second, video bitrate suffix", "kbps"));
connect(ui->cmbCodec, SIGNAL(currentIndexChanged(int)),
ui->stackedWidget, SLOT(setCurrentIndex(int)));
connect(ui->cmbCodec, SIGNAL(currentIndexChanged(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));
ui->cmbCodec->setCurrentIndex(0);
ui->cmbCodec->setEnabled(false);
......@@ -194,6 +193,12 @@ void VideoExportOptionsDialog::setConfiguration(const KisPropertiesConfiguration
m_d->defaultTune = cfg->getInt("h264TuneIndex", 1);
m_d->defaultBitrate = cfg->getInt("TheoraBitrate", 5000);
m_d->defaultCustomLine = cfg->getString("CustomLineValue", "");
if (cfg->hasProperty("CodecIndex")) {
setCodec((VideoExportOptionsDialog::CodecIndex)cfg->getInt("CodecIndex"));
}
else {
ui->cmbCodec->setEnabled(false);
}
}
QStringList VideoExportOptionsDialog::generateCustomLine() const
......@@ -204,6 +209,7 @@ QStringList VideoExportOptionsDialog::generateCustomLine() const
options << "-crf" << QString::number(ui->intConstantRateFactor->value());
const int presetIndex = ui->cmbPreset->currentIndex();
qDebug() << "presetIndex" << presetIndex << m_d->presets;
options << "-preset" << m_d->presets[presetIndex].id();
const int profileIndex = ui->cmbProfile->currentIndex();
......
......@@ -6,11 +6,11 @@
<rect>
<x>0</x>
<y>0</y>
<width>505</width>
<height>333</height>
<width>273</width>
<height>323</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,1,0">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,1">
<item>
<widget class="QComboBox" name="cmbCodec">
<item>
......@@ -149,16 +149,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
......@@ -169,38 +159,5 @@
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>VideoExportOptionsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>VideoExportOptionsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>
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