Added ComboBoxDelegate class and using it as delegate for type columns in table view.
This commit is contained in:
@ -34,6 +34,7 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
|||||||
dialogs/edititemdialog.h dialogs/edititemdialog.cpp
|
dialogs/edititemdialog.h dialogs/edititemdialog.cpp
|
||||||
dialogs/settingsdialog.h dialogs/settingsdialog.cpp
|
dialogs/settingsdialog.h dialogs/settingsdialog.cpp
|
||||||
views/itemdetailmapper.h views/itemdetailmapper.cpp
|
views/itemdetailmapper.h views/itemdetailmapper.cpp
|
||||||
|
widgets/comboboxdelegate.h widgets/comboboxdelegate.cpp
|
||||||
)
|
)
|
||||||
# Define target properties for Android with Qt 6 as:
|
# Define target properties for Android with Qt 6 as:
|
||||||
# set_property(TARGET ${TARGET_APP} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
# set_property(TARGET ${TARGET_APP} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||||
|
|||||||
@ -15,7 +15,9 @@
|
|||||||
#include "dialogs/settingsdialog.h"
|
#include "dialogs/settingsdialog.h"
|
||||||
#include "genericcore.h"
|
#include "genericcore.h"
|
||||||
#include "model/generalsortfiltermodel.h"
|
#include "model/generalsortfiltermodel.h"
|
||||||
|
#include "model/metadata.h"
|
||||||
#include "model/tablemodel.h"
|
#include "model/tablemodel.h"
|
||||||
|
#include "widgets/comboboxdelegate.h"
|
||||||
|
|
||||||
static QStandardPaths::StandardLocation standardLocation = QStandardPaths::HomeLocation;
|
static QStandardPaths::StandardLocation standardLocation = QStandardPaths::HomeLocation;
|
||||||
static QString updateTextClean = "Do you want to update the application now?";
|
static QString updateTextClean = "Do you want to update the application now?";
|
||||||
@ -46,11 +48,7 @@ MainWindow::MainWindow(QWidget* parent)
|
|||||||
restoreGeometry(settings.value("geometry").toByteArray());
|
restoreGeometry(settings.value("geometry").toByteArray());
|
||||||
restoreState(settings.value("windowState").toByteArray());
|
restoreState(settings.value("windowState").toByteArray());
|
||||||
|
|
||||||
// m_tableModel = m_core->getModel();
|
setupModelViews();
|
||||||
// ui->tableView->setModel(m_tableModel.get());
|
|
||||||
m_proxyModel = m_core->getSortFilterModel();
|
|
||||||
ui->tableView->setModel((QAbstractItemModel*)m_proxyModel.get());
|
|
||||||
ui->tableView->setSortingEnabled(true);
|
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
createHelpMenu();
|
createHelpMenu();
|
||||||
@ -343,6 +341,20 @@ void MainWindow::execSettingsDialog() {
|
|||||||
delete settingsDialog;
|
delete settingsDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupModelViews() {
|
||||||
|
// m_tableModel = m_core->getModel();
|
||||||
|
// ui->tableView->setModel(m_tableModel.get());
|
||||||
|
m_proxyModel = m_core->getSortFilterModel();
|
||||||
|
|
||||||
|
ComboboxDelegate* shareTypeDelegate = new ComboboxDelegate(SHARE_TYPES, this);
|
||||||
|
ComboboxDelegate* biddingTypeDelegate = new ComboboxDelegate(BIDDING_TYPES, this);
|
||||||
|
ui->tableView->setItemDelegateForColumn(3, shareTypeDelegate);
|
||||||
|
ui->tableView->setItemDelegateForColumn(5, biddingTypeDelegate);
|
||||||
|
|
||||||
|
ui->tableView->setModel((QAbstractItemModel*)m_proxyModel.get());
|
||||||
|
ui->tableView->setSortingEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::createActions() {
|
void MainWindow::createActions() {
|
||||||
// TODO add generic menu actions (file/new, edit/cut, ...)
|
// TODO add generic menu actions (file/new, edit/cut, ...)
|
||||||
createFileActions();
|
createFileActions();
|
||||||
|
|||||||
@ -7,8 +7,8 @@
|
|||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QUndoStack;
|
class QUndoStack;
|
||||||
|
|
||||||
class QUndoView;
|
class QUndoView;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
@ -110,6 +110,7 @@ class MainWindow : public QMainWindow {
|
|||||||
unique_ptr<EditItemDialog> m_editItemDialog;
|
unique_ptr<EditItemDialog> m_editItemDialog;
|
||||||
|
|
||||||
/// Setup functions
|
/// Setup functions
|
||||||
|
void setupModelViews();
|
||||||
void createActions();
|
void createActions();
|
||||||
void createFileActions();
|
void createFileActions();
|
||||||
void createUndoActions();
|
void createUndoActions();
|
||||||
|
|||||||
66
UIs/BeetRoundWidgets/widgets/comboboxdelegate.cpp
Normal file
66
UIs/BeetRoundWidgets/widgets/comboboxdelegate.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "comboboxdelegate.h"
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QStringListModel>
|
||||||
|
#include "model/metadata.h"
|
||||||
|
|
||||||
|
ComboboxDelegate::ComboboxDelegate(const QStringList items, QObject* parent)
|
||||||
|
: QStyledItemDelegate(parent)
|
||||||
|
, m_types(new QStringListModel(items)) {}
|
||||||
|
|
||||||
|
void ComboboxDelegate::paint(QPainter* painter,
|
||||||
|
const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index) const {
|
||||||
|
QStyledItemDelegate::paint(painter, option, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize ComboboxDelegate::sizeHint(const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index) const {
|
||||||
|
return QStyledItemDelegate::sizeHint(option, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget* ComboboxDelegate::createEditor(QWidget* parent,
|
||||||
|
const QStyleOptionViewItem& /*option*/,
|
||||||
|
const QModelIndex& /*index*/) const {
|
||||||
|
QComboBox* editor = new QComboBox(parent);
|
||||||
|
editor->setModel(m_types);
|
||||||
|
return editor;
|
||||||
|
// return QStyledItemDelegate::createEditor(parent, option, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboboxDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const {
|
||||||
|
/// Get the value via index of the Model
|
||||||
|
const QAbstractItemModel* localModel = index.model();
|
||||||
|
QString headerText = localModel->headerData(index.column(), Qt::Horizontal).toString();
|
||||||
|
|
||||||
|
UserRoles role = GET_ROLE_FOR_COLUMN(index.column());
|
||||||
|
const bool isShareType = SHARE_TYPE_ROLES.contains(role);
|
||||||
|
const bool isBiddingType = BIDDING_TYPE_ROLES.contains(role);
|
||||||
|
/// Put the value into the SpinBox
|
||||||
|
if (isShareType) {
|
||||||
|
const QString valueString = index.model()->data(index, ShareTypeRole).toString();
|
||||||
|
int value = SHARE_TYPES.indexOf(valueString);
|
||||||
|
|
||||||
|
QComboBox* combobox = static_cast<QComboBox*>(editor);
|
||||||
|
combobox->setCurrentIndex(value);
|
||||||
|
// QStyledItemDelegate::setEditorData(editor, index);
|
||||||
|
} else if (isBiddingType) {
|
||||||
|
const QString valueString = index.model()->data(index, BiddingTypeRole).toString();
|
||||||
|
int value = BIDDING_TYPES.indexOf(valueString);
|
||||||
|
|
||||||
|
// Put the value into the SpinBox
|
||||||
|
QComboBox* combobox = static_cast<QComboBox*>(editor);
|
||||||
|
combobox->setCurrentIndex(value);
|
||||||
|
// QStyledItemDelegate::setEditorData(editor, index);
|
||||||
|
} else {
|
||||||
|
qCritical() << "Could not find the correct type role for index:" << index << "!!!";
|
||||||
|
QComboBox* combobox = static_cast<QComboBox*>(editor);
|
||||||
|
combobox->setCurrentIndex(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ComboboxDelegate::setModelData(QWidget* editor,
|
||||||
|
QAbstractItemModel* model,
|
||||||
|
const QModelIndex& index) const {
|
||||||
|
QStyledItemDelegate::setModelData(editor, model, index);
|
||||||
|
}
|
||||||
30
UIs/BeetRoundWidgets/widgets/comboboxdelegate.h
Normal file
30
UIs/BeetRoundWidgets/widgets/comboboxdelegate.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef COMBOBOXDELEGATE_H
|
||||||
|
#define COMBOBOXDELEGATE_H
|
||||||
|
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
|
class QStringListModel;
|
||||||
|
class ComboboxDelegate : public QStyledItemDelegate {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ComboboxDelegate(const QStringList items, QObject* parent = nullptr);
|
||||||
|
|
||||||
|
/// QAbstractItemDelegate interface
|
||||||
|
public:
|
||||||
|
void paint(QPainter* painter,
|
||||||
|
const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex& index) const override;
|
||||||
|
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
|
QWidget* createEditor(QWidget* parent,
|
||||||
|
const QStyleOptionViewItem& option,
|
||||||
|
const QModelIndex&) const override;
|
||||||
|
void setEditorData(QWidget* editor, const QModelIndex& index) const override;
|
||||||
|
void setModelData(QWidget* editor,
|
||||||
|
QAbstractItemModel* model,
|
||||||
|
const QModelIndex& index) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QStringListModel* m_types = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COMBOBOXDELEGATE_H
|
||||||
Reference in New Issue
Block a user