LUACompletionModel.hxx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifndef LUAEDITOR_LUACOMPLETIONMODEL_H
  9. #define LUAEDITOR_LUACOMPLETIONMODEL_H
  10. #if !defined(Q_MOC_RUN)
  11. #include <AzCore/base.h>
  12. #include <QtCore/QStringListModel>
  13. #include <Source/LUA/LUAEditorStyleMessages.h>
  14. #include <QRegularExpression>
  15. #endif
  16. #pragma once
  17. namespace LUAEditor
  18. {
  19. class CompletionModel
  20. : public QAbstractItemModel
  21. , private HighlightedWordNotifications::Handler
  22. {
  23. Q_OBJECT
  24. public:
  25. AZ_CLASS_ALLOCATOR(CompletionModel, AZ::SystemAllocator);
  26. CompletionModel(QObject *pParent = nullptr);
  27. virtual ~CompletionModel();
  28. QVariant data(const QModelIndex& index, int role) const override;
  29. Qt::ItemFlags flags(const QModelIndex& index) const override;
  30. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
  31. QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
  32. QModelIndex parent(const QModelIndex& index) const override;
  33. int rowCount(const QModelIndex& parent = QModelIndex()) const override;
  34. int columnCount(const QModelIndex& parent = QModelIndex()) const override;
  35. public slots:
  36. void OnScopeNamesUpdated(const QStringList& scopeNames);
  37. private:
  38. void LUALibraryFunctionsUpdated() override;
  39. void UpdateKeywords();
  40. struct LUAName
  41. {
  42. const QString* m_name{ nullptr };
  43. LUAName* m_parent{ nullptr };
  44. QMap<QString, LUAName> m_children;
  45. QList<LUAName*> m_fastLookup;
  46. void AddName(const QStringList& nameList, int index = 0);
  47. void GenerateFastLookup();
  48. void Reset();
  49. };
  50. QRegularExpression luaSplitRegex{R"([.:])"};
  51. LUAName m_root;
  52. LUAName m_builtIns;
  53. QStringList m_keywords;
  54. };
  55. }
  56. #endif