32 #include <QFileDialog>
36 #include <QMessageBox>
41 #include <QApplication>
45 QString fName, QObject* myParent, QString metaFile) :
46 QAbstractTableModel(myParent),
47 _resetMutex(new QMutex()),
58 if (!metaFile.isEmpty()) {
65 connect(
this, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
90 int col = ind.column();
91 QString key =
_keys[row];
99 if ((row >= 0) && (row <
_keys.size())) {
104 key.remove(0,
_prefix.length());
120 if (val.startsWith(
'@')) {
121 QString ref = val.mid(1);
125 else if(role == Qt::DisplayRole) {
126 val = tr(
"[invalid reference to %1]").arg(ref);
133 QString typestring =
getType(key);
134 QVariant::Type
type = mapper[typestring];
135 Q_ASSERT(res.canConvert(type));
141 if (role == Qt::DisplayRole) {
144 return getValue(key +
".editorpriority").toUInt();
149 case Qt::ToolTipRole:
152 return ret.isEmpty() ? QVariant() : ret;
156 case Qt::ForegroundRole:
158 return QColor(Qt::lightGray);
162 case Qt::BackgroundRole:
163 switch (
getValue(key+
".editorpriority").toInt()) {
165 return QColor(
"#8f8");
167 return QColor(
"#ff8");
169 return QColor(
"#f80");
175 case Qt::CheckStateRole:
178 const bool& checked =
isSet(key) ?
181 return checked ? Qt::Checked : Qt::Unchecked;
185 case Qt::StatusTipRole:
189 if(ret.startsWith(
'@')) {
190 return tr(
"link to: %1").arg(ret.mid(1));
196 case Qt::DecorationRole:
200 if(ret.startsWith(
'@')) {
201 return QIcon(
":/icons/symlink.png");
213 const QModelIndex& ind,
const QVariant& value,
int role) {
220 case Qt::DisplayRole:
221 if ((ind.row() >= 0) && (ind.row() <
_keys.size())) {
222 switch (ind.column()) {
227 if (value.canConvert(QVariant::String)) {
228 QString oldName =
_keys[ind.row()];
233 newName += value.toString();
234 if (oldName == newName)
243 emit dataChanged(ind, ind);
248 if (value.canConvert(QVariant::String)) {
249 QString valueStr = value.toString();
250 QString keyStr =
_keys[ind.row()];
258 QTimer::singleShot(0,
this, SLOT(
_update()));
261 emit dataChanged(index(ind.row(), 0), ind);
266 if (value.canConvert(QVariant::Int)) {
268 int valueInt = value.toInt();
269 QString valueStr = QVariant(valueInt).toString();
270 if (valueInt < 0 || valueInt > 3) {
276 if (
isSet(
_keys[ind.row()] +
".editorpriority")) {
279 emit dataChanged(index(ind.row(), 0), ind);
290 emit dataChanged(index(ind.row(), 0), ind);
298 case Qt::CheckStateRole:
301 bool checked (value.toBool());
303 emit dataChanged(index(ind.row(),0),ind);
304 if (
_keys[ind.row()].contains(
"active") && checked ==
true){
308 if (
_keys[ind.row()].contains(
"active") && checked ==
false){
319 QStringList inputsOfOneSlot;
320 int parameterIndex = 0;
321 for (
int p = 0; p <
_keys.size(); p++){
322 if (
_keys[p].contains(
"active")){
327 for (
int i = 0; i < tmpPrefix.size(); i++){
328 if (tmpPrefix.at(i) ==
'.'){
329 tmpPrefix.truncate(i);
332 for (
int i = 0; i <
getInputs(tmpPrefix).size(); i++){
334 inputsOfOneSlot =
getValue(tmpPrefix +
"."+
getInputs(tmpPrefix).at(i)).split(
";");
335 for (
int o = 0; o < inputsOfOneSlot.size(); o++){
337 for (
int p = 0; p <
_keys.size(); p++){
338 if (
_keys[p].contains(
"active")){
349 for (
int p = 0; p <
_keys.size(); p++){
350 if (
_keys[p].contains(
"active")){
365 QStringList outputsOfOneSlot;
366 int parameterIndex = 0;
367 for (
int p = 0; p <
_keys.size(); p++){
368 if (
_keys[p].contains(
"active")){
373 for (
int i = 0; i < tmpPrefix.size(); i++){
374 if (tmpPrefix.at(i) ==
'.'){
375 tmpPrefix.truncate(i);
378 for (
int i = 0; i <
getOutputs(tmpPrefix).size(); i++){
381 for (
int o = 0; o < outputsOfOneSlot.size(); o++){
383 for (
int p = 0; p <
_keys.size(); p++){
384 if (
_keys[p].contains(
"active")){
395 for (
int p = 0; p <
_keys.size(); p++){
396 if (
_keys[p].contains(
"active")){
410 QStringList outputsOfOneSlot;
411 int parameterIndex = 0;
412 for (
int p = 0; p <
_keys.size(); p++){
413 if (
_keys[p].contains(
"active")){
420 for (
int i = 0; i < tmpPrefix.size(); i++){
421 if (tmpPrefix.at(i) ==
'.'){
422 tmpPrefix.truncate(i);
425 for (
int i = 0; i <
getOutputs(tmpPrefix).size(); i++){
428 for (
int o = 0; o < outputsOfOneSlot.size(); o++){
443 int parameterIndex=0;
444 for (
int p = 0; p <
_keys.size(); p++){
445 if (
_keys[p].contains(
"active")){
462 return Qt::NoItemFlags;
464 Q_ASSERT(ind.row() >= 0);
465 Q_ASSERT(ind.row() <
_keys.size());
467 Qt::ItemFlags res = Qt::NoItemFlags;
469 QVariant::Type dataType;
471 switch (ind.column()) {
474 res = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
476 res = res | Qt::ItemIsEditable;
481 res = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
484 dataType =
data(ind).type();
486 && paramType ==
"bool") {
488 res = res | Qt::ItemIsUserCheckable;
492 res = res | Qt::ItemIsEditable;
494 if (dataType == QVariant::String &&
495 !paramType.contains(QRegExp(
"^\\{\\s*\\w.*\\}\\s*$"))) {
498 res = res | Qt::ItemIsDropEnabled;
504 res = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
515 Qt::Orientation orientation,
int role)
const {
517 if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
520 return tr(
"Parameter");
524 return tr(
"Priority");
527 return QAbstractTableModel::headerData(section,orientation,role);
531 const QModelIndex& parentInd) {
535 && (row >= 0) && (row ==
_keys.size()) && (count > 0)) {
536 beginInsertRows(parentInd, row, row + count - 1);
546 name += QString(
"new%1").arg(i + offset);
567 Q_ASSERT(
_keys.size() == (row + count));
576 const QModelIndex& parentInd) {
583 if ((count > 0) && (row >= 0) && ((row + count) <=
_keys.size())) {
587 beginRemoveRows(parentInd, row, row + count - 1);
589 for (
int i = row; i < row + count; i++) {
601 emit dataChanged(index(row, 0), index(row + count, 1));
629 qDebug(
"(DD) disabled dynamic-update");
632 else if (QApplication::instance()) {
642 qDebug(
"(WW) no qapplication, skipping dynamic loading");
669 if (tempList.size() > 0) {
686 const QModelIndex&,
const QModelIndex &bottomRight) {
696 QString fromDialog = fName;
697 if (fromDialog.isEmpty()) {
699 if (guess.isEmpty()) {
702 settings.value(
"recentFileList").toStringList();
703 if (files.size() > 0)
706 guess = QDir::homePath();
708 fromDialog = QFileDialog::getOpenFileName(0, tr(
"Open File"),
709 guess, tr(
"ParameterFiles (*.wrp);;All Files (*.*)"));
711 if (fromDialog.isEmpty()) {
714 else if (!QFileInfo(fromDialog).isFile()) {
715 QMessageBox::warning(0, tr(
"Error loading file"),
716 tr(
"File <em>%1</em> does not exist or is no file!")
719 else if (!QFileInfo(fromDialog).isReadable()) {
720 QMessageBox::warning(0, tr(
"Error loading file"),
721 tr(
"File <em>%1</em> is not readable!").arg(fromDialog));
737 if (!fName.isEmpty())
739 if (!name.isEmpty()) {
749 if (fName.isEmpty() || fName ==
_fileName)
778 return _prefix.isEmpty() ?
true :
788 if (fName.isEmpty()) {
796 foreach (
const QString& cur, classes) {
818 emit dataChanged(index(0,1),index(
rowCount()-1,1));
843 name = name.section(
".",0,0);
844 QString cName =
getValue(name +
".type").toLower();
856 return list.filter(QRegExp(
"^\\s*"+
_prefix+
"\\.",Qt::CaseInsensitive));
859 return list.filter(QRegExp(
"^\\s*"+
_prefix,Qt::CaseInsensitive));
864 QSet<QString> result;
865 for (
int ii = 0; ii < list.size(); ii++) {
866 QString cur = list[ii].section(
".",0,0);
869 return result.toList();
878 for (
int ii = 0; ii < objects.size(); ii++) {
881 tmp.replaceInStrings(QRegExp(
"(^.*$)"), objects[ii]+
".\\1");
893 foreach (
const QString& cur, list) {
894 if (!cur.endsWith(
".editorpriority", Qt::CaseInsensitive)) {
906 foreach (
const QString& cur, list) {
922 if (fileInfo.exists()) {
924 res = pFile.
get(cName +
"." + parName.section(
".",1) +
".type");
930 if (tmplType && res.contains(
931 QRegExp(
"^\\s*(.*<\\s*T\\s*>.*|T)\\s*$",Qt::CaseInsensitive))) {
932 parName = parName.section(
".",0,0);
933 QString tType =
getValue(parName +
".templatetype");
934 if(tType.isEmpty()) {
935 tType =
getDefault(parName +
".templatetype");
938 QRegExp(
"<\\s*T\\s*>",Qt::CaseInsensitive),
939 QString(
"<%1>").arg(tType));
941 QRegExp(
"^\\s*T\\s*$",Qt::CaseInsensitive),tType);
960 bool existed =
isSet(parName);
963 if (parName.endsWith(
".editorcomment", Qt::CaseInsensitive)) {
971 int i = keys.indexOf(parName);
973 emit dataChanged(index(i, 1), index(i, 1));
986 int pos =
_keys.indexOf(parName);
988 beginRemoveRows(QModelIndex(),pos,pos);
1017 if (value < 0 || value > 3) {
1027 Qt::DropActions ParameterFileModel::supportedDropActions()
const {
1028 return Qt::CopyAction | Qt::MoveAction;
1031 QStringList ParameterFileModel::mimeTypes()
const {
1033 list <<
"text/plain";
1034 list <<
"text/uri-list";
1038 bool ParameterFileModel::dropMimeData(
const QMimeData* mData,
1039 Qt::DropAction action,
int row,
int column,
const QModelIndex& pInd) {
1043 if (mData->hasUrls()) {
1044 QList<QUrl> urlList = mData->urls();
1045 if (urlList.size() >= 1) {
1046 content = urlList.at(0).path();
1048 for (
int ii = 1; ii < urlList.size(); ii += 1) {
1049 content +=
";" + urlList.at(ii).path();
1051 }
else if (mData->hasText()) {
1052 content = mData->text();
1054 return QAbstractTableModel::dropMimeData(mData, action,
1065 return fm.
configDir().absoluteFilePath(
"dynamics/"
1066 + QFileInfo(
_fileName).baseName() +
"_" + objName +
".wrp");
1070 objName = objName.section(
".",0,0);
1071 QString className =
getClass(objName);
1074 if (fileInfo.exists()) {
1075 MetaData tmp(fileInfo.absoluteFilePath());
1083 objName = objName.section(
".",0,0);
1084 QString className =
getClass(objName);
1087 if (fileInfo.exists()) {
1088 MetaData tmp(fileInfo.absoluteFilePath());
1096 objName = objName.section(
".",0,0);
1097 QString className =
getClass(objName);
1100 if (fileInfo.exists()) {
1101 MetaData tmp(fileInfo.absoluteFilePath());
1109 objName = objName.section(
".",0,0);
1110 QString className =
getClass(objName);
1113 if (fileInfo.exists()) {
1114 MetaData tmp(fileInfo.absoluteFilePath());
1123 objName = objName.section(
".",0,0);
1124 QString className =
getClass(objName);
1127 if (fileInfo.exists()) {
1128 MetaData tmp(fileInfo.absoluteFilePath());
1136 QString obj = name.section(
".",0,0);
1137 name = name.section(
".",-1);
1139 return (list.indexOf(QRegExp(name,Qt::CaseInsensitive)) >= 0);
1143 QString obj = name.section(
".",0,0);
1144 name = name.section(
".",-1);
1146 return (list.indexOf(QRegExp(name,Qt::CaseInsensitive)) >= 0);
1150 QString obj = name.section(
".",0,0);
1151 name = name.section(
".",-1);
1153 return (list.indexOf(QRegExp(name,Qt::CaseInsensitive)) >= 0);
1157 QString className =
getClass(slotName);
1158 QString objName = slotName.section(
".",0,0);
1161 if (fileInfo.exists()) {
1162 MetaData tmp(fileInfo.absoluteFilePath());
1170 QString className =
getClass(parName);
1171 QString objName = parName.section(
".",0,0);
1174 if (fileInfo.exists()) {
1175 MetaData tmp(fileInfo.absoluteFilePath());
1187 QString className =
getClass(parName);
1188 QString objName = parName.section(
".",0,0);
1191 QRegExp ttype(
"(.*\\.)?templatetype",Qt::CaseInsensitive);
1192 QString defaultTmplType =
getValue(
"global.templatetype");
1193 if (ttype.exactMatch(parName) && !defaultTmplType.isEmpty()) {
1194 return defaultTmplType;
1199 if (fileInfo.exists()) {
1200 MetaData tmp(fileInfo.absoluteFilePath());
bool _handleDynamics
handle dynamics by calling update-dynamics process
class for logging display and communication with external processes
void setOnlyParams(bool value)
Set property _onlyparams.
void reactivate()
Reactivate all following plugins.
void commentChanged(QString comment)
inform about editor comment change
void statusMessage(const QString &msg)
send status message
QString get(QString parameter) const
get parameter value
Declaration of class FileManager.
void erase(QString parName)
Delete a parameter from the the underlying parameter file.
virtual void save(const QString &fileName="")
Save model content to a text file.
void setMinPriority(int value)
Set property _minPriority.
Declaration of class PrefixValidator.
virtual void _update()
Update content (e.g. when prefix has changed)
QParameterFile * _parameterFile
Pointer to the ParameterFile instance storing the model content.
virtual QString setPrefix(const QString &prefix)
Change prefix.
void setHandleDynamics(bool)
set _handleDynamics
bool rename(QString oldPrefix, QString newPrefix)
rename prefix
virtual ~ParameterFileModel()
Default destructor.
Declaration of class ParameterFileModel.
bool _useMetaInfo
toggle usage of metadata
void dynamicUpdate()
inform about dynamic plugin update
QStringList getClasses() const
get classes contained in metadata file
bool metaInfoValid() const
check for available metaInfos
QString getValue(QString parName) const
Get a parameter from the underlying parameter file.
static const FileManager & instance()
get a reference to the file Manager instance
void fileNameChanged(QString fileName)
Property _fileName has changed.
QString _fileName
Store filename of the model data file.
const QParameterFile & parameterFile() const
Get const pointer of ParameterFile.
QMutex * _resetMutex
avoid multiple reset model calls
QString getDefault(QString parName) const
pass to metaInfo, use dynamic metadata if needed
bool isSet(QString parameter) const
check if a given parameter has been set
Mapping of types given as string to QVariant::type.
int _minPriority
minimum priority to be listed
QDir configDir() const
get config directory
void _updateDynamics()
update dynamic objects
QStringList getInputs(QString objName) const
Get input slots of object.
Declaration of class QParameterFile.
QString prefix() const
Get property _prefix.
void load(QString fileName, QString encoding=QString())
load parameter file
QMap< QString, QString > _classCaseMap
map to fix class name cases
QStringList getOutputs(QString objName) const
Get output slots of object.
QStringList getOutputDisplayNames(QString objName) const
Get output slots of object.
virtual void loadMetaInfo(const QString &fileName)
load metaFile
QStringList _keys
Cache stored parameter names.
Declaration of classes in the LogDecorators namespace.
Common config file information and handling.
virtual void _updatePriority(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Update filter if priority changed.
Declaration of class LogDialog.
QString getClass(QString objName, bool fixCase=false) const
get class of some given object
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Return number of table rows.
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex())
Add data to the model.
bool isMultiSlot(QString name) const
Check if some slot is a multi slot.
const MetaData * _metaInfos
ParameterFile describing classes and in-/output slots.
QStringList getInputDisplayNames(QString objName) const
Get input slots of object.
bool isParameter(QString name) const
Check if some parameter/slot is a parameter.
Qt implementation for ParameterFile class.
bool hasErrorLines()
query for possible error lines in logfile
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Access to item content.
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Data for the table headers.
bool isSet(QString parName) const
pass to QParameterFile::isSet
bool _onlyParams
only show configurable parameters
bool prefixValid() const
Check prefix.
void deactivate()
Deactivate all following plugins.
void useMetaInfoChanged(bool value)
Property _useMetadata changed.
virtual void setFileName(const QString &fileName)
Set new value for Property _fileName.
QStringList _prefixFilter(QStringList list) const
filter keys starting with the given prefix
void erase(QString parameter)
remove parameter from file
void prefixChanged(const QString &prefix)
Property _prefix has changed.
virtual bool load(const QString &fName="")
Load model content from parameterFile.
QString fileName() const
Get property _fileName.
QString getDoc(QString parName) const
pass to metaInfo, use dynamic metadata if needed
bool active() const
Returns the bool value of the Active Parameter.
bool rename(QString oldPrefix, QString newPrefix)
rename prefix
QStringList _collectObjects(QStringList list) const
Return set of objects contained in given parameter list.
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Item flags (editable etc).
bool isOutputSlot(QString name) const
Check if some parameter/slot is an output slot.
void minPriorityChanged(int value)
Property _minPriority changed.
Convert parameter types into Qt versions.
static VarTypeMap & instance()
return reference to an VarTypeMap instance
void save(QString fileName) const
save to given plain text file
void reactivatePreviousPlugins()
Reactivates all previous plugins.
charon_core_DLL_PUBLIC std::string type(const std::string &typeInfo)
void setValue(QString parName, QString value)
Set a parameter in the underlying parameter file.
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Return number of table columns.
bool useMetaInfo() const
Get property _useMetadata;.
void metaInfoChanged(bool valid)
New metadata have been loaded.
QStringList getKeyList(QString beginsWith="") const
Look for parameters beginning with a given string.
void modified(bool val)
inform about modifications
virtual bool _load()
Load data without showing OpenFile Dialog.
bool onlyParams() const
Get property _onlyparams.
void setUseMetaInfo(bool value)
Set property _useMetadata.
void onlyParamsChanged(bool value)
Property _onlyParams changed.
decorator for update dynamics dialog
virtual void clear()
Clear ParameterFile content.
QString _getDynamicMetaFile(QString objName) const
creates path to dynamic meta info file for object
QStringList _paramFilter(QStringList list) const
filter keys listed in the classes parameter section
QString getType(QString parName, bool applyTmplType=true) const
Get type of some parameter or slot.
QStringList getParameters(QString objName) const
Get parameters of object.
ParameterFileModel(QString fileName="", QObject *parent=0, QString metaFile="")
Constructor initializing the model with the given file.
void clear()
clear content
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Remove data from the model.
bool waitForFinished(int msecs=1500)
wait for process to finish
int minPriority() const
Get property _minPriority.
bool isInputSlot(QString name) const
Check if some parameter/slot is an input slot.
virtual bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Set item content.
QStringList _priorityTagFilter(QStringList list) const
filter keys containing priority information
QStringList _priorityFilter(QStringList list) const
filter keys depending on their priority
QString _prefix
Parameter prefix.