diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-05-22 10:22:08 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-22 10:22:08 -0700 |
commit | 9c3b512701c59955350f317eb6d19e6fdc93f546 (patch) | |
tree | e52e2cfd54e54f814f01aab5a99c9c631df1eda3 | |
parent | 56c58bdd24451352e1f2a538c145f865b2546ac2 (diff) | |
parent | f73660cc0916bd52adfeaeb97c836176431b7d97 (diff) | |
download | subsurface-9c3b512701c59955350f317eb6d19e6fdc93f546.tar.gz |
Merge branch 'comboBoxDelegate' of https://github.com/tcanabrava/subsurface
-rw-r--r-- | qt-ui/maintab.cpp | 2 | ||||
-rw-r--r-- | qt-ui/modeldelegates.cpp | 23 | ||||
-rw-r--r-- | qt-ui/modeldelegates.h | 8 | ||||
-rw-r--r-- | trash.png | bin | 0 -> 4870 bytes |
4 files changed, 33 insertions, 0 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index a52058816..c172deeea 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -12,6 +12,7 @@ #include "../helpers.h" #include "../statistics.h" #include "divelistview.h" +#include "modeldelegates.h" #include <QLabel> #include <QDebug> @@ -81,6 +82,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui->cylinders->setColumnWidth( CylindersModel::REMOVE, 24); ui->cylinders->horizontalHeader()->setResizeMode (CylindersModel::REMOVE , QHeaderView::Fixed); + ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate()); ui->weights->setColumnWidth( WeightModel::REMOVE, 24); ui->cylinders->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed); } diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index be47198e2..0164deedc 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -9,6 +9,7 @@ #include <QSortFilterProxyModel> #include <QStyle> #include <QStyleOption> +#include <QComboBox> StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent): QStyledItemDelegate(parent), @@ -47,3 +48,25 @@ QSize StarWidgetsDelegate::sizeHint(const QStyleOptionViewItem& option, const QM { return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS-1), IMG_SIZE); } + +QWidget* TankInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QComboBox *comboDelegate = new QComboBox(parent); + TankInfoModel *model = new TankInfoModel; + QString data = index.model()->data(index, Qt::DisplayRole).toString(); + qDebug() << "Tentando pegar " << data; + comboDelegate->setModel(model); + int i; + for(i = 0; i < model->rowCount(); i++){ + if (model->data(model->index(i,0), Qt::DisplayRole).toString() == data){ + break; + } + } + if (i != model->rowCount()) + comboDelegate->setCurrentIndex(i); + return comboDelegate; +} + +TankInfoDelegate::TankInfoDelegate(QObject* parent): QStyledItemDelegate(parent) +{ +} diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h index 5f90a3061..0a56d14d6 100644 --- a/qt-ui/modeldelegates.h +++ b/qt-ui/modeldelegates.h @@ -12,4 +12,12 @@ public: private: QWidget *parentWidget; }; + +class TankInfoDelegate : public QStyledItemDelegate{ + Q_OBJECT +public: + explicit TankInfoDelegate(QObject* parent = 0); + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; +}; + #endif diff --git a/trash.png b/trash.png Binary files differnew file mode 100644 index 000000000..e3e835dee --- /dev/null +++ b/trash.png |