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

View File

@ -125,6 +125,16 @@ public slots:
*/ */
void Save(); 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(); void ShowProjectFileDialog();
protected slots: protected slots:

View File

@ -17,16 +17,30 @@
*/ */
#include <QStringList> #include <QStringList>
#include <QFile>
#include <QFileDialog>
#include "projectfiledialog.h" #include "projectfiledialog.h"
#include "projectfile.h" #include "projectfile.h"
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent) ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
: QDialog(parent) : QDialog(parent)
, mFileName(path) , mFileName(path)
, mDataSaved(false)
{ {
mUI.setupUi(this); mUI.setupUi(this);
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(this, SIGNAL(accepted()), this, SLOT(DialogAccepted()));
mPFile = new ProjectFile(path, this); mPFile = new ProjectFile(path, this);
if (QFile::exists(path))
{
ReadProjectFile();
}
}
void ProjectFileDialog::ReadProjectFile()
{
mPFile->Read(); mPFile->Read();
QStringList includes = mPFile->GetIncludeDirs(); QStringList includes = mPFile->GetIncludeDirs();
@ -48,18 +62,32 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
definestr += ";"; definestr += ";";
} }
mUI.mEditDefines->setText(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(); mPFile->Write();
} }
mDataSaved = true;
} }
void ProjectFileDialog::UpdateProjectFileData() void ProjectFileDialog::UpdateProjectFileData()

View File

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