GUI: Allow creating new project file.

Add new "New project file" item to File-menu and rename existing
"Project File" item to "Open Project File". Selecting new file
opens empty project file dialog. When the dialog is then closed
the user is asked to select a filename for the new project file.
This commit is contained in:
Kimmo Varis 2010-07-08 18:59:06 +03:00
parent 4958424adc
commit 25a9c75287
5 changed files with 430 additions and 377 deletions

View File

@ -1,369 +1,375 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>640</width>
<height>480</height>
</size>
</property>
<property name="windowTitle">
<string>Cppcheck</string>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<widget class="QWidget" name="mCentral">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="ResultsView" name="mResults" native="true"/>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="mMenuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="mMenuFile">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="mActionProjectFile"/>
<addaction name="mActionSave"/>
<addaction name="mActionQuit"/>
</widget>
<widget class="QMenu" name="mMenuView">
<property name="title">
<string>&amp;View</string>
</property>
<widget class="QMenu" name="mMenuToolbars">
<property name="title">
<string>&amp;Toolbars</string>
</property>
<addaction name="mActionToolBarMain"/>
<addaction name="mActionToolBarView"/>
</widget>
<addaction name="mMenuToolbars"/>
<addaction name="separator"/>
<addaction name="mActionShowStyle"/>
<addaction name="mActionShowErrors"/>
<addaction name="mActionCheckAll"/>
<addaction name="mActionUncheckAll"/>
<addaction name="separator"/>
<addaction name="mActionCollapseAll"/>
<addaction name="mActionExpandAll"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="mMenuLanguage">
<property name="title">
<string>&amp;Language</string>
</property>
</widget>
<widget class="QMenu" name="mMenuHelp">
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="mActionHelpContents"/>
<addaction name="mActionLicense"/>
<addaction name="mActionAuthors"/>
<addaction name="separator"/>
<addaction name="mActionAbout"/>
</widget>
<widget class="QMenu" name="mMenuCheck">
<property name="title">
<string>&amp;Check</string>
</property>
<addaction name="mActionCheckFiles"/>
<addaction name="mActionCheckDirectory"/>
<addaction name="mActionRecheck"/>
<addaction name="mActionStop"/>
</widget>
<widget class="QMenu" name="mMenuEdit">
<property name="title">
<string>&amp;Edit</string>
</property>
<addaction name="mActionClearResults"/>
<addaction name="mActionSettings"/>
</widget>
<addaction name="mMenuFile"/>
<addaction name="mMenuEdit"/>
<addaction name="mMenuView"/>
<addaction name="mMenuCheck"/>
<addaction name="mMenuLanguage"/>
<addaction name="mMenuHelp"/>
</widget>
<widget class="QToolBar" name="mToolBarMain">
<property name="windowTitle">
<string>Standard</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionCheckDirectory"/>
<addaction name="mActionSave"/>
<addaction name="mActionRecheck"/>
<addaction name="mActionStop"/>
<addaction name="mActionClearResults"/>
<addaction name="mActionSettings"/>
<addaction name="mActionAbout"/>
</widget>
<widget class="QToolBar" name="mToolBarView">
<property name="windowTitle">
<string>Categories</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionShowErrors"/>
<addaction name="mActionShowStyle"/>
</widget>
<action name="mActionLicense">
<property name="text">
<string>&amp;License...</string>
</property>
</action>
<action name="mActionAuthors">
<property name="text">
<string>A&amp;uthors...</string>
</property>
</action>
<action name="mActionAbout">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/help-browser.png</normaloff>:/images/help-browser.png</iconset>
</property>
<property name="text">
<string>&amp;About...</string>
</property>
</action>
<action name="mActionCheckFiles">
<property name="text">
<string>&amp;Files...</string>
</property>
<property name="shortcut">
<string>Ctrl+F</string>
</property>
</action>
<action name="mActionCheckDirectory">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<property name="text">
<string>&amp;Directory...</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="mActionRecheck">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/view-refresh.png</normaloff>:/images/view-refresh.png</iconset>
</property>
<property name="text">
<string>&amp;Recheck files</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="mActionStop">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/process-stop.png</normaloff>:/images/process-stop.png</iconset>
</property>
<property name="text">
<string>&amp;Stop</string>
</property>
<property name="shortcut">
<string>Esc</string>
</property>
</action>
<action name="mActionSave">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/media-floppy.png</normaloff>:/images/media-floppy.png</iconset>
</property>
<property name="text">
<string>&amp;Save results to file...</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="mActionQuit">
<property name="text">
<string>&amp;Quit</string>
</property>
</action>
<action name="mActionClearResults">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/edit-clear.png</normaloff>:/images/edit-clear.png</iconset>
</property>
<property name="text">
<string>&amp;Clear results</string>
</property>
</action>
<action name="mActionSettings">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/preferences-system.png</normaloff>:/images/preferences-system.png</iconset>
</property>
<property name="text">
<string>&amp;Preferences</string>
</property>
</action>
<action name="mActionShowStyle">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/showstylewarnings.png</normaloff>:/images/showstylewarnings.png</iconset>
</property>
<property name="text">
<string>Show style errors</string>
</property>
</action>
<action name="mActionShowErrors">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/showerrors.png</normaloff>:/images/showerrors.png</iconset>
</property>
<property name="text">
<string>Show common errors</string>
</property>
</action>
<action name="mActionCheckAll">
<property name="text">
<string>&amp;Check all</string>
</property>
</action>
<action name="mActionUncheckAll">
<property name="text">
<string>&amp;Uncheck all</string>
</property>
</action>
<action name="mActionCollapseAll">
<property name="text">
<string>Collapse &amp;all</string>
</property>
</action>
<action name="mActionExpandAll">
<property name="text">
<string>&amp;Expand all</string>
</property>
</action>
<action name="mActionToolBarMain">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Standard</string>
</property>
<property name="toolTip">
<string>Standard items</string>
</property>
</action>
<action name="mActionHelpContents">
<property name="text">
<string>&amp;Contents</string>
</property>
<property name="statusTip">
<string>Open the help contents</string>
</property>
<property name="shortcut">
<string>F1</string>
</property>
</action>
<action name="actionToolbar">
<property name="text">
<string>Toolbar</string>
</property>
</action>
<action name="mActionToolBarView">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Categories</string>
</property>
<property name="toolTip">
<string>Error categories</string>
</property>
</action>
<action name="mActionProjectFile">
<property name="text">
<string>P&amp;roject File...</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>ResultsView</class>
<extends>QWidget</extends>
<header>resultsview.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="gui.qrc"/>
</resources>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>640</width>
<height>480</height>
</size>
</property>
<property name="windowTitle">
<string>Cppcheck</string>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<widget class="QWidget" name="mCentral">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="ResultsView" name="mResults" native="true"/>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="mMenuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="mMenuFile">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="mActionNewProjectFile"/>
<addaction name="mActionOpenProjectFile"/>
<addaction name="mActionSave"/>
<addaction name="mActionQuit"/>
</widget>
<widget class="QMenu" name="mMenuView">
<property name="title">
<string>&amp;View</string>
</property>
<widget class="QMenu" name="mMenuToolbars">
<property name="title">
<string>&amp;Toolbars</string>
</property>
<addaction name="mActionToolBarMain"/>
<addaction name="mActionToolBarView"/>
</widget>
<addaction name="mMenuToolbars"/>
<addaction name="separator"/>
<addaction name="mActionShowStyle"/>
<addaction name="mActionShowErrors"/>
<addaction name="mActionCheckAll"/>
<addaction name="mActionUncheckAll"/>
<addaction name="separator"/>
<addaction name="mActionCollapseAll"/>
<addaction name="mActionExpandAll"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="mMenuLanguage">
<property name="title">
<string>&amp;Language</string>
</property>
</widget>
<widget class="QMenu" name="mMenuHelp">
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="mActionHelpContents"/>
<addaction name="mActionLicense"/>
<addaction name="mActionAuthors"/>
<addaction name="separator"/>
<addaction name="mActionAbout"/>
</widget>
<widget class="QMenu" name="mMenuCheck">
<property name="title">
<string>&amp;Check</string>
</property>
<addaction name="mActionCheckFiles"/>
<addaction name="mActionCheckDirectory"/>
<addaction name="mActionRecheck"/>
<addaction name="mActionStop"/>
</widget>
<widget class="QMenu" name="mMenuEdit">
<property name="title">
<string>&amp;Edit</string>
</property>
<addaction name="mActionClearResults"/>
<addaction name="mActionSettings"/>
</widget>
<addaction name="mMenuFile"/>
<addaction name="mMenuEdit"/>
<addaction name="mMenuView"/>
<addaction name="mMenuCheck"/>
<addaction name="mMenuLanguage"/>
<addaction name="mMenuHelp"/>
</widget>
<widget class="QToolBar" name="mToolBarMain">
<property name="windowTitle">
<string>Standard</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionCheckDirectory"/>
<addaction name="mActionSave"/>
<addaction name="mActionRecheck"/>
<addaction name="mActionStop"/>
<addaction name="mActionClearResults"/>
<addaction name="mActionSettings"/>
<addaction name="mActionAbout"/>
</widget>
<widget class="QToolBar" name="mToolBarView">
<property name="windowTitle">
<string>Categories</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionShowErrors"/>
<addaction name="mActionShowStyle"/>
</widget>
<action name="mActionLicense">
<property name="text">
<string>&amp;License...</string>
</property>
</action>
<action name="mActionAuthors">
<property name="text">
<string>A&amp;uthors...</string>
</property>
</action>
<action name="mActionAbout">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/help-browser.png</normaloff>:/images/help-browser.png</iconset>
</property>
<property name="text">
<string>&amp;About...</string>
</property>
</action>
<action name="mActionCheckFiles">
<property name="text">
<string>&amp;Files...</string>
</property>
<property name="shortcut">
<string>Ctrl+F</string>
</property>
</action>
<action name="mActionCheckDirectory">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<property name="text">
<string>&amp;Directory...</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
</action>
<action name="mActionRecheck">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/view-refresh.png</normaloff>:/images/view-refresh.png</iconset>
</property>
<property name="text">
<string>&amp;Recheck files</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="mActionStop">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/process-stop.png</normaloff>:/images/process-stop.png</iconset>
</property>
<property name="text">
<string>&amp;Stop</string>
</property>
<property name="shortcut">
<string>Esc</string>
</property>
</action>
<action name="mActionSave">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/media-floppy.png</normaloff>:/images/media-floppy.png</iconset>
</property>
<property name="text">
<string>&amp;Save results to file...</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
<action name="mActionQuit">
<property name="text">
<string>&amp;Quit</string>
</property>
</action>
<action name="mActionClearResults">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/edit-clear.png</normaloff>:/images/edit-clear.png</iconset>
</property>
<property name="text">
<string>&amp;Clear results</string>
</property>
</action>
<action name="mActionSettings">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/preferences-system.png</normaloff>:/images/preferences-system.png</iconset>
</property>
<property name="text">
<string>&amp;Preferences</string>
</property>
</action>
<action name="mActionShowStyle">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/showstylewarnings.png</normaloff>:/images/showstylewarnings.png</iconset>
</property>
<property name="text">
<string>Show style errors</string>
</property>
</action>
<action name="mActionShowErrors">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/images/showerrors.png</normaloff>:/images/showerrors.png</iconset>
</property>
<property name="text">
<string>Show common errors</string>
</property>
</action>
<action name="mActionCheckAll">
<property name="text">
<string>&amp;Check all</string>
</property>
</action>
<action name="mActionUncheckAll">
<property name="text">
<string>&amp;Uncheck all</string>
</property>
</action>
<action name="mActionCollapseAll">
<property name="text">
<string>Collapse &amp;all</string>
</property>
</action>
<action name="mActionExpandAll">
<property name="text">
<string>&amp;Expand all</string>
</property>
</action>
<action name="mActionToolBarMain">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Standard</string>
</property>
<property name="toolTip">
<string>Standard items</string>
</property>
</action>
<action name="mActionHelpContents">
<property name="text">
<string>&amp;Contents</string>
</property>
<property name="statusTip">
<string>Open the help contents</string>
</property>
<property name="shortcut">
<string>F1</string>
</property>
</action>
<action name="actionToolbar">
<property name="text">
<string>Toolbar</string>
</property>
</action>
<action name="mActionToolBarView">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>&amp;Categories</string>
</property>
<property name="toolTip">
<string>Error categories</string>
</property>
</action>
<action name="mActionOpenProjectFile">
<property name="text">
<string>Open P&amp;roject File...</string>
</property>
</action>
<action name="mActionNewProjectFile">
<property name="text">
<string>&amp;New Project File...</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>ResultsView</class>
<extends>QWidget</extends>
<header>resultsview.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="gui.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -80,7 +80,8 @@ MainWindow::MainWindow() :
connect(mUI.mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded()));
connect(mUI.mMenuView, SIGNAL(aboutToShow()), this, SLOT(AboutToShowViewMenu()));
connect(mUI.mActionProjectFile, SIGNAL(triggered()), this, SLOT(ShowProjectFileDialog()));
connect(mUI.mActionNewProjectFile, SIGNAL(triggered()), this, SLOT(NewProjectFileDialog()));
connect(mUI.mActionOpenProjectFile, SIGNAL(triggered()), this, SLOT(ShowProjectFileDialog()));
#ifdef WIN32
connect(mUI.mActionHelpContents, SIGNAL(triggered()), this, SLOT(OpenHelpContents()));
@ -679,3 +680,9 @@ void MainWindow::ShowProjectFileDialog()
dlg.exec();
}
}
void MainWindow::NewProjectFileDialog()
{
ProjectFileDialog dlg(QString(), this);
dlg.exec();
}

