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

31 32
#ifndef UICODEMODELSUPPORT_H
#define UICODEMODELSUPPORT_H
33

34
#include "qtsupport_global.h"
35

36
#include <cpptools/abstracteditorsupport.h>
37

38
#include <QDateTime>
Tobias Hunger's avatar
Tobias Hunger committed
39
#include <QHash>
Daniel Teske's avatar
Daniel Teske committed
40
#include <QProcess>
Tobias Hunger's avatar
Tobias Hunger committed
41
#include <QSet>
42

Tobias Hunger's avatar
Tobias Hunger committed
43
namespace Core { class IEditor; }
44
namespace CPlusPlus { class CppModelManager; }
45
namespace ProjectExplorer { class Project; }
46

47 48
namespace QtSupport {

Tobias Hunger's avatar
Tobias Hunger committed
49 50 51
namespace Internal { class QtSupportPlugin; }

class UiCodeModelSupport : public CppTools::AbstractEditorSupport
52
{
53
    Q_OBJECT
54

55
public:
56
    UiCodeModelSupport(CppTools::CppModelManager *modelmanager,
57
                       ProjectExplorer::Project *project,
58 59 60
                       const QString &sourceFile,
                       const QString &uiHeaderFile);
    ~UiCodeModelSupport();
61

Tobias Hunger's avatar
Tobias Hunger committed
62
    void setHeaderFileName(const QString &name);
63
    /// \returns the contents encoded in UTF-8.
64
    QByteArray contents() const;
Tobias Hunger's avatar
Tobias Hunger committed
65 66 67
    QString uiFileName() const; // The .ui-file
    QString fileName() const; // The header file
    QString headerFileName() const { return fileName(); }
68 69
    void updateFromEditor(const QString &formEditorContents);
    void updateFromBuild();
70 71 72 73 74 75

private:
    QString uicCommand() const;
    QStringList environment() const;

private slots:
76
    bool finishProcess();
77

78
private:
79
    ProjectExplorer::Project *m_project;
80
    enum State { BARE, RUNNING, FINISHED, ABORTING };
81

dt's avatar
dt committed
82
    void init() const;
83
    bool runUic(const QString &ui) const;
Daniel Teske's avatar
Daniel Teske committed
84
    mutable QProcess m_process;
Tobias Hunger's avatar
Tobias Hunger committed
85 86
    QString m_uiFileName;
    QString m_headerFileName;
87
    mutable State m_state;
88 89
    mutable QByteArray m_contents;
    mutable QDateTime m_cacheTime;
90
    static QList<UiCodeModelSupport *> m_waitingForStart;
91 92
};

Tobias Hunger's avatar
Tobias Hunger committed
93 94 95 96 97 98
class QTSUPPORT_EXPORT UiCodeModelManager : public QObject
{
    Q_OBJECT

public:
    // This needs to be called by the project *before* the C++ code model is updated!
99 100
    static void update(ProjectExplorer::Project *project,
                       QHash<QString, QString> uiHeaders);
Tobias Hunger's avatar
Tobias Hunger committed
101 102 103 104 105 106 107 108 109 110

private slots:
    void buildStateHasChanged(ProjectExplorer::Project *project);
    void projectWasRemoved(ProjectExplorer::Project *project);
    void editorIsAboutToClose(Core::IEditor *editor);
    void editorWasChanged(Core::IEditor *editor);
    void uiDocumentContentsHasChanged();

private:
    UiCodeModelManager();
111
    ~UiCodeModelManager();
Tobias Hunger's avatar
Tobias Hunger committed
112

113
    static void updateContents(const QString &uiFileName, const QString &contents);
Tobias Hunger's avatar
Tobias Hunger committed
114 115 116 117 118 119 120 121 122 123

    QHash<ProjectExplorer::Project *, QList<UiCodeModelSupport *> > m_projectUiSupport;
    Core::IEditor *m_lastEditor;
    bool m_dirty;

    static UiCodeModelManager *m_instance;

    friend class Internal::QtSupportPlugin;
};

124
} // QtSupport
125

126
#endif // UICODEMODELSUPPORT_H