1
0
Fork 0

Remote-canvas element highlighting.

Debugging aid to correlate property tree items to their visual
location.
This commit is contained in:
James Turner 2016-12-22 17:15:50 +00:00
parent 980be9f479
commit a42900bef5
8 changed files with 78 additions and 10 deletions

View file

@ -35,7 +35,7 @@ int CanvasTreeModel::rowCount(const QModelIndex &parent) const
int CanvasTreeModel::columnCount(const QModelIndex &parent) const
{
return 2;
return 1;
}
QVariant CanvasTreeModel::data(const QModelIndex &index, int role) const
@ -48,6 +48,12 @@ QVariant CanvasTreeModel::data(const QModelIndex &index, int role) const
switch (role) {
case Qt::DisplayRole:
return e->property()->value("id", QVariant("<noid>"));
case Qt::CheckStateRole:
return e->property()->value("visible", true);
default:
break;
}
return QVariant();
@ -100,6 +106,27 @@ QModelIndex CanvasTreeModel::parent(const QModelIndex &child) const
return indexForGroup(const_cast<FGCanvasGroup*>(e->parentGroup()));
}
Qt::ItemFlags CanvasTreeModel::flags(const QModelIndex &index) const
{
return QAbstractItemModel::flags(index) | Qt::ItemIsUserCheckable;
}
bool CanvasTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
FGCanvasElement* e = static_cast<FGCanvasElement*>(index.internalPointer());
if (!e) {
return false;
}
if (role == Qt::CheckStateRole) {
e->property()->setProperty("visible", value);
emit dataChanged(index, index, QVector<int>() << Qt::CheckStateRole);
return true;
}
return false;
}
QModelIndex CanvasTreeModel::indexForGroup(FGCanvasGroup* group) const
{
if (!group) {

View file

@ -23,6 +23,10 @@ protected:
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const override;
virtual QModelIndex parent(const QModelIndex &child) const override;
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override;
private:
QModelIndex indexForGroup(FGCanvasGroup *group) const;

View file

@ -58,9 +58,10 @@ void ElementDataModel::computeKeys()
QByteArrayList directProps = QByteArrayList() << "fill" << "stroke" <<
"background" <<
"text" <<
"clip" << "file" <<
"clip" << "file" << "src"
"font" << "character-size" <<
"z-index" << "visible";
"z-index" << "visible" <<
"stroke";
Q_FOREACH (QByteArray b, directProps) {
if (prop->hasChild(b)) {

View file

@ -40,6 +40,16 @@ LocalProp *FGCanvasElement::property() const
return const_cast<LocalProp*>(_propertyRoot);
}
void FGCanvasElement::setHighlighted(bool hilighted)
{
_highlighted = hilighted;
}
bool FGCanvasElement::isHighlighted() const
{
return _highlighted;
}
FGCanvasElement::FGCanvasElement(FGCanvasGroup* pr, LocalProp* prop) :
QObject(pr),
_propertyRoot(prop),
@ -95,8 +105,6 @@ void FGCanvasElement::paint(FGCanvasPaintContext *context) const
p->setBrush(_fillColor);
}
doPaint(context);
if (_hasClip) {

View file

@ -31,6 +31,9 @@ public:
static bool isStyleProperty(QByteArray name);
LocalProp* property() const;
void setHighlighted(bool hilighted);
bool isHighlighted() const;
protected:
virtual void doPaint(FGCanvasPaintContext* context) const;
@ -63,6 +66,8 @@ private:
friend class FGCanvasGroup;
bool _visible = true;
bool _highlighted = false;
mutable bool _transformsDirty = true;
mutable bool _styleDirty = true;

View file

@ -185,6 +185,21 @@ void FGCanvasPath::doPaint(FGCanvasPaintContext *context) const
break;
}
if (isHighlighted()) {
context->painter()->setPen(QPen(Qt::red, 1));
context->painter()->setBrush(Qt::NoBrush);
switch (_paintType) {
case Rect:
case RoundRect:
context->painter()->drawRect(_rect);
break;
case Path:
context->painter()->drawRect(_painterPath.boundingRect());
break;
}
}
}
void FGCanvasPath::markStyleDirty()

View file

@ -6,6 +6,7 @@
#include <QJsonObject>
#include <QJsonValue>
#include <QSettings>
#include <QItemSelectionModel>
#include "fgqcanvasfontcache.h"
#include "fgqcanvasimageloader.h"
@ -21,7 +22,7 @@ TemporaryWidget::TemporaryWidget(QWidget *parent) :
connect(ui->connectButton, &QPushButton::clicked, this, &TemporaryWidget::onStartConnect);
restoreSettings();
connect(ui->treeView, &QAbstractItemView::clicked, this, &TemporaryWidget::onCanvasTreeElementClicked);
connect(ui->treeView->selectionModel(), &QItemSelectionModel::currentChanged, this, &TemporaryWidget::onTreeCurrentChanged);
}
TemporaryWidget::~TemporaryWidget()
@ -162,10 +163,18 @@ void TemporaryWidget::onSocketClosed()
ui->stack->setCurrentIndex(0);
}
void TemporaryWidget::onCanvasTreeElementClicked(const QModelIndex &index)
void TemporaryWidget::onTreeCurrentChanged(const QModelIndex &previous, const QModelIndex &current)
{
FGCanvasElement* e = m_canvasModel->elementFromIndex(index);
FGCanvasElement* prev = m_canvasModel->elementFromIndex(previous);
if (prev) {
prev->setHighlighted(false);
}
FGCanvasElement* e = m_canvasModel->elementFromIndex(current);
m_elementModel->setElement(e);
if (e) {
e->setHighlighted(true);
}
}
void TemporaryWidget::saveSettings()

View file

@ -29,8 +29,7 @@ private Q_SLOTS:
void onSocketClosed();
void onCanvasTreeElementClicked(const QModelIndex& index);
void onTreeCurrentChanged(const QModelIndex &previous, const QModelIndex &current);
private:
void saveSettings();
void restoreSettings();