Fix updateData signal signature so it actually works + cleanups

This commit is contained in:
Artem Pavlenko 2021-03-08 13:19:11 +00:00
parent b532beccde
commit fb325f527b
3 changed files with 29 additions and 27 deletions

View file

@ -21,13 +21,12 @@
#include "layerlistmodel.hpp" #include "layerlistmodel.hpp"
#include <QIcon> #include <QIcon>
#include <QBrush>
#include <iostream>
#include <mapnik/layer.hpp> #include <mapnik/layer.hpp>
using mapnik::Map; using mapnik::Map;
LayerListModel::LayerListModel(std::shared_ptr<Map> map,QObject *parent) LayerListModel::LayerListModel(std::shared_ptr<Map> map, QObject *parent)
: QAbstractListModel(parent), : QAbstractListModel(parent),
map_(map) {} map_(map) {}
@ -37,7 +36,7 @@ int LayerListModel::rowCount(QModelIndex const&) const
return 0; return 0;
} }
QVariant LayerListModel::data(QModelIndex const& index,int role) const QVariant LayerListModel::data(QModelIndex const& index, int role) const
{ {
if (!index.isValid() || !map_) if (!index.isValid() || !map_)
return QVariant(); return QVariant();
@ -64,6 +63,13 @@ QVariant LayerListModel::data(QModelIndex const& index,int role) const
else else
return QVariant(Qt::Unchecked); return QVariant(Qt::Unchecked);
} }
else if (role == Qt::ForegroundRole)
{
if (map_->layers().at(index.row()).active())
return QBrush(QColor("black"));
else
return QBrush(QColor("lightgrey"));
}
else else
{ {
return QVariant(); return QVariant();
@ -101,7 +107,6 @@ bool LayerListModel::setData(const QModelIndex &index,
Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const
{ {
Qt::ItemFlags flags = QAbstractItemModel::flags(index); Qt::ItemFlags flags = QAbstractItemModel::flags(index);
if (index.isValid()) if (index.isValid())
flags |= Qt::ItemIsUserCheckable; flags |= Qt::ItemIsUserCheckable;
return flags; return flags;

View file

@ -29,12 +29,9 @@
#include <qscrollbar.h> #include <qscrollbar.h>
#include <qrubberband.h> #include <qrubberband.h>
#include <qdebug.h> #include <qdebug.h>
#include <iostream>
#include "layerlistmodel.hpp" #include "layerlistmodel.hpp"
#include "layer_info_dialog.hpp" #include "layer_info_dialog.hpp"
using namespace std;
LayerTab::LayerTab(QWidget* parent) LayerTab::LayerTab(QWidget* parent)
: QListView(parent) {} : QListView(parent) {}
@ -45,11 +42,11 @@ void LayerTab::paintEvent(QPaintEvent *e)
} }
void LayerTab::dataChanged(const QModelIndex &topLeft, void LayerTab::dataChanged(const QModelIndex &topLeft,
const QModelIndex &bottomRight) const QModelIndex &bottomRight,
const QVector<int> &roles)
{ {
QListView::dataChanged(topLeft, bottomRight); emit update_mapwidget();
qDebug("FIXME : update map view!"); QListView::dataChanged(topLeft, bottomRight, roles);
emit update_mapwidget();
} }
void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSelection &) void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSelection &)
@ -57,7 +54,7 @@ void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSele
QModelIndexList list = selected.indexes(); QModelIndexList list = selected.indexes();
if (list.size() != 0) if (list.size() != 0)
{ {
std::cout << "SELECTED LAYER ->" << list[0].row() << "\n"; qDebug("SELECTED LAYER -> %d",list[0].row());
emit layerSelected(list[0].row()); emit layerSelected(list[0].row());
} }
} }

View file

@ -27,19 +27,19 @@
class LayerTab : public QListView class LayerTab : public QListView
{ {
Q_OBJECT Q_OBJECT
public: public:
LayerTab(QWidget* parent=0); LayerTab(QWidget* parent=0);
void paintEvent(QPaintEvent *e); void paintEvent(QPaintEvent *e);
signals: signals:
void update_mapwidget(); void update_mapwidget();
void layerSelected(int) const; void layerSelected(int) const;
public slots: public slots:
void layerInfo(); void layerInfo();
void layerInfo2(QModelIndex const&); void layerInfo2(QModelIndex const&);
protected slots: protected slots:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void selectionChanged(const QItemSelection & selected, const QItemSelection &); void selectionChanged(const QItemSelection & selected, const QItemSelection &);
}; };
class StyleTab : public QTreeView class StyleTab : public QTreeView
@ -48,7 +48,7 @@ class StyleTab : public QTreeView
public: public:
StyleTab(QWidget* parent=0); StyleTab(QWidget* parent=0);
protected: protected:
void contextMenuEvent(QContextMenuEvent * event ); void contextMenuEvent(QContextMenuEvent * event );
}; };
#endif #endif