mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-23 20:58:55 -05:00
Finally fixed the default item delegate creation mechanism
This commit is contained in:
parent
381faca99a
commit
94b86c3b29
@ -1122,9 +1122,6 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network
|
||||
ui_->frequencies_table_view->setColumnHidden (FrequencyList_v2::frequency_mhz_column, true);
|
||||
|
||||
// delegates
|
||||
auto frequencies_item_delegate = new QStyledItemDelegate {this};
|
||||
frequencies_item_delegate->setItemEditorFactory (item_editor_factory ());
|
||||
ui_->frequencies_table_view->setItemDelegate (frequencies_item_delegate);
|
||||
ui_->frequencies_table_view->setItemDelegateForColumn (FrequencyList_v2::region_column, new ForeignKeyDelegate {®ions_, 0, this});
|
||||
ui_->frequencies_table_view->setItemDelegateForColumn (FrequencyList_v2::mode_column, new ForeignKeyDelegate {&modes_, 0, this});
|
||||
|
||||
@ -1163,9 +1160,6 @@ Configuration::impl::impl (Configuration * self, QNetworkAccessManager * network
|
||||
ui_->stations_table_view->sortByColumn (StationList::band_column, Qt::AscendingOrder);
|
||||
|
||||
// stations delegates
|
||||
auto stations_item_delegate = new QStyledItemDelegate {this};
|
||||
stations_item_delegate->setItemEditorFactory (item_editor_factory ());
|
||||
ui_->stations_table_view->setItemDelegate (stations_item_delegate);
|
||||
ui_->stations_table_view->setItemDelegateForColumn (StationList::band_column, new ForeignKeyDelegate {&bands_, &next_stations_, 0, StationList::band_column, this});
|
||||
|
||||
// stations actions
|
||||
|
@ -17,14 +17,33 @@
|
||||
#include "widgets/FrequencyLineEdit.hpp"
|
||||
#include "widgets/DateTimeEdit.hpp"
|
||||
|
||||
QItemEditorFactory * item_editor_factory ()
|
||||
namespace
|
||||
{
|
||||
static QItemEditorFactory * our_item_editor_factory = new QItemEditorFactory;
|
||||
return our_item_editor_factory;
|
||||
class ItemEditorFactory final
|
||||
: public QItemEditorFactory
|
||||
{
|
||||
public:
|
||||
ItemEditorFactory ()
|
||||
: default_factory_ {QItemEditorFactory::defaultFactory ()}
|
||||
{
|
||||
}
|
||||
|
||||
QWidget * createEditor (int user_type, QWidget * parent) const override
|
||||
{
|
||||
auto editor = QItemEditorFactory::createEditor (user_type, parent);
|
||||
return editor ? editor : default_factory_->createEditor (user_type, parent);
|
||||
}
|
||||
|
||||
private:
|
||||
QItemEditorFactory const * default_factory_;
|
||||
};
|
||||
}
|
||||
|
||||
void register_types ()
|
||||
{
|
||||
auto item_editor_factory = new ItemEditorFactory;
|
||||
QItemEditorFactory::setDefaultFactory (item_editor_factory);
|
||||
|
||||
// types in Radio.hpp are registered in their own translation unit
|
||||
// as they are needed in the wsjtx_udp shared library too
|
||||
|
||||
@ -32,12 +51,10 @@ void register_types ()
|
||||
// used as signal/slot connection arguments since the new Qt 5.5
|
||||
// Q_ENUM macro only seems to register the unqualified name
|
||||
|
||||
item_editor_factory ()->registerEditor (qMetaTypeId<Radio::Frequency> (), new QStandardItemEditorCreator<FrequencyLineEdit> ());
|
||||
item_editor_factory->registerEditor (qMetaTypeId<Radio::Frequency> (), new QStandardItemEditorCreator<FrequencyLineEdit> ());
|
||||
//auto frequency_delta_type_id = qRegisterMetaType<Radio::FrequencyDelta> ("FrequencyDelta");
|
||||
item_editor_factory ()->registerEditor (qMetaTypeId<Radio::FrequencyDelta> (), new QStandardItemEditorCreator<FrequencyDeltaLineEdit> ());
|
||||
auto factory = new QItemEditorFactory;
|
||||
factory->registerEditor (qMetaTypeId<QDateTime> (), new QStandardItemEditorCreator<DateTimeEdit> ());
|
||||
QItemEditorFactory::setDefaultFactory (factory);
|
||||
item_editor_factory->registerEditor (qMetaTypeId<Radio::FrequencyDelta> (), new QStandardItemEditorCreator<FrequencyDeltaLineEdit> ());
|
||||
item_editor_factory->registerEditor (qMetaTypeId<QDateTime> (), new QStandardItemEditorCreator<DateTimeEdit> ());
|
||||
|
||||
// Frequency list model
|
||||
qRegisterMetaTypeStreamOperators<FrequencyList_v2::Item> ("Item_v2");
|
||||
|
@ -1,9 +1,6 @@
|
||||
#ifndef META_DATA_REGISTRY_HPP__
|
||||
#define META_DATA_REGISTRY_HPP__
|
||||
|
||||
class QItemEditorFactory;
|
||||
|
||||
QItemEditorFactory * item_editor_factory ();
|
||||
void register_types ();
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user