GUI: Use list to manage paths in project file.

Handling paths in line edit control is quite hard. List control is
much more pleasant to use for it. Convert Project file path
handling to similar list control usage than include paths earlier.
This commit is contained in:
Kimmo Varis 2011-02-26 13:18:11 +02:00
parent d1d0706154
commit cf4a73eb80
3 changed files with 161 additions and 112 deletions

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>467</width>
<height>313</height>
<height>329</height>
</rect>
</property>
<property name="windowTitle">
@ -23,78 +23,114 @@
<attribute name="title">
<string>Project</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Project:</string>
</property>
<property name="buddy">
<cstring>mEditProjectRoot</cstring>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Project:</string>
</property>
<property name="buddy">
<cstring>mEditProjectRoot</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mEditProjectRoot"/>
</item>
</layout>
</item>
<item>
<widget class="QLineEdit" name="mEditProjectRoot"/>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Defines:</string>
</property>
<property name="buddy">
<cstring>mEditDefines</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mEditDefines"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Paths:</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<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>
<item>
<widget class="QListWidget" name="mListPaths"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="mBtnAddPath">
<property name="text">
<string>Add...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mBtnEditPath">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mBtnRemovePath">
<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>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Paths:</string>
</property>
<property name="buddy">
<cstring>mEditPaths</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mEditPaths"/>
</item>
<item>
<widget class="QPushButton" name="mBtnBrowsePaths">
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Defines:</string>
</property>
<property name="buddy">
<cstring>mEditDefines</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mEditDefines"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<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>
</widget>
<widget class="QWidget" name="tab_2">
@ -178,9 +214,11 @@
<tabstop>mButtons</tabstop>
<tabstop>tabWidget</tabstop>
<tabstop>mEditProjectRoot</tabstop>
<tabstop>mEditPaths</tabstop>
<tabstop>mBtnBrowsePaths</tabstop>
<tabstop>mEditDefines</tabstop>
<tabstop>mListPaths</tabstop>
<tabstop>mBtnAddPath</tabstop>
<tabstop>mBtnEditPath</tabstop>
<tabstop>mBtnRemovePath</tabstop>
<tabstop>mListIncludeDirs</tabstop>
<tabstop>mBtnAddInclude</tabstop>
<tabstop>mBtnEditInclude</tabstop>
@ -195,8 +233,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>148</y>
<x>266</x>
<y>319</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
@ -211,8 +249,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>148</y>
<x>334</x>
<y>319</y>
</hint>
<hint type="destinationlabel">
<x>286</x>

View File

@ -38,9 +38,11 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(mUI.mBtnAddInclude, SIGNAL(clicked()), this, SLOT(AddIncludeDir()));
connect(mUI.mBtnBrowsePaths, SIGNAL(clicked()), this, SLOT(BrowsePaths()));
connect(mUI.mBtnAddPath, SIGNAL(clicked()), this, SLOT(AddPath()));
connect(mUI.mBtnEditInclude, SIGNAL(clicked()), this, SLOT(EditIncludeDir()));
connect(mUI.mBtnRemoveInclude, SIGNAL(clicked()), this, SLOT(RemoveIncludeDir()));
connect(mUI.mBtnEditPath, SIGNAL(clicked()), this, SLOT(EditPath()));
connect(mUI.mBtnRemovePath, SIGNAL(clicked()), this, SLOT(RemovePath()));
}
void ProjectFileDialog::AddIncludeDir(const QString &dir)
@ -53,6 +55,16 @@ void ProjectFileDialog::AddIncludeDir(const QString &dir)
mUI.mListIncludeDirs->addItem(item);
}
void ProjectFileDialog::AddPath(const QString &path)
{
if (path.isNull() || path.isEmpty())
return;
QListWidgetItem *item = new QListWidgetItem(path);
item->setFlags(item->flags() | Qt::ItemIsEditable);
mUI.mListPaths->addItem(item);
}
QString ProjectFileDialog::GetRootPath() const
{
QString root = mUI.mEditProjectRoot->text();
@ -89,16 +101,12 @@ QStringList ProjectFileDialog::GetDefines() const
QStringList ProjectFileDialog::GetPaths() const
{
QString path = mUI.mEditPaths->text();
const int count = mUI.mListPaths->count();
QStringList paths;
if (!path.isEmpty())
for (int i = 0; i < count; i++)
{
path = path.trimmed();
path = QDir::fromNativeSeparators(path);
if (path.indexOf(';') != -1)
paths = path.split(";");
else
paths.append(path);
QListWidgetItem *item = mUI.mListPaths->item(i);
paths << item->text();
}
return paths;
}
@ -110,8 +118,7 @@ void ProjectFileDialog::SetRootPath(const QString &root)
void ProjectFileDialog::SetIncludepaths(const QStringList &includes)
{
QString dir;
foreach(dir, includes)
foreach(QString dir, includes)
{
AddIncludeDir(dir);
}
@ -134,18 +141,10 @@ void ProjectFileDialog::SetDefines(const QStringList &defines)
void ProjectFileDialog::SetPaths(const QStringList &paths)
{
QString pathstr;
QString path;
foreach(path, paths)
foreach(QString path, paths)
{
pathstr += path;
pathstr += ";";
AddPath(path);
}
// Remove ; from the end of the string
if (pathstr.endsWith(';'))
pathstr = pathstr.left(pathstr.length() - 1);
pathstr = QDir::toNativeSeparators(pathstr);
mUI.mEditPaths->setText(pathstr);
}
void ProjectFileDialog::AddIncludeDir()
@ -160,7 +159,7 @@ void ProjectFileDialog::AddIncludeDir()
}
}
void ProjectFileDialog::BrowsePaths()
void ProjectFileDialog::AddPath()
{
QString selectedDir = QFileDialog::getExistingDirectory(this,
tr("Select directory to check"),
@ -168,20 +167,10 @@ void ProjectFileDialog::BrowsePaths()
if (!selectedDir.isEmpty())
{
AppendDirname(mUI.mEditPaths, selectedDir);
AddPath(selectedDir);
}
}
void ProjectFileDialog::AppendDirname(QLineEdit *edit, const QString &dir)
{
QString wholeText = edit->text();
wholeText += ";";
wholeText += dir;
if (!wholeText.endsWith(QDir::separator()))
wholeText += QDir::separator();
edit->setText(wholeText);
}
void ProjectFileDialog::RemoveIncludeDir()
{
const int row = mUI.mListIncludeDirs->currentRow();
@ -194,3 +183,16 @@ void ProjectFileDialog::EditIncludeDir()
QListWidgetItem *item = mUI.mListIncludeDirs->currentItem();
mUI.mListIncludeDirs->editItem(item);
}
void ProjectFileDialog::EditPath()
{
QListWidgetItem *item = mUI.mListPaths->currentItem();
mUI.mListPaths->editItem(item);
}
void ProjectFileDialog::RemovePath()
{
const int row = mUI.mListPaths->currentRow();
QListWidgetItem *item = mUI.mListPaths->takeItem(row);
delete item;
}

View File

@ -96,11 +96,11 @@ protected slots:
* Allow user to add new include directory to the list.
*/
void AddIncludeDir();
/**
* @brief Browse for checked directory.
* Allow user to choose new checked directory.
* @brief Add new path to check.
*/
void BrowsePaths();
void AddPath();
/**
* @brief Remove include directory from the list.
@ -112,6 +112,16 @@ protected slots:
*/
void EditIncludeDir();
/**
* @brief Edit path in the list.
*/
void EditPath();
/**
* @brief Remove path from the list.
*/
void RemovePath();
protected:
/**
@ -121,11 +131,10 @@ protected:
void AddIncludeDir(const QString &dir);
/**
* @brief Append new path to the edit control.
* @param edit Edit control to modify.
* @param dir Path to add.
* @brief Add new path to check.
* @param path Path to add.
*/
void AppendDirname(QLineEdit *edit, const QString &dir);
void AddPath(const QString &path);
private:
Ui::ProjectFile mUI;