2017-01-09 16:55:03 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 2017 James Turner zakalawe@mac.com
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program 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
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2016-12-22 16:59:19 +00:00
|
|
|
#include "elementdatamodel.h"
|
|
|
|
|
|
|
|
#include "fgcanvaselement.h"
|
|
|
|
#include "localprop.h"
|
|
|
|
|
|
|
|
ElementDataModel::ElementDataModel(QObject* pr)
|
|
|
|
: QAbstractTableModel(pr)
|
|
|
|
, m_element(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElementDataModel::setElement(FGCanvasElement *e)
|
|
|
|
{
|
|
|
|
beginResetModel();
|
|
|
|
m_element = e;
|
|
|
|
computeKeys();
|
|
|
|
endResetModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ElementDataModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return m_keys.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ElementDataModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant ElementDataModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (!index.isValid() || (index.row() >= m_keys.size())) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray key = m_keys.at(index.row());
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
if (index.column() == 0) {
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2017-01-26 23:14:48 +00:00
|
|
|
if (key == "position") {
|
|
|
|
return m_element->property()->position();
|
|
|
|
}
|
|
|
|
|
2016-12-22 16:59:19 +00:00
|
|
|
return m_element->property()->value(key.constData(), QVariant());
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElementDataModel::computeKeys()
|
|
|
|
{
|
|
|
|
m_keys.clear();
|
|
|
|
if (m_element == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalProp *prop = m_element->property();
|
|
|
|
|
|
|
|
QByteArrayList directProps = QByteArrayList() << "fill" << "stroke" <<
|
|
|
|
"background" <<
|
|
|
|
"text" <<
|
2016-12-22 17:15:50 +00:00
|
|
|
"clip" << "file" << "src"
|
2016-12-22 16:59:19 +00:00
|
|
|
"font" << "character-size" <<
|
2016-12-27 08:56:35 +00:00
|
|
|
"z-index" << "visible";
|
2016-12-22 16:59:19 +00:00
|
|
|
|
|
|
|
Q_FOREACH (QByteArray b, directProps) {
|
|
|
|
if (prop->hasChild(b)) {
|
|
|
|
m_keys.append(b);
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 23:14:48 +00:00
|
|
|
|
|
|
|
m_keys.append("position");
|
2016-12-22 16:59:19 +00:00
|
|
|
}
|