diff --git a/demo/viewer/layerlistmodel.cpp b/demo/viewer/layerlistmodel.cpp index 55af8e76e..ec0eaac26 100644 --- a/demo/viewer/layerlistmodel.cpp +++ b/demo/viewer/layerlistmodel.cpp @@ -21,13 +21,12 @@ #include "layerlistmodel.hpp" #include - -#include +#include #include using mapnik::Map; -LayerListModel::LayerListModel(std::shared_ptr map,QObject *parent) +LayerListModel::LayerListModel(std::shared_ptr map, QObject *parent) : QAbstractListModel(parent), map_(map) {} @@ -37,7 +36,7 @@ int LayerListModel::rowCount(QModelIndex const&) const return 0; } -QVariant LayerListModel::data(QModelIndex const& index,int role) const +QVariant LayerListModel::data(QModelIndex const& index, int role) const { if (!index.isValid() || !map_) return QVariant(); @@ -64,6 +63,13 @@ QVariant LayerListModel::data(QModelIndex const& index,int role) const else 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 { return QVariant(); @@ -101,7 +107,6 @@ bool LayerListModel::setData(const QModelIndex &index, Qt::ItemFlags LayerListModel::flags(QModelIndex const& index) const { Qt::ItemFlags flags = QAbstractItemModel::flags(index); - if (index.isValid()) flags |= Qt::ItemIsUserCheckable; return flags; diff --git a/demo/viewer/layerwidget.cpp b/demo/viewer/layerwidget.cpp index a6ab6b8f4..5733f1e63 100644 --- a/demo/viewer/layerwidget.cpp +++ b/demo/viewer/layerwidget.cpp @@ -29,12 +29,9 @@ #include #include #include -#include #include "layerlistmodel.hpp" #include "layer_info_dialog.hpp" -using namespace std; - LayerTab::LayerTab(QWidget* parent) : QListView(parent) {} @@ -45,11 +42,11 @@ void LayerTab::paintEvent(QPaintEvent *e) } void LayerTab::dataChanged(const QModelIndex &topLeft, - const QModelIndex &bottomRight) + const QModelIndex &bottomRight, + const QVector &roles) { - QListView::dataChanged(topLeft, bottomRight); - qDebug("FIXME : update map view!"); - emit update_mapwidget(); + emit update_mapwidget(); + QListView::dataChanged(topLeft, bottomRight, roles); } void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSelection &) @@ -57,7 +54,7 @@ void LayerTab::selectionChanged(const QItemSelection & selected, const QItemSele QModelIndexList list = selected.indexes(); if (list.size() != 0) { - std::cout << "SELECTED LAYER ->" << list[0].row() << "\n"; + qDebug("SELECTED LAYER -> %d",list[0].row()); emit layerSelected(list[0].row()); } } diff --git a/demo/viewer/layerwidget.hpp b/demo/viewer/layerwidget.hpp index f59196de7..6761d79a4 100644 --- a/demo/viewer/layerwidget.hpp +++ b/demo/viewer/layerwidget.hpp @@ -27,19 +27,19 @@ class LayerTab : public QListView { - Q_OBJECT - public: - LayerTab(QWidget* parent=0); - void paintEvent(QPaintEvent *e); - signals: - void update_mapwidget(); - void layerSelected(int) const; - public slots: - void layerInfo(); - void layerInfo2(QModelIndex const&); - protected slots: - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); - void selectionChanged(const QItemSelection & selected, const QItemSelection &); + Q_OBJECT +public: + LayerTab(QWidget* parent=0); + void paintEvent(QPaintEvent *e); +signals: + void update_mapwidget(); + void layerSelected(int) const; +public slots: + void layerInfo(); + void layerInfo2(QModelIndex const&); +protected slots: + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles); + void selectionChanged(const QItemSelection & selected, const QItemSelection &); }; class StyleTab : public QTreeView @@ -48,7 +48,7 @@ class StyleTab : public QTreeView public: StyleTab(QWidget* parent=0); protected: - void contextMenuEvent(QContextMenuEvent * event ); + void contextMenuEvent(QContextMenuEvent * event ); }; #endif