Commit dd6388b5 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Introducing StringProperty as specific class, which has a display type.

Depending on StringProperty's display type, its property widget shows either just the QLineEdit, or additionally a browse button that pops up a QFileDialog for either loading or saving a file, or choosing a directory.

closes #43
parent 3d5ed98c
......@@ -40,7 +40,7 @@ namespace campvis {
_lineEdit->setText(QString::fromStdString(property->getValue()));
addWidget(_lineEdit);
if (! dynamic_cast<DataNameProperty*>(property)) {
if (property->getDisplayType() != StringProperty::BASIC_STRING) {
_btnLoadFile = new QPushButton(tr("Browse"), this);
addWidget(_btnLoadFile);
connect(_btnLoadFile, SIGNAL(clicked(bool)), this, SLOT(onBtnLoadFileClicked(bool)));
......@@ -76,30 +76,23 @@ namespace campvis {
void StringPropertyWidget::onBtnLoadFileClicked(bool flag) {
StringProperty* prop = static_cast<StringProperty*>(_property);
QString dialogCaption = QString::fromStdString(prop->getTitle());
QString directory;
// use directory of current property value if any, default directory otherwise
if (! prop->getValue().empty())
directory = QString::fromStdString(prop->getValue());
else
directory = tr("");
const QString fileFilter = /*QString::fromStdString(property_->getFileFilter()) + ";;" + */tr("All files (*)");
const QString dialogCaption = QString::fromStdString(prop->getTitle());
const QString directory = QString::fromStdString(prop->getValue());
const QString fileFilter = tr("All files (*)");
QString filename;
// if (property_->getFileMode() == FileDialogProperty::OPEN_FILE) {
if (prop->getDisplayType() == StringProperty::OPEN_FILENAME) {
filename = QFileDialog::getOpenFileName(QWidget::parentWidget(), dialogCaption, directory, fileFilter);
/* }
else if (property_->getFileMode() == FileDialogProperty::SAVE_FILE) {
}
else if (prop->getDisplayType() == StringProperty::SAVE_FILENAME) {
filename = QFileDialog::getSaveFileName(QWidget::parentWidget(), dialogCaption, directory, fileFilter);
}
else if (property_->getFileMode() == FileDialogProperty::DIRECTORY) {
filename = QFileDialog::getExistingDirectory(QWidget::parentWidget(), dialogCaption, QString::fromStdString(property_->get()));
}*/
else if (prop->getDisplayType() == StringProperty::DIRECTORY) {
filename = QFileDialog::getExistingDirectory(QWidget::parentWidget(), dialogCaption, directory);
}
if (! filename.isEmpty()) {
prop->setValue(filename.toStdString());
//emit modified();
}
}
......
......@@ -27,7 +27,7 @@
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/properties/propertywidgetfactory.h"
#include "core/properties/genericproperty.h"
#include "core/properties/stringproperty.h"
class QLineEdit;
class QPushButton;
......
......@@ -29,7 +29,7 @@ namespace campvis {
const std::string DataNameProperty::loggerCat_ = "CAMPVis.core.datastructures.DataNameProperty";
DataNameProperty::DataNameProperty(const std::string& name, const std::string& title, const std::string& value, DataAccessInfo access)
: GenericProperty<std::string>(name, title, value)
: StringProperty(name, title, value, StringProperty::BASIC_STRING)
, _accessInfo(access)
{
......
......@@ -25,7 +25,7 @@
#ifndef DATANAMEPROPERTY_H__
#define DATANAMEPROPERTY_H__
#include "core/properties/genericproperty.h"
#include "core/properties/stringproperty.h"
#include <ctime>
#include <set>
......@@ -37,7 +37,7 @@ namespace campvis {
* Specialization of a StringProperty to specify the keys (string IDs) for DataHandles to read/write.
* Offers an additional DataAccessInfo flag whether processor will read or write from/to that ID.
*/
class CAMPVIS_CORE_API DataNameProperty : public GenericProperty<std::string> {
class CAMPVIS_CORE_API DataNameProperty : public StringProperty {
public:
/**
* DataAccessInfo flag defining whether processor will read or write from/to the corresponding DataHandle.
......
......@@ -121,7 +121,6 @@ namespace campvis {
// = Typedefs =====================================================================================
typedef GenericProperty<bool> BoolProperty;
typedef GenericProperty<std::string> StringProperty;
// = Template Implementation ======================================================================
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#include "stringproperty.h"
namespace campvis {
const std::string StringProperty::loggerCat_ = "CAMPVis.core.datastructures.StringProperty";
StringProperty::StringProperty(const std::string& name, const std::string& title, const std::string& value, DisplayType displayType)
: GenericProperty<std::string>(name, title, value)
, _displayType(displayType)
{
}
StringProperty::~StringProperty() {
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universität München
// Boltzmannstr. 3, 85748 Garching b. München, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
// ================================================================================================
#ifndef STRINGPROPERTY_H__
#define STRINGPROPERTY_H__
#include "core/properties/genericproperty.h"
#include <string>
namespace campvis {
class CAMPVIS_CORE_API StringProperty : public GenericProperty<std::string> {
public:
/// Enumeration of the possible display types of this property
enum DisplayType {
BASIC_STRING,
OPEN_FILENAME,
SAVE_FILENAME,
DIRECTORY
};
/**
* Creates a new StringProperty
* \param name Property name (unchangable!)
* \param title Property title (e.g. used for GUI)
* \param value Initial value
*/
StringProperty(const std::string& name, const std::string& title, const std::string& value = "", DisplayType displayType = BASIC_STRING);
/**
* Virtual Destructor
**/
virtual ~StringProperty();
/**
* Gets display type of this property.
* \return _displayType
**/
DisplayType getDisplayType() const { return _displayType; }
/**
* Sets display type of this property.
* \param _displayType New value for display type of this property.
**/
void setDisplayType(DisplayType val) { _displayType = val; }
protected:
DisplayType _displayType;
static const std::string loggerCat_;
};
}
#endif // STRINGPROPERTY_H__
......@@ -52,9 +52,9 @@ namespace campvis {
, _usBlurFilter(&_canvasSize)
, _usFusion(&_canvasSize)
, p_autoExecution("AutoExecution", "Automatic Execution", false)
, p_sourcePath("SourcePath", "Source Files Path", "")
, p_targetPathColor("TargetPathColor", "Target Path Color Files", "")
, p_targetPathFuzzy("TargetPathFuzzy", "Target Path Fuzzy Files", "")
, p_sourcePath("SourcePath", "Source Files Path", "", StringProperty::DIRECTORY)
, p_targetPathColor("TargetPathColor", "Target Path Color Files", "", StringProperty::DIRECTORY)
, p_targetPathFuzzy("TargetPathFuzzy", "Target Path Fuzzy Files", "", StringProperty::DIRECTORY)
, p_range("Range", "Files Range", tgt::ivec2(0, 1), tgt::ivec2(0, 0), tgt::ivec2(10000, 10000))
, p_execute("Execute", "Execute Batch Pipeline")
{
......
......@@ -34,6 +34,7 @@
#include "core/properties/buttonproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/stringproperty.h"
namespace campvis {
class CmBatchGeneration : public AutoEvaluationPipeline {
......
......@@ -35,7 +35,7 @@ namespace campvis {
CampcomMhdReceiver::CampcomMhdReceiver()
: AbstractProcessor()
, p_address("ServerAddress", "Server Address", "127.0.0.1")
, p_address("ServerAddress", "Server Address", "127.0.0.1", StringProperty::BASIC_STRING)
, p_connect("Connect", "Connect to Server")
, p_targetImageID("targetImageName", "Target Image ID", "CampcomMhdReceiver.output", DataNameProperty::WRITE)
, p_imageOffset("ImageOffset", "Image Offset in mm", tgt::vec3(0.f), tgt::vec3(-10000.f), tgt::vec3(10000.f), tgt::vec3(0.1f))
......
......@@ -37,6 +37,7 @@
#include "core/properties/buttonproperty.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/stringproperty.h"
namespace campvis {
/**
......
......@@ -53,7 +53,7 @@ namespace campvis {
DevilImageReader::DevilImageReader(IVec2Property* viewportSizeProp)
: VisualizationProcessor(viewportSizeProp)
, p_url("url", "Image URL", "")
, p_url("url", "Image URL", "", StringProperty::OPEN_FILENAME)
, p_targetImageID("targetImageName", "Target Image ID", "DevilImageReader.output", DataNameProperty::WRITE)
, p_importType("ImportType", "Import Type", importOptions, 3)
, _shader(nullptr)
......
......@@ -31,6 +31,7 @@
#include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/optionproperty.h"
#include "core/properties/stringproperty.h"
namespace tgt {
class Shader;
......
......@@ -46,7 +46,7 @@ namespace campvis {
DevilImageWriter::DevilImageWriter()
: AbstractProcessor()
, p_inputImage("InputImage", "Input Image ID", "DevilImageWriter.input", DataNameProperty::READ)
, p_url("url", "Image URL", "")
, p_url("url", "Image URL", "", StringProperty::SAVE_FILENAME)
{
addProperty(p_inputImage);
addProperty(p_url);
......
......@@ -32,6 +32,7 @@
#include "core/properties/datanameproperty.h"
#include "core/properties/genericproperty.h"
#include "core/properties/optionproperty.h"
#include "core/properties/stringproperty.h"
#include "core/tools/weaklytypedpointer.h"
namespace tgt {
......
......@@ -31,7 +31,7 @@
namespace campvis {
AbstractImageReader::AbstractImageReader()
: p_url("url", "Image URL", "")
: p_url("url", "Image URL", "", StringProperty::OPEN_FILENAME)
, p_targetImageID("targetImageName", "Target Image ID", "AbstractImageReader.output", DataNameProperty::WRITE)
{
}
......@@ -39,29 +39,9 @@ namespace campvis {
AbstractImageReader::~AbstractImageReader() {
}
void AbstractImageReader::setURL(StringProperty p_url) {
this->p_url.setValue(p_url.getValue());
}
void AbstractImageReader::setTargetImageId(DataNameProperty& targetImageId) {
this->p_targetImageID.setValue(targetImageId.getValue());
std::set<AbstractProperty*> sharedProperties = targetImageId.getSharedProperties();
for(std::set<AbstractProperty*>::iterator it = sharedProperties.begin(); it != sharedProperties.end(); ++it) {
this->p_targetImageID.addSharedProperty(*it);
}
}
void AbstractImageReader::setTargetImageId(std::string imageId) {
this->p_targetImageID.setValue(imageId);
}
void AbstractImageReader::setTargetImageIdSharedProperty(DataNameProperty* sharedProperty) {
this->p_targetImageID.addSharedProperty(sharedProperty);
}
bool AbstractImageReader::acceptsExtension(const std::string& extension) {
for(std::vector<std::string>::iterator it = this->_ext.begin(); it != this->_ext.end(); ++it) {
if(*it == extension) {
bool AbstractImageReader::acceptsExtension(const std::string& extension) const {
for (std::vector<std::string>::const_iterator it = this->_ext.begin(); it != this->_ext.end(); ++it) {
if (*it == extension) {
return true;
}
}
......
......@@ -36,6 +36,7 @@
#include "core/pipeline/abstractprocessor.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/stringproperty.h"
namespace campvis {
/**
......@@ -64,22 +65,13 @@ namespace campvis {
*
* \param extension The extension to be checked
**/
virtual bool acceptsExtension(const std::string& extension);
virtual bool acceptsExtension(const std::string& extension) const;
/// functions to set the property of the readers
virtual void setURL(StringProperty p_url);
virtual void setTargetImageId(DataNameProperty& targetImageId);
virtual void setTargetImageId(std::string imageId);
virtual void setTargetImageIdSharedProperty(DataNameProperty* sharedProperty);
public:
StringProperty p_url; ///< URL for file to read
DataNameProperty p_targetImageID; ///< image ID for read image
protected:
std::vector<std::string> _ext;
private:
std::vector<std::string> _ext; ///< accepted extensions
};
......
......@@ -43,7 +43,7 @@ namespace campvis {
GenericImageReader::GenericImageReader()
: AbstractProcessor()
, p_url("url", "Image URL", "")
, p_url("url", "Image URL", "", StringProperty::OPEN_FILENAME)
{
addProperty(p_url);
p_url.s_changed.connect(this, &GenericImageReader::onUrlPropertyChanged);
......
......@@ -36,6 +36,7 @@
#include "core/properties/datanameproperty.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/metaproperty.h"
#include "core/properties/stringproperty.h"
#include "modules/io/processors/csvdimagereader.h"
#include "modules/io/processors/ltfimagereader.h"
......
......@@ -43,7 +43,7 @@ namespace campvis {
MhdImageWriter::MhdImageWriter()
: AbstractProcessor()
, p_inputImage("InputImage", "Input Image", "image", DataNameProperty::READ)
, p_fileName("FileName", "File Name", "")
, p_fileName("FileName", "File Name", "", StringProperty::SAVE_FILENAME)
, p_saveFile("SaveFile", "Save to File")
{
addProperty(p_inputImage, VALID);
......
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