workspacemodel.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2020 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of Qt Creator.
  7. **
  8. ** Commercial License Usage
  9. ** Licensees holding valid commercial Qt licenses may use this file in
  10. ** accordance with the commercial license agreement provided with the
  11. ** Software or, alternatively, in accordance with the terms contained in
  12. ** a written agreement between you and The Qt Company. For licensing terms
  13. ** and conditions see https://www.qt.io/terms-conditions. For further
  14. ** information use the contact form at https://www.qt.io/contact-us.
  15. **
  16. ** GNU Lesser General Public License Usage
  17. ** Alternatively, this file may be used under the terms of the GNU Lesser
  18. ** General Public License version 2.1 or (at your option) any later version.
  19. ** The licenses are as published by the Free Software Foundation
  20. ** and appearing in the file LICENSE.LGPLv21 included in the packaging
  21. ** of this file. Please review the following information to ensure
  22. ** the GNU Lesser General Public License version 2.1 requirements
  23. ** will be met: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 3 or (at your option) any later version
  28. ** approved by the KDE Free Qt Foundation. The licenses are as published by
  29. ** the Free Software Foundation and appearing in the file LICENSE.GPL3
  30. ** included in the packaging of this file. Please review the following
  31. ** information to ensure the GNU General Public License requirements will
  32. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  33. **
  34. ****************************************************************************/
  35. #pragma once
  36. #include <QAbstractTableModel>
  37. #include <functional>
  38. namespace ADS {
  39. class DockManager;
  40. class WorkspaceNameInputDialog;
  41. class WorkspaceModel : public QAbstractTableModel
  42. {
  43. Q_OBJECT
  44. public:
  45. enum { DefaultWorkspaceRole = Qt::UserRole + 1, LastWorkspaceRole, ActiveWorkspaceRole };
  46. explicit WorkspaceModel(DockManager *manager, QObject *parent = nullptr);
  47. int indexOfWorkspace(const QString &workspace);
  48. QString workspaceAt(int row) const;
  49. int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  50. int columnCount(const QModelIndex &parent = QModelIndex()) const override;
  51. QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
  52. QVariant data(const QModelIndex &index, int role) const override;
  53. QHash<int, QByteArray> roleNames() const override;
  54. void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
  55. Q_SCRIPTABLE bool isDefaultVirgin() const;
  56. signals:
  57. void workspaceSwitched();
  58. void workspaceCreated(const QString &workspaceName);
  59. public:
  60. void resetWorkspaces();
  61. void newWorkspace(QWidget *parent);
  62. void cloneWorkspace(QWidget *parent, const QString &workspace);
  63. void deleteWorkspaces(const QStringList &workspaces);
  64. void renameWorkspace(QWidget *parent, const QString &workspace);
  65. void switchToWorkspace(const QString &workspace);
  66. private:
  67. void runWorkspaceNameInputDialog(WorkspaceNameInputDialog *workspaceInputDialog,
  68. std::function<void(const QString &)> createWorkspace);
  69. QStringList m_sortedWorkspaces;
  70. DockManager *m_manager;
  71. };
  72. } // namespace ADS