forked from qt-creator/qt-creator
Fixes: Don't call Qt4ProFileNode::update on rebuild.
Task: Found by Roberto.
This commit is contained in:
@@ -203,5 +203,59 @@ void DirectoryWatcher::updateFileList(const QString &dir)
|
||||
}
|
||||
}
|
||||
|
||||
int FileWatcher::m_objectCount = 0;
|
||||
QHash<QString,int> FileWatcher::m_fileCount;
|
||||
QFileSystemWatcher *FileWatcher::m_watcher = 0;
|
||||
|
||||
FileWatcher::FileWatcher(QObject *parent)
|
||||
{
|
||||
if (!m_watcher)
|
||||
m_watcher = new QFileSystemWatcher();
|
||||
++m_objectCount;
|
||||
connect(m_watcher, SIGNAL(fileChanged(QString)),
|
||||
this, SLOT(slotFileChanged(QString)));
|
||||
}
|
||||
|
||||
FileWatcher::~FileWatcher()
|
||||
{
|
||||
foreach (const QString &file, m_files)
|
||||
removeFile(file);
|
||||
if (--m_objectCount == 0) {
|
||||
delete m_watcher;
|
||||
m_watcher = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void FileWatcher::slotFileChanged(const QString &file)
|
||||
{
|
||||
if (m_files.contains(file))
|
||||
emit fileChanged(file);
|
||||
}
|
||||
|
||||
QStringList FileWatcher::files()
|
||||
{
|
||||
return m_files;
|
||||
}
|
||||
|
||||
void FileWatcher::addFile(const QString &file)
|
||||
{
|
||||
if (m_files.contains(file))
|
||||
return;
|
||||
m_files += file;
|
||||
if (m_fileCount[file] == 0)
|
||||
m_watcher->addPath(file);
|
||||
m_fileCount[file] += 1;
|
||||
}
|
||||
|
||||
void FileWatcher::removeFile(const QString &file)
|
||||
{
|
||||
m_files.removeOne(file);
|
||||
m_fileCount[file] -= 1;
|
||||
if (m_fileCount[file] == 0)
|
||||
m_watcher->removePath(file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Qt4ProjectManager
|
||||
|
||||
@@ -87,6 +87,31 @@ private:
|
||||
FileModificationTimeMap m_files;
|
||||
};
|
||||
|
||||
class FileWatcher : public QObject
|
||||
{
|
||||
Q_DISABLE_COPY(FileWatcher)
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FileWatcher(QObject *parent = 0);
|
||||
virtual ~FileWatcher();
|
||||
|
||||
QStringList files();
|
||||
void addFile(const QString &file);
|
||||
void removeFile(const QString &file);
|
||||
signals:
|
||||
void fileChanged(const QString &path);
|
||||
void debugOutout(const QString &path);
|
||||
|
||||
private slots:
|
||||
void slotFileChanged(const QString&);
|
||||
|
||||
private:
|
||||
static int m_objectCount;
|
||||
static QHash<QString, int> m_fileCount;
|
||||
static QFileSystemWatcher *m_watcher;
|
||||
QStringList m_files;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Qt4ProjectManager
|
||||
|
||||
|
||||
@@ -87,11 +87,20 @@ Qt4PriFileNode::Qt4PriFileNode(Qt4Project *project, Qt4ProFileNode* qt4ProFileNo
|
||||
m_project(project),
|
||||
m_qt4ProFileNode(qt4ProFileNode),
|
||||
m_projectFilePath(QDir::fromNativeSeparators(filePath)),
|
||||
m_projectDir(QFileInfo(filePath).absolutePath())
|
||||
m_projectDir(QFileInfo(filePath).absolutePath()),
|
||||
m_fileWatcher(new FileWatcher(this))
|
||||
{
|
||||
QTC_ASSERT(project, return);
|
||||
setFolderName(QFileInfo(filePath).baseName());
|
||||
setIcon(QIcon(":/qt4projectmanager/images/qt_project.png"));
|
||||
m_fileWatcher->addFile(filePath);
|
||||
connect(m_fileWatcher, SIGNAL(fileChanged(QString)),
|
||||
this, SLOT(scheduleUpdate()));
|
||||
}
|
||||
|
||||
void Qt4PriFileNode::scheduleUpdate()
|
||||
{
|
||||
m_qt4ProFileNode->scheduleUpdate();
|
||||
}
|
||||
|
||||
void Qt4PriFileNode::update(ProFile *includeFile, ProFileReader *reader)
|
||||
@@ -495,12 +504,17 @@ Qt4ProFileNode::Qt4ProFileNode(Qt4Project *project,
|
||||
if (parent)
|
||||
setParent(parent);
|
||||
|
||||
m_updateTimer.setInterval(100);
|
||||
m_updateTimer.setSingleShot(true);
|
||||
|
||||
connect(m_dirWatcher, SIGNAL(directoryChanged(const QString&)),
|
||||
this, SLOT(update()));
|
||||
this, SLOT(updateGeneratedFiles()));
|
||||
connect(m_dirWatcher, SIGNAL(fileChanged(const QString&)),
|
||||
this, SLOT(fileChanged(const QString&)));
|
||||
connect(m_project, SIGNAL(activeBuildConfigurationChanged()),
|
||||
this, SLOT(update()));
|
||||
connect(&m_updateTimer, SIGNAL(timeout()),
|
||||
this, SLOT(update()));
|
||||
}
|
||||
|
||||
Qt4ProFileNode::~Qt4ProFileNode()
|
||||
@@ -523,6 +537,11 @@ QStringList Qt4ProFileNode::variableValue(const Qt4Variable var) const
|
||||
return m_varValues.value(var);
|
||||
}
|
||||
|
||||
void Qt4ProFileNode::scheduleUpdate()
|
||||
{
|
||||
m_updateTimer.start();
|
||||
}
|
||||
|
||||
void Qt4ProFileNode::update()
|
||||
{
|
||||
ProFileReader *reader = createProFileReader();
|
||||
@@ -681,9 +700,11 @@ void Qt4ProFileNode::update()
|
||||
|
||||
void Qt4ProFileNode::fileChanged(const QString &filePath)
|
||||
{
|
||||
qDebug()<<"+++++"<<filePath;
|
||||
CppTools::CppModelManagerInterface *modelManager =
|
||||
ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
|
||||
|
||||
// TODO compress
|
||||
modelManager->updateSourceFiles(QStringList() << filePath);
|
||||
}
|
||||
|
||||
@@ -731,11 +752,16 @@ void Qt4ProFileNode::updateGeneratedFiles()
|
||||
|
||||
// update generated files
|
||||
|
||||
// Already existing FileNodes
|
||||
QList<FileNode*> existingFileNodes;
|
||||
foreach (FileNode *file, fileNodes()) {
|
||||
if (file->isGenerated())
|
||||
existingFileNodes << file;
|
||||
}
|
||||
|
||||
|
||||
// Convert uiFile to uiHeaderFilePath, find all headers that correspond
|
||||
// and try to find them in uicDirs
|
||||
QStringList newFilePaths;
|
||||
foreach (const QString &uicDir, m_varValues[UiDirVar]) {
|
||||
foreach (FileNode *uiFile, uiFiles) {
|
||||
|
||||
@@ -75,6 +75,7 @@ using ProjectExplorer::FileType;
|
||||
|
||||
class ProFileReader;
|
||||
class DirectoryWatcher;
|
||||
class FileWatcher;
|
||||
|
||||
// Type of projects
|
||||
enum Qt4ProjectType {
|
||||
@@ -142,6 +143,9 @@ protected:
|
||||
QString buildDir() const;
|
||||
ProFileReader *createProFileReader() const;
|
||||
|
||||
private slots:
|
||||
void scheduleUpdate();
|
||||
|
||||
private:
|
||||
void save(ProFile *includeFile);
|
||||
bool priFileWritable(const QString &path);
|
||||
@@ -151,7 +155,10 @@ private:
|
||||
Qt4ProFileNode *m_qt4ProFileNode;
|
||||
QString m_projectFilePath;
|
||||
QString m_projectDir;
|
||||
QTimer *m_saveTimer;
|
||||
|
||||
// TODO we might be better off using an IFile* and the FileManager for
|
||||
// watching changes to the .pro and .pri files on disk
|
||||
FileWatcher *m_fileWatcher;
|
||||
|
||||
// managed by Qt4ProFileNode
|
||||
friend class Qt4ProFileNode;
|
||||
@@ -174,14 +181,13 @@ public:
|
||||
QStringList variableValue(const Qt4Variable var) const;
|
||||
|
||||
public slots:
|
||||
void scheduleUpdate();
|
||||
void update();
|
||||
|
||||
private slots:
|
||||
void fileChanged(const QString &filePath);
|
||||
|
||||
private:
|
||||
void updateGeneratedFiles();
|
||||
|
||||
private:
|
||||
Qt4ProFileNode *createSubProFileNode(const QString &path);
|
||||
|
||||
QStringList uiDirPaths(ProFileReader *reader) const;
|
||||
@@ -197,9 +203,9 @@ private:
|
||||
Qt4ProjectType m_projectType;
|
||||
QHash<Qt4Variable, QStringList> m_varValues;
|
||||
bool m_isQBuildProject;
|
||||
QTimer m_updateTimer;
|
||||
|
||||
DirectoryWatcher *m_dirWatcher;
|
||||
|
||||
friend class Qt4NodeHierarchy;
|
||||
};
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ Qt4Project::~Qt4Project()
|
||||
void Qt4Project::defaultQtVersionChanged()
|
||||
{
|
||||
if (qtVersionId(activeBuildConfiguration()) == 0)
|
||||
update();
|
||||
m_rootProjectNode->update();
|
||||
}
|
||||
|
||||
void Qt4Project::qtVersionsChanged()
|
||||
@@ -274,7 +274,7 @@ void Qt4Project::qtVersionsChanged()
|
||||
if (!qt4ProjectManager()->versionManager()->version(qtVersionId(bc))->isValid()) {
|
||||
setQtVersion(bc, 0);
|
||||
if (bc == activeBuildConfiguration())
|
||||
update();
|
||||
m_rootProjectNode->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -507,9 +507,9 @@ void Qt4Project::updateCodeModel()
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Updates complete project
|
||||
*/
|
||||
///*!
|
||||
// Updates complete project
|
||||
// */
|
||||
void Qt4Project::update()
|
||||
{
|
||||
// TODO Maybe remove this method completely?
|
||||
|
||||
Reference in New Issue
Block a user