Settings dialog and application dialog now use Qt Designer ui files.

This commit is contained in:
Vesa Pikki 2009-07-02 19:14:12 +03:00
parent 97508ade3f
commit e973f9653b
7 changed files with 72 additions and 254 deletions

View File

@ -63,7 +63,7 @@ kate -l(line) (file)</string>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<widget class="QDialogButtonBox" name="mButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -77,7 +77,7 @@ kate -l(line) (file)</string>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<sender>mButtons</sender>
<signal>accepted()</signal>
<receiver>ApplicationDialog</receiver>
<slot>accept()</slot>
@ -93,7 +93,7 @@ kate -l(line) (file)</string>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<sender>mButtons</sender>
<signal>rejected()</signal>
<receiver>ApplicationDialog</receiver>
<slot>reject()</slot>

View File

@ -32,47 +32,13 @@ ApplicationDialog::ApplicationDialog(const QString &name,
QWidget *parent) :
QDialog(parent)
{
QVBoxLayout *layout = new QVBoxLayout();
mName = new QLineEdit(name);
mName->setMaxLength(100); // Should be plenty for app name
mPath = new QLineEdit(QDir::toNativeSeparators(path));
mUI.setupUi(this);
QString guide = tr("Here you can add applications that can open error files.\n" \
"Specify a name for the application and the application to execute.\n\n" \
"The following texts are replaced with appriproate values when application is executed:\n" \
"(file) - Filename containing the error\n" \
"(line) - Line number containing the error\n" \
"(message) - Error message\n" \
"(severity) - Error severity\n" \
"\n" \
"Example opening a file with Kate and make Kate scroll to the correct line:\n" \
"kate -l(line) (file)");
layout->addWidget(new QLabel(guide));
layout->addWidget(new QLabel(tr("Application's name")));
layout->addWidget(mName);
layout->addWidget(new QLabel(tr("Application to execute")));
layout->addWidget(mPath);
QPushButton *browse = new QPushButton(tr("Browse"));
connect(browse, SIGNAL(clicked()), this, SLOT(Browse()));
layout->addWidget(browse);
QPushButton *cancel = new QPushButton(tr("Cancel"));
QPushButton *ok = new QPushButton(tr("Ok"));
//Add a layout for ok/cancel buttons
QHBoxLayout *buttonLayout = new QHBoxLayout();
buttonLayout->addWidget(ok);
buttonLayout->addWidget(cancel);
layout->addLayout(buttonLayout);
//Connect OK buttons
connect(ok, SIGNAL(clicked()),
this, SLOT(Ok()));
connect(cancel, SIGNAL(clicked()),
this, SLOT(reject()));
setLayout(layout);
connect(mUI.mButtonBrowse, SIGNAL(clicked()), this, SLOT(Browse()));
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
mUI.mPath->setText(path);
mUI.mName->setText(name);
setWindowTitle(title);
}
@ -108,24 +74,24 @@ void ApplicationDialog::Browse()
}
#endif // Q_WS_WIN
mPath->setText(path);
mUI.mPath->setText(path);
}
}
QString ApplicationDialog::GetName()
{
return mName->text();
return mUI.mName->text();
}
QString ApplicationDialog::GetPath()
{
return mPath->text();
return mUI.mPath->text();
}
void ApplicationDialog::Ok()
{
if (mName->text().isEmpty() || mPath->text().isEmpty())
if (mUI.mName->text().isEmpty() || mUI.mPath->text().isEmpty())
{
QMessageBox msg(QMessageBox::Warning,
tr("Cppcheck"),
@ -139,7 +105,7 @@ void ApplicationDialog::Ok()
else
{
// Convert possible native (Windows) path to internal presentation format
mPath->setText(QDir::fromNativeSeparators(mPath->text()));
mUI.mPath->setText(QDir::fromNativeSeparators(mUI.mPath->text()));
accept();
}
}

View File

@ -21,6 +21,7 @@
#include <QDialog>
#include <QLineEdit>
#include "ui_application.h"
/**
* @brief Dialog to edit a startable application.
@ -70,18 +71,12 @@ protected slots:
*/
void Browse();
protected:
/**
* @brief Editbox for the application's name
* This is just a name to display the application. This has nothing to do
* with executing the application.
*/
QLineEdit *mName;
/**
* @brief Editbox for the application's path
* This also contains all parameters user wants to specify.
* @brief UI from the Qt designer
*
*/
QLineEdit *mPath;
Ui::ApplicationDialog mUI;
private:
};

View File

@ -580,7 +580,7 @@ void MainWindow::SetLanguage(int index)
if (languages.size() <= actions.size())
{
for (int i=0;i<languages.size();i++)
for (int i = 0;i < languages.size();i++)
{
actions[i]->setText(tr(languages[i].toLatin1()));
}

View File

@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -36,26 +36,26 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
<widget class="QLineEdit" name="mJobs"/>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="mForce">
<property name="text">
<string>Check all #ifdef configurations</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<widget class="QCheckBox" name="mShowFullPath">
<property name="text">
<string>Show full path of files</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<widget class="QCheckBox" name="mShowNoErrorsMessage">
<property name="text">
<string>Show &quot;No errors found&quot; message when no errors found</string>
</property>
@ -122,14 +122,14 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="checkBox_4">
<widget class="QCheckBox" name="mSaveAllErrors">
<property name="text">
<string>Save all errors when creating report</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_5">
<widget class="QCheckBox" name="mSaveFullPath">
<property name="text">
<string>Save full path to files in reports</string>
</property>
@ -153,7 +153,7 @@
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<widget class="QDialogButtonBox" name="mButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -167,7 +167,7 @@
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<sender>mButtons</sender>
<signal>accepted()</signal>
<receiver>Settings</receiver>
<slot>accept()</slot>
@ -183,7 +183,7 @@
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<sender>mButtons</sender>
<signal>rejected()</signal>
<receiver>Settings</receiver>
<slot>reject()</slot>

View File

@ -34,124 +34,39 @@ SettingsDialog::SettingsDialog(QSettings *programSettings,
mApplications(list),
mTempApplications(new ApplicationList(this))
{
mUI.setupUi(this);
mTempApplications->Copy(list);
//Create a layout for the settings dialog
QVBoxLayout *dialoglayout = new QVBoxLayout();
//Create a tabwidget and add it to dialogs layout
QTabWidget *tabs = new QTabWidget();
dialoglayout->addWidget(tabs);
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(Ok()));
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
//Add ok and cancel buttons
QPushButton *cancel = new QPushButton(tr("Cancel"));
QPushButton *ok = new QPushButton(tr("Ok"));
mUI.mJobs->setText(programSettings->value(SETTINGS_CHECK_THREADS, 1).toString());
mUI.mForce->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_CHECK_FORCE, false).toBool()));
mUI.mShowFullPath->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_FULL_PATH, false).toBool()));
mUI.mShowNoErrorsMessage->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SHOW_NO_ERRORS, false).toBool()));
//Add a layout for ok/cancel buttons
QHBoxLayout *buttonLayout = new QHBoxLayout();
buttonLayout->addStretch();
buttonLayout->addWidget(ok);
buttonLayout->addWidget(cancel);
//Add button layout to the main dialog layout
dialoglayout->addLayout(buttonLayout);
//Connect OK buttons
connect(ok, SIGNAL(clicked()),
this, SLOT(Ok()));
connect(cancel, SIGNAL(clicked()),
this, SLOT(reject()));
//Begin adding tabs and tab content
//General tab
QWidget *general = new QWidget();
tabs->addTab(general, tr("General"));
//layout for general tab
QVBoxLayout *layout = new QVBoxLayout();
//Number of jobs
QHBoxLayout *jobsLayout = new QHBoxLayout();
mJobs = new QLineEdit(programSettings->value(SETTINGS_CHECK_THREADS, 1).toString());
mJobs->setValidator(new QIntValidator(1, 9999, this));
jobsLayout->addWidget(new QLabel(tr("Number of threads: ")));
jobsLayout->addWidget(mJobs);
layout->addLayout(jobsLayout);
//Force
mForce = AddCheckbox(layout,
tr("Check all #ifdef configurations"),
SETTINGS_CHECK_FORCE,
false);
mShowFullPath = AddCheckbox(layout,
tr("Show full path of files"),
SETTINGS_SHOW_FULL_PATH,
false);
mShowNoErrorsMessage = AddCheckbox(layout,
tr("Show \"No errors found\" message when no errors found"),
SETTINGS_SHOW_NO_ERRORS,
true);
layout->addStretch();
general->setLayout(layout);
//Add tab for setting user startable applications
QWidget *applications = new QWidget();
tabs->addTab(applications, tr("Applications"));
QVBoxLayout *appslayout = new QVBoxLayout();
mListWidget = new QListWidget();
appslayout->addWidget(mListWidget);
applications->setLayout(appslayout);
QPushButton *add = new QPushButton(tr("Add application"));
appslayout->addWidget(add);
connect(add, SIGNAL(clicked()),
connect(mUI.mButtonAdd, SIGNAL(clicked()),
this, SLOT(AddApplication()));
QPushButton *del = new QPushButton(tr("Delete application"));
appslayout->addWidget(del);
connect(del, SIGNAL(clicked()),
connect(mUI.mButtonDelete, SIGNAL(clicked()),
this, SLOT(DeleteApplication()));
QPushButton *modify = new QPushButton(tr("Modify application"));
appslayout->addWidget(modify);
connect(modify, SIGNAL(clicked()),
connect(mUI.mButtonModify, SIGNAL(clicked()),
this, SLOT(ModifyApplication()));
QPushButton *def = new QPushButton(tr("Set as default application"));
appslayout->addWidget(def);
connect(def, SIGNAL(clicked()),
connect(mUI.mButtonDefault, SIGNAL(clicked()),
this, SLOT(DefaultApplication()));
connect(mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
connect(mUI.mListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem *)),
this, SLOT(ModifyApplication()));
mListWidget->setSortingEnabled(false);
mUI.mListWidget->setSortingEnabled(false);
PopulateListWidget();
//report tab
QWidget *report = new QWidget();
tabs->addTab(report, tr("Reports"));
mUI.mSaveAllErrors->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_ALL_ERRORS, false).toBool()));
mUI.mSaveFullPath->setCheckState(BoolToCheckState(programSettings->value(SETTINGS_SAVE_FULL_PATH, false).toBool()));
QVBoxLayout *reportlayout = new QVBoxLayout();
mSaveAllErrors = AddCheckbox(reportlayout,
tr("Save all errors when creating report"),
SETTINGS_SAVE_ALL_ERRORS,
false);
mSaveFullPath = AddCheckbox(reportlayout,
tr("Save full path to files in reports"),
SETTINGS_SAVE_FULL_PATH,
false);
reportlayout->addStretch();
report->setLayout(reportlayout);
setLayout(dialoglayout);
setWindowTitle(tr("Settings"));
LoadSettings();
}
@ -178,16 +93,6 @@ bool SettingsDialog::CheckStateToBool(Qt::CheckState state)
return false;
}
QCheckBox* SettingsDialog::AddCheckbox(QVBoxLayout *layout,
const QString &label,
const QString &settings,
bool value)
{
QCheckBox *result = new QCheckBox(label);
result->setCheckState(BoolToCheckState(mSettings->value(settings, value).toBool()));
layout->addWidget(result);
return result;
}
void SettingsDialog::LoadSettings()
{
@ -203,18 +108,18 @@ void SettingsDialog::SaveSettings()
void SettingsDialog::SaveCheckboxValues()
{
int jobs = mJobs->text().toInt();
int jobs = mUI.mJobs->text().toInt();
if (jobs <= 0)
{
jobs = 1;
}
mSettings->setValue(SETTINGS_CHECK_THREADS, jobs);
SaveCheckboxValue(mForce, SETTINGS_CHECK_FORCE);
SaveCheckboxValue(mSaveAllErrors, SETTINGS_SAVE_ALL_ERRORS);
SaveCheckboxValue(mSaveFullPath, SETTINGS_SAVE_FULL_PATH);
SaveCheckboxValue(mShowFullPath, SETTINGS_SHOW_FULL_PATH);
SaveCheckboxValue(mShowNoErrorsMessage, SETTINGS_SHOW_NO_ERRORS);
SaveCheckboxValue(mUI.mForce, SETTINGS_CHECK_FORCE);
SaveCheckboxValue(mUI.mSaveAllErrors, SETTINGS_SAVE_ALL_ERRORS);
SaveCheckboxValue(mUI.mSaveFullPath, SETTINGS_SAVE_FULL_PATH);
SaveCheckboxValue(mUI.mShowFullPath, SETTINGS_SHOW_FULL_PATH);
SaveCheckboxValue(mUI.mShowNoErrorsMessage, SETTINGS_SHOW_NO_ERRORS);
}
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
@ -229,31 +134,31 @@ void SettingsDialog::AddApplication()
if (dialog.exec() == QDialog::Accepted)
{
mTempApplications->AddApplicationType(dialog.GetName(), dialog.GetPath());
mListWidget->addItem(dialog.GetName());
mUI.mListWidget->addItem(dialog.GetName());
}
}
void SettingsDialog::DeleteApplication()
{
QList<QListWidgetItem *> selected = mListWidget->selectedItems();
QList<QListWidgetItem *> selected = mUI.mListWidget->selectedItems();
QListWidgetItem *item = 0;
foreach(item, selected)
{
mTempApplications->RemoveApplication(mListWidget->row(item));
mListWidget->clear();
mTempApplications->RemoveApplication(mUI.mListWidget->row(item));
mUI.mListWidget->clear();
PopulateListWidget();
}
}
void SettingsDialog::ModifyApplication()
{
QList<QListWidgetItem *> selected = mListWidget->selectedItems();
QList<QListWidgetItem *> selected = mUI.mListWidget->selectedItems();
QListWidgetItem *item = 0;
foreach(item, selected)
{
int row = mListWidget->row(item);
int row = mUI.mListWidget->row(item);
ApplicationDialog dialog(mTempApplications->GetApplicationName(row),
mTempApplications->GetApplicationPath(row),
@ -269,12 +174,12 @@ void SettingsDialog::ModifyApplication()
void SettingsDialog::DefaultApplication()
{
QList<QListWidgetItem *> selected = mListWidget->selectedItems();
QList<QListWidgetItem *> selected = mUI.mListWidget->selectedItems();
if (selected.size() > 0)
{
int index = mListWidget->row(selected[0]);
int index = mUI.mListWidget->row(selected[0]);
mTempApplications->MoveFirst(index);
mListWidget->clear();
mUI.mListWidget->clear();
PopulateListWidget();
}
}
@ -283,13 +188,13 @@ void SettingsDialog::PopulateListWidget()
{
for (int i = 0; i < mTempApplications->GetApplicationCount(); i++)
{
mListWidget->addItem(mTempApplications->GetApplicationName(i));
mUI.mListWidget->addItem(mTempApplications->GetApplicationName(i));
}
// If list contains items select first item
if (mTempApplications->GetApplicationCount())
{
mListWidget->setCurrentRow(0);
mUI.mListWidget->setCurrentRow(0);
}
}
@ -301,22 +206,22 @@ void SettingsDialog::Ok()
bool SettingsDialog::ShowFullPath()
{
return CheckStateToBool(mShowFullPath->checkState());
return CheckStateToBool(mUI.mShowFullPath->checkState());
}
bool SettingsDialog::SaveFullPath()
{
return CheckStateToBool(mSaveFullPath->checkState());
return CheckStateToBool(mUI.mSaveFullPath->checkState());
}
bool SettingsDialog::SaveAllErrors()
{
return CheckStateToBool(mSaveAllErrors->checkState());
return CheckStateToBool(mUI.mSaveAllErrors->checkState());
}
bool SettingsDialog::ShowNoErrorsMessage()
{
return CheckStateToBool(mShowNoErrorsMessage->checkState());
return CheckStateToBool(mUI.mShowNoErrorsMessage->checkState());
}

View File

@ -31,6 +31,7 @@
#include <QListWidget>
#include <QKeyEvent>
#include "ui_settings.h"
/**
@ -141,18 +142,6 @@ protected:
*/
void SaveCheckboxValue(QCheckBox *box, const QString &name);
/**
* @brief Add a new checkbox to layout
*
* @param layout layout to add to
* @param label label for the checkbox
* @param settings QSettings name for default value
* @return newly created QCheckBox
*/
QCheckBox* AddCheckbox(QVBoxLayout *layout,
const QString &label,
const QString &settings,
bool value);
/**
* @brief Convert bool to Qt::CheckState
@ -170,49 +159,6 @@ protected:
*/
bool CheckStateToBool(Qt::CheckState state);
/**
* @brief How many threads should cppcheck have
*
*/
QLineEdit *mJobs;
/**
* @brief Cppcheck setting
*
*/
QCheckBox *mForce;
/**
* @brief Save all errors
*
*/
QCheckBox *mSaveAllErrors;
/**
* @brief Save full path of the file in error reports
*
*/
QCheckBox *mSaveFullPath;
/**
* @brief Show full path of file in results view
*
*/
QCheckBox *mShowFullPath;
/**
* @brief Show a message dialog when no errors are found (false)
*
*/
QCheckBox *mShowNoErrorsMessage;
/**
* @brief List of all applications that can be started when right clicking
* an error
*/
QListWidget *mListWidget;
/**
* @brief Settings
@ -232,6 +178,12 @@ protected:
* when user clicks ok.
*/
ApplicationList *mTempApplications;
/**
* @brief Dialog from UI designer
*
*/
Ui::Settings mUI;
private:
};