Skip to content

Commit

Permalink
ozwadmin-main/valuetable.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishwaldo committed Jun 5, 2020
1 parent 9440a7d commit cfba983
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion ozwadmin-main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "mainwindow.h"

Q_LOGGING_CATEGORY(ozwadmin, "ozwadmin");
Q_LOGGING_CATEGORY(ozwvd, "ozwadmin.valuedelgate");


#define DEF2STR2(x) #x
Expand All @@ -47,7 +48,8 @@ int main(int argc, char *argv[])
"qt.remoteobjects.warning=true\n"
"ozw.*.debug=true\n"
"ozw.library.debug=false\n"
"ozwadmin.debug=true\n");
"ozwadmin.debug=true\n"
"ozwadmin.*=true\n");
#else
QLoggingCategory::setFilterRules("default.debug=true");
#endif
Expand Down
3 changes: 2 additions & 1 deletion ozwadmin-main/valuetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ValueTable::ValueTable(QTOZW_ValueIds::ValueIdGenres genre, QWidget *parent) :
this->setSelectionMode(QAbstractItemView::SingleSelection);
this->setSortingEnabled(true);
this->horizontalHeader()->setSectionsMovable(true);
this->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
}

void ValueTable::setModel(QAbstractItemModel *model, QItemSelectionModel *selectionModel)
Expand All @@ -31,7 +32,7 @@ void ValueTable::setModel(QAbstractItemModel *model, QItemSelectionModel *select
this->m_proxyModel->setSelectionModel(selectionModel);
connect(this->m_proxyModel, &QAbstractItemModel::rowsInserted, this, &ValueTable::resizeContents);
connect(this->m_proxyModel, &QAbstractItemModel::rowsRemoved, this, &ValueTable::resizeContents);
connect(selectionModel, &QItemSelectionModel::currentRowChanged, this, &ValueTable::logChanges);
//connect(selectionModel, &QItemSelectionModel::currentRowChanged, this, &ValueTable::logChanges);
QTableView::setModel(this->m_proxyModel);

for (int i = 0; i <= QTOZW_ValueIds::ValueIdColumns::ValueIdCount; i++) {
Expand Down
20 changes: 16 additions & 4 deletions ozwadmin-widgets/value_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ void Value_Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option
switch (typeIndex.data().value<QTOZW_ValueIds::ValueIdTypes>()) {
case QTOZW_ValueIds::ValueIdTypes::List: {
QTOZW_ValueIDList val = index.data().value<QTOZW_ValueIDList>();
const QWidget* const widget = option.widget;
QStyle* const style = widget ? widget->style() : QApplication::style();
QStyleOptionComboBox comboBoxOption;
comboBoxOption.rect = option.rect;
comboBoxOption.state = option.state;
comboBoxOption.direction = option.direction;
//comboBoxOption.currentIcon = index.data(Qt::DecorationRole).value<QIcon>();
//comboBoxOption.currentText = index.data(Qt::DisplayRole).toString();
comboBoxOption.fontMetrics = option.fontMetrics;
const int iconWidth = style->pixelMetric(QStyle::PM_SmallIconSize, Q_NULLPTR, widget);
comboBoxOption.iconSize = QSize(iconWidth, iconWidth);
comboBoxOption.palette = option.palette;
comboBoxOption.styleObject = option.styleObject;
if (readOnly) {
comboBoxOption.state |= QStyle::State_ReadOnly;
}
comboBoxOption.currentText = val.selectedItem;

QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, painter);
QApplication::style()->drawControl(QStyle::CE_ComboBoxLabel, &comboBoxOption, painter);

QApplication::style()->drawComplexControl(QStyle::CC_ComboBox, &comboBoxOption, painter, widget);
QApplication::style()->drawControl(QStyle::CE_ComboBoxLabel, &comboBoxOption, painter, widget);
break;
}
case QTOZW_ValueIds::ValueIdTypes::Bool: {
Expand Down Expand Up @@ -102,7 +111,7 @@ QSize Value_Delegate::sizeHint(const QStyleOptionViewItem &option, const QModelI
comboBoxOption.state = option.state;
comboBoxOption.currentText = val.selectedItem;
QFontMetrics fm(option.font);
Q_FOREACH (const auto& value, val.values) {
Q_FOREACH (const auto& value, val.labels) {
hint = hint.expandedTo(qApp->style()->sizeFromContents(QStyle::CT_ComboBox,
&comboBoxOption, QSize(fm.width(value), hint.height())));
}
Expand All @@ -127,6 +136,9 @@ QSize Value_Delegate::sizeHint(const QStyleOptionViewItem &option, const QModelI

QWidget *Value_Delegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (!(index.flags() & Qt::ItemIsEditable)) {
return nullptr;
}
QModelIndex typeIndex = index.sibling(index.row(), QTOZW_ValueIds::ValueIdColumns::Type);
switch (typeIndex.data().value<QTOZW_ValueIds::ValueIdTypes>()) {
case QTOZW_ValueIds::ValueIdTypes::List: {
Expand Down
5 changes: 5 additions & 0 deletions ozwadmin-widgets/value_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include <QComboBox>
#include <QCheckBox>
#include <QSpinBox>
#include <QLoggingCategory>


Q_DECLARE_LOGGING_CATEGORY(ozwvd);


class Value_Delegate : public QStyledItemDelegate
{
Expand Down

0 comments on commit cfba983

Please sign in to comment.