mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
Add the ID completion delegate
This commit is contained in:
parent
19cc6b83e5
commit
33e36ee922
3 changed files with 78 additions and 1 deletions
|
@ -69,7 +69,7 @@ opencs_units (view/world
|
||||||
|
|
||||||
opencs_units_noqt (view/world
|
opencs_units_noqt (view/world
|
||||||
subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate
|
subviews enumdelegate vartypedelegate recordstatusdelegate idtypedelegate datadisplaydelegate
|
||||||
scripthighlighter idvalidator dialoguecreator physicssystem
|
scripthighlighter idvalidator dialoguecreator physicssystem idcompletiondelegate
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units (view/widget
|
opencs_units (view/widget
|
||||||
|
|
41
apps/opencs/view/world/idcompletiondelegate.cpp
Normal file
41
apps/opencs/view/world/idcompletiondelegate.cpp
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#include "idcompletiondelegate.hpp"
|
||||||
|
|
||||||
|
#include "../../model/world/idcompletionmanager.hpp"
|
||||||
|
|
||||||
|
CSVWorld::IdCompletionDelegate::IdCompletionDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||||
|
CSMDoc::Document& document,
|
||||||
|
QObject *parent)
|
||||||
|
: CommandDelegate(dispatcher, document, parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QWidget *CSVWorld::IdCompletionDelegate::createEditor(QWidget *parent,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
return createEditor(parent, option, index, CSMWorld::ColumnBase::Display_None);
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *CSVWorld::IdCompletionDelegate::createEditor(QWidget *parent,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &index,
|
||||||
|
CSMWorld::ColumnBase::Display display) const
|
||||||
|
{
|
||||||
|
int columnIdData = index.data(CSMWorld::ColumnBase::Role_ColumnId).toInt();
|
||||||
|
CSMWorld::Columns::ColumnId columnId = static_cast<CSMWorld::Columns::ColumnId>(columnIdData);
|
||||||
|
CSMWorld::IdCompletionManager &completionManager = getDocument().getIdCompletionManager();
|
||||||
|
|
||||||
|
QWidget *editor = CSVWorld::CommandDelegate::createEditor(parent, option, index, display);
|
||||||
|
QLineEdit *lineEditor = qobject_cast<QLineEdit *>(editor);
|
||||||
|
if (lineEditor != NULL && completionManager.isCompleterExistFor(columnId))
|
||||||
|
{
|
||||||
|
lineEditor->setCompleter(completionManager.getCompleter(columnId).get());
|
||||||
|
}
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSVWorld::CommandDelegate *CSVWorld::IdCompletionDelegateFactory::makeDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||||
|
CSMDoc::Document& document,
|
||||||
|
QObject *parent) const
|
||||||
|
{
|
||||||
|
return new IdCompletionDelegate(dispatcher, document, parent);
|
||||||
|
}
|
36
apps/opencs/view/world/idcompletiondelegate.hpp
Normal file
36
apps/opencs/view/world/idcompletiondelegate.hpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#ifndef CSV_WORLD_IDCOMPLETIONMANAGER_HPP
|
||||||
|
#define CSV_WORLD_IDCOMPLETIONMANAGER_HPP
|
||||||
|
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
|
namespace CSVWorld
|
||||||
|
{
|
||||||
|
/// \brief Enables the Id completion for a column
|
||||||
|
class IdCompletionDelegate : public CommandDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IdCompletionDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||||
|
CSMDoc::Document& document,
|
||||||
|
QObject *parent);
|
||||||
|
|
||||||
|
virtual QWidget *createEditor (QWidget *parent,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &index) const;
|
||||||
|
|
||||||
|
virtual QWidget *createEditor (QWidget *parent,
|
||||||
|
const QStyleOptionViewItem &option,
|
||||||
|
const QModelIndex &index,
|
||||||
|
CSMWorld::ColumnBase::Display display) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
class IdCompletionDelegateFactory : public CommandDelegateFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual CommandDelegate *makeDelegate(CSMWorld::CommandDispatcher *dispatcher,
|
||||||
|
CSMDoc::Document& document,
|
||||||
|
QObject *parent) const;
|
||||||
|
///< The ownership of the returned CommandDelegate is transferred to the caller.
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue