GUI: Add list control for include paths.

Instead of hard-to-use single line edit control, use list control
for include paths. Have separate buttons for adding, editing and
removing paths. Paths are still stored as one string where paths
are separated with ";". Empty paths are ignored.
This commit is contained in:
Kimmo Varis 2011-02-24 22:06:30 +02:00
parent 9bf6e67898
commit 51eee5f3a7
3 changed files with 138 additions and 35 deletions

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>589</width>
<height>313</height>
<height>319</height>
</rect>
</property>
<property name="windowTitle">
@ -17,37 +17,13 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Include paths:</string>
</property>
<property name="buddy">
<cstring>mEditIncludePaths</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mEditIncludePaths"/>
</item>
<item>
<widget class="QPushButton" name="mBtnAddIncludePath">
<property name="text">
<string>Add...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="sizeConstraint">
@ -182,6 +158,69 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string>Paths</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Include paths:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="mListIncludePaths">
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QPushButton" name="mBtnAddIncludePath">
<property name="text">
<string>Add...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mBtnEditIncludePath">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mBtnRemoveIncludePath">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Applications</string>
@ -284,8 +323,6 @@
</widget>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>mEditIncludePaths</tabstop>
<tabstop>mBtnAddIncludePath</tabstop>
<tabstop>mJobs</tabstop>
<tabstop>mForce</tabstop>
<tabstop>mShowFullPath</tabstop>

View File

@ -46,7 +46,6 @@ SettingsDialog::SettingsDialog(QSettings *programSettings,
mUI.setupUi(this);
mTempApplications->Copy(list);
mUI.mEditIncludePaths->setText(programSettings->value(SETTINGS_GLOBAL_INCLUDE_PATHS).toString());
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()));
@ -70,6 +69,10 @@ SettingsDialog::SettingsDialog(QSettings *programSettings,
this, SLOT(ModifyApplication()));
connect(mUI.mBtnAddIncludePath, SIGNAL(clicked()),
this, SLOT(AddIncludePath()));
connect(mUI.mBtnRemoveIncludePath, SIGNAL(clicked()),
this, SLOT(RemoveIncludePath()));
connect(mUI.mBtnEditIncludePath, SIGNAL(clicked()),
this, SLOT(EditIncludePath()));
mUI.mListWidget->setSortingEnabled(false);
PopulateListWidget();
@ -82,6 +85,7 @@ SettingsDialog::SettingsDialog(QSettings *programSettings,
LoadSettings();
InitTranslationsList();
InitIncludepathsList();
}
SettingsDialog::~SettingsDialog()
@ -89,6 +93,26 @@ SettingsDialog::~SettingsDialog()
SaveSettings();
}
void SettingsDialog::AddIncludePath(const QString &path)
{
if (path.isNull() || path.isEmpty())
return;
QListWidgetItem *item = new QListWidgetItem(path);
item->setFlags(item->flags() | Qt::ItemIsEditable);
mUI.mListIncludePaths->addItem(item);
}
void SettingsDialog::InitIncludepathsList()
{
const QString allPaths = mSettings->value(SETTINGS_GLOBAL_INCLUDE_PATHS).toString();
const QStringList paths = allPaths.split(";", QString::SkipEmptyParts);
foreach(QString path, paths)
{
AddIncludePath(path);
}
}
void SettingsDialog::InitTranslationsList()
{
const QString current = mTranslator->GetCurrentLanguage();
@ -151,11 +175,20 @@ void SettingsDialog::SaveSettingValues()
SaveCheckboxValue(mUI.mShowNoErrorsMessage, SETTINGS_SHOW_NO_ERRORS);
SaveCheckboxValue(mUI.mShowDebugWarnings, SETTINGS_SHOW_DEBUG_WARNINGS);
SaveCheckboxValue(mUI.mInlineSuppressions, SETTINGS_INLINE_SUPPRESSIONS);
mSettings->setValue(SETTINGS_GLOBAL_INCLUDE_PATHS, mUI.mEditIncludePaths->text());
QListWidgetItem *currentLang = mUI.mListLanguages->currentItem();
const QString langcode = currentLang->data(LangCodeRole).toString();
mSettings->setValue(SETTINGS_LANGUAGE, langcode);
const int count = mUI.mListIncludePaths->count();
QString includePaths;
for (int i = 0; i < count; i++)
{
QListWidgetItem *item = mUI.mListIncludePaths->item(i);
includePaths += item->text();
includePaths += ";";
}
mSettings->setValue(SETTINGS_GLOBAL_INCLUDE_PATHS, includePaths);
}
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
@ -268,10 +301,19 @@ void SettingsDialog::AddIncludePath()
if (!selectedDir.isEmpty())
{
QString text = mUI.mEditIncludePaths->text();
if (!text.isEmpty())
text += ';';
text += selectedDir;
mUI.mEditIncludePaths->setText(text);
AddIncludePath(selectedDir);
}
}
void SettingsDialog::RemoveIncludePath()
{
const int row = mUI.mListIncludePaths->currentRow();
QListWidgetItem *item = mUI.mListIncludePaths->takeItem(row);
delete item;
}
void SettingsDialog::EditIncludePath()
{
QListWidgetItem *item = mUI.mListIncludePaths->currentItem();
mUI.mListIncludePaths->editItem(item);
}

View File

@ -118,8 +118,27 @@ protected slots:
*/
void AddIncludePath();
/**
* @brief Slot for removing an include path.
*
*/
void RemoveIncludePath();
/**
* @brief Slot for editing an include path.
*
*/
void EditIncludePath();
protected:
/**
* @brief Add new include path to the list.
* @param path Path to add.
*
*/
void AddIncludePath(const QString &path);
/**
* @brief Clear all applications from the list and re insert them from mTempApplications
*
@ -165,6 +184,11 @@ protected:
*/
bool CheckStateToBool(Qt::CheckState state) const;
/**
* @brief Populate the include paths-list.
*/
void InitIncludepathsList();
/**
* @brief Populate the translations list.
*/