logchangedialog.h 3.8 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
hjk's avatar
hjk committed
24 25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29

30 31
#ifndef LOGCHANGEDDIALOG_H
#define LOGCHANGEDDIALOG_H
32 33

#include <QDialog>
34 35
#include <QIcon>
#include <QStyledItemDelegate>
36
#include <QTreeView>
37 38 39

QT_BEGIN_NAMESPACE
class QDialogButtonBox;
Petar Perisin's avatar
Petar Perisin committed
40
class QComboBox;
41 42 43 44 45 46 47
class QStandardItemModel;
class QStandardItem;
QT_END_NAMESPACE

namespace Git {
namespace Internal {

48 49 50 51 52 53 54 55
// A widget that lists SHA1 and subject of the changes
// Used for reset and interactive rebase

class LogChangeWidget : public QTreeView
{
    Q_OBJECT

public:
56 57 58 59 60 61 62 63
    enum LogFlag
    {
        None = 0x00,
        IncludeRemotes = 0x01
    };

    Q_DECLARE_FLAGS(LogFlags, LogFlag)

64
    explicit LogChangeWidget(QWidget *parent = 0);
65
    bool init(const QString &repository, const QString &commit = QString(), LogFlags flags = None);
66 67
    QString commit() const;
    int commitIndex() const;
68
    QString earliestCommit() const;
69
    void setItemDelegate(QAbstractItemDelegate *delegate);
70

71 72 73 74 75 76
signals:
    void doubleClicked(const QString &commit);

private slots:
    void emitDoubleClicked(const QModelIndex &index);

77
private:
78
    void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
79
    bool populateLog(const QString &repository, const QString &commit, LogFlags flags);
80 81 82
    const QStandardItem *currentItem(int column = 0) const;

    QStandardItemModel *m_model;
83
    bool m_hasCustomDelegate;
84 85
};

86
class LogChangeDialog : public QDialog
87 88
{
    Q_OBJECT
89

90
public:
91
    LogChangeDialog(bool isReset, QWidget *parent);
92

Orgad Shaneh's avatar
Orgad Shaneh committed
93
    bool runDialog(const QString &repository, const QString &commit = QString(),
94
                   LogChangeWidget::LogFlags flags = LogChangeWidget::None);
95 96

    QString commit() const;
97
    int commitIndex() const;
Orgad Shaneh's avatar
Orgad Shaneh committed
98
    QString resetFlag() const;
99
    LogChangeWidget *widget() const;
100 101

private:
102
    LogChangeWidget *m_widget;
103
    QDialogButtonBox *m_dialogButtonBox;
Petar Perisin's avatar
Petar Perisin committed
104
    QComboBox *m_resetTypeComboBox;
105 106
};

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
class LogItemDelegate : public QStyledItemDelegate
{
protected:
    LogItemDelegate(LogChangeWidget *widget);

    int currentRow() const;

private:
    LogChangeWidget *m_widget;
};

class IconItemDelegate : public LogItemDelegate
{
public:
    IconItemDelegate(LogChangeWidget *widget, const QString &icon);

    virtual bool hasIcon(int row) const = 0;

    void paint(QPainter *painter, const QStyleOptionViewItem &option,
               const QModelIndex &index) const;

private:
    QIcon m_icon;
};

132 133 134
} // namespace Internal
} // namespace Git

135
#endif // LOGCHANGEDDIALOG_H