View File

@ -125,6 +125,16 @@ public slots:
*/
void Save();
/**
* @brief Slot to shown project file dialog for new project file.
*
*/
void NewProjectFileDialog();
/**
* @brief Slot to shown project file dialog for existing project file.
*
*/
void ShowProjectFileDialog();
protected slots:

View File

@ -17,16 +17,30 @@
*/
#include <QStringList>
#include <QFile>
#include <QFileDialog>
#include "projectfiledialog.h"
#include "projectfile.h"
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
: QDialog(parent)
, mFileName(path)
, mDataSaved(false)
{
mUI.setupUi(this);
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(this, SIGNAL(accepted()), this, SLOT(DialogAccepted()));
mPFile = new ProjectFile(path, this);
if (QFile::exists(path))
{
ReadProjectFile();
}
}
void ProjectFileDialog::ReadProjectFile()
{
mPFile->Read();
QStringList includes = mPFile->GetIncludeDirs();
@ -48,18 +62,32 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
definestr += ";";
}
mUI.mEditDefines->setText(definestr);
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(this, SIGNAL(finished(int)), this, SLOT(DialogFinished(int)));
}
void ProjectFileDialog::DialogFinished(int result)
void ProjectFileDialog::DialogAccepted()
{
if (result == QDialog::Accepted)
if (mDataSaved)
return;
UpdateProjectFileData();
if (mFileName.isEmpty())
{
const QString filter = tr("Project files (*.cppcheck);;All files(*.*)");
QString filepath = QFileDialog::getSaveFileName(this,
tr("Save Project File"),
QString(),
filter);
if (!filepath.isEmpty())
{
mPFile->Write(filepath);
}
}
else
{
UpdateProjectFileData();
mPFile->Write();
}
mDataSaved = true;
}
void ProjectFileDialog::UpdateProjectFileData()

View File

@ -36,15 +36,17 @@ public:
ProjectFileDialog(const QString &path, QWidget *parent = 0);
protected slots:
void DialogFinished(int result);
void DialogAccepted();
protected:
void ReadProjectFile();
void UpdateProjectFileData();
private:
Ui::ProjectFile mUI;
QString mFileName;
ProjectFile *mPFile;
bool mDataSaved;
};
/// @}