submiteditorwidget.h 4.98 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
hjk's avatar
hjk committed
25

Tobias Hunger's avatar
Tobias Hunger committed
26
#pragma once
con's avatar
con committed
27

28 29
#include "vcsbase_global.h"

30
#include <QAbstractItemView>
con's avatar
con committed
31 32 33

QT_BEGIN_NAMESPACE
class QAction;
34
class QModelIndex;
con's avatar
con committed
35 36
QT_END_NAMESPACE

37
namespace Utils { class CompletingTextEdit; }
38
namespace VcsBase {
con's avatar
con committed
39

40
class SubmitFieldWidget;
con's avatar
con committed
41
struct SubmitEditorWidgetPrivate;
42
class SubmitFileModel;
con's avatar
con committed
43

44
class VCSBASE_EXPORT SubmitEditorWidget : public QWidget
hjk's avatar
hjk committed
45
{
con's avatar
con committed
46 47
    Q_OBJECT
    Q_PROPERTY(QString descriptionText READ descriptionText WRITE setDescriptionText DESIGNABLE true)
48
    Q_PROPERTY(QAbstractItemView::SelectionMode fileListSelectionMode READ fileListSelectionMode WRITE setFileListSelectionMode DESIGNABLE true)
49 50
    Q_PROPERTY(bool lineWrap READ lineWrap WRITE setLineWrap DESIGNABLE true)
    Q_PROPERTY(int lineWrapWidth READ lineWrapWidth WRITE setLineWrapWidth DESIGNABLE true)
51
    Q_PROPERTY(bool descriptionMandatory READ isDescriptionMandatory WRITE setDescriptionMandatory DESIGNABLE false)
52 53
    Q_PROPERTY(bool emptyFileListEnabled READ isEmptyFileListEnabled WRITE setEmptyFileListEnabled DESIGNABLE true)

con's avatar
con committed
54
public:
55
    SubmitEditorWidget();
Tobias Hunger's avatar
Tobias Hunger committed
56
    ~SubmitEditorWidget() override;
con's avatar
con committed
57

58 59 60
    // Register/Unregister actions that are managed by ActionManager with this widget.
    // The submit action should have Core::Command::CA_UpdateText set as its text will
    // be updated.
con's avatar
con committed
61 62 63 64 65 66 67 68
    void registerActions(QAction *editorUndoAction,  QAction *editorRedoAction,
                         QAction *submitAction = 0, QAction *diffAction = 0);
    void unregisterActions(QAction *editorUndoAction,  QAction *editorRedoAction,
                           QAction *submitAction = 0, QAction *diffAction = 0);

    QString descriptionText() const;
    void setDescriptionText(const QString &text);

69 70 71 72
    // 'Commit' action enabled despite empty file list
    bool isEmptyFileListEnabled() const;
    void setEmptyFileListEnabled(bool e);

73 74 75 76 77 78
    bool lineWrap() const;
    void setLineWrap(bool);

    int lineWrapWidth() const;
    void setLineWrapWidth(int);

79 80 81
    bool isDescriptionMandatory() const;
    void setDescriptionMandatory(bool);

82 83 84
    QAbstractItemView::SelectionMode fileListSelectionMode() const;
    void setFileListSelectionMode(QAbstractItemView::SelectionMode sm);

85 86
    void setFileModel(SubmitFileModel *model);
    SubmitFileModel *fileModel() const;
con's avatar
con committed
87 88 89 90

    // Files to be included in submit
    QStringList checkedFiles() const;

91
    Utils::CompletingTextEdit *descriptionEdit() const;
con's avatar
con committed
92

93 94 95
    void addDescriptionEditContextMenuAction(QAction *a);
    void insertDescriptionEditContextMenuAction(int pos, QAction *a);

96 97
    void addSubmitFieldWidget(SubmitFieldWidget *f);
    QList<SubmitFieldWidget *> submitFieldWidgets() const;
98

99
    virtual bool canSubmit() const;
100
    void setUpdateInProgress(bool value);
101
    bool updateInProgress() const;
102

Tobias Hunger's avatar
Tobias Hunger committed
103 104 105
public slots:
    void updateSubmitAction();

con's avatar
con committed
106
signals:
107
    void diffSelected(const QList<int> &);
con's avatar
con committed
108
    void fileSelectionChanged(bool someFileSelected);
109
    void submitActionTextChanged(const QString &);
Hugues Delorme's avatar
Hugues Delorme committed
110
    void submitActionEnabledChanged(bool);
111

con's avatar
con committed
112
protected:
113
    virtual QString cleanupDescription(const QString &) const;
114
    virtual QString commitName() const;
con's avatar
con committed
115
    void insertTopWidget(QWidget *w);
116
    void insertLeftWidget(QWidget *w);
117
    void addSubmitButtonMenu(QMenu *menu);
118
    void hideDescription();
119 120

protected slots:
Yuchen Deng's avatar
Yuchen Deng committed
121
    void descriptionTextChanged();
122

Tobias Hunger's avatar
Tobias Hunger committed
123 124 125 126 127
private:
    void updateCheckAllComboBox();
    void checkAllToggled();
    void checkAll();
    void uncheckAll();
con's avatar
con committed
128 129

    void triggerDiffSelected();
130 131 132 133
    void diffActivated(const QModelIndex &index);
    void diffActivatedDelayed();
    void updateActions();
    void updateDiffAction();
134
    void editorCustomContextMenuRequested(const QPoint &);
135
    void fileListCustomContextMenuRequested(const QPoint & pos);
con's avatar
con committed
136

137
    bool hasSelection() const;
138
    int checkedFilesCount() const;
139 140
    void wrapDescription();
    void trimDescription();
con's avatar
con committed
141

hjk's avatar
hjk committed
142
    SubmitEditorWidgetPrivate *d;
con's avatar
con committed
143 144
};

145
} // namespace VcsBase