GUI: Edit project's include directories as list.

Editing include directories in edit control is not nice. Instead
add new tab and list control for the include directories. They
are now added, edited and removed like global include directories
in settings dialog.
This commit is contained in:
Kimmo Varis 2011-02-25 20:34:55 +02:00
parent ece896a13d
commit d1d0706154
3 changed files with 207 additions and 120 deletions

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>159</height>
<width>467</width>
<height>313</height>
</rect>
</property>
<property name="windowTitle">
@ -15,99 +15,152 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<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>
<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">
<item>
<widget class="QLabel" name="label">
<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="mBtnBrowseIncludes">
<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">
<property name="orientation">
<enum>Qt::Vertical</enum>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Project</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<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>
<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">
<attribute name="title">
<string>Includes</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Include directories:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="mListIncludeDirs">
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="mBtnAddInclude">
<property name="text">
<string>Add...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mBtnEditInclude">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mBtnRemoveInclude">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<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>
</item>
<item>
<widget class="QDialogButtonBox" name="mButtons">
@ -122,13 +175,16 @@
</layout>
</widget>
<tabstops>
<tabstop>mButtons</tabstop>
<tabstop>tabWidget</tabstop>
<tabstop>mEditProjectRoot</tabstop>
<tabstop>mEditPaths</tabstop>
<tabstop>mBtnBrowsePaths</tabstop>
<tabstop>mEditIncludePaths</tabstop>
<tabstop>mBtnBrowseIncludes</tabstop>
<tabstop>mEditDefines</tabstop>
<tabstop>mButtons</tabstop>
<tabstop>mListIncludeDirs</tabstop>
<tabstop>mBtnAddInclude</tabstop>
<tabstop>mBtnEditInclude</tabstop>
<tabstop>mBtnRemoveInclude</tabstop>
</tabstops>
<resources/>
<connections>

View File

@ -37,8 +37,20 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
setWindowTitle(title);
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(mUI.mBtnBrowseIncludes, SIGNAL(clicked()), this, SLOT(BrowseIncludes()));
connect(mUI.mBtnAddInclude, SIGNAL(clicked()), this, SLOT(AddIncludeDir()));
connect(mUI.mBtnBrowsePaths, SIGNAL(clicked()), this, SLOT(BrowsePaths()));
connect(mUI.mBtnEditInclude, SIGNAL(clicked()), this, SLOT(EditIncludeDir()));
connect(mUI.mBtnRemoveInclude, SIGNAL(clicked()), this, SLOT(RemoveIncludeDir()));
}
void ProjectFileDialog::AddIncludeDir(const QString &dir)
{
if (dir.isNull() || dir.isEmpty())
return;
QListWidgetItem *item = new QListWidgetItem(dir);
item->setFlags(item->flags() | Qt::ItemIsEditable);
mUI.mListIncludeDirs->addItem(item);
}
QString ProjectFileDialog::GetRootPath() const
@ -50,18 +62,14 @@ QString ProjectFileDialog::GetRootPath() const
QStringList ProjectFileDialog::GetIncludePaths() const
{
QString include = mUI.mEditIncludePaths->text();
QStringList includes;
if (!include.isEmpty())
const int count = mUI.mListIncludeDirs->count();
QStringList includePaths;
for (int i = 0; i < count; i++)
{
include = include.trimmed();
include = QDir::fromNativeSeparators(include);
if (include.indexOf(';') != -1)
includes = include.split(";");
else
includes.append(include);
QListWidgetItem *item = mUI.mListIncludeDirs->item(i);
includePaths << item->text();
}
return includes;
return includePaths;
}
QStringList ProjectFileDialog::GetDefines() const
@ -102,18 +110,11 @@ void ProjectFileDialog::SetRootPath(const QString &root)
void ProjectFileDialog::SetIncludepaths(const QStringList &includes)
{
QString includestr;
QString dir;
foreach(dir, includes)
{
includestr += dir;
includestr += ";";
AddIncludeDir(dir);
}
// Remove ; from the end of the string
if (includestr.endsWith(';'))
includestr = includestr.left(includestr.length() - 1);
includestr = QDir::toNativeSeparators(includestr);
mUI.mEditIncludePaths->setText(includestr);
}
void ProjectFileDialog::SetDefines(const QStringList &defines)
@ -147,7 +148,7 @@ void ProjectFileDialog::SetPaths(const QStringList &paths)
mUI.mEditPaths->setText(pathstr);
}
void ProjectFileDialog::BrowseIncludes()
void ProjectFileDialog::AddIncludeDir()
{
QString selectedDir = QFileDialog::getExistingDirectory(this,
tr("Select include directory"),
@ -155,7 +156,7 @@ void ProjectFileDialog::BrowseIncludes()
if (!selectedDir.isEmpty())
{
AppendDirname(mUI.mEditIncludePaths, selectedDir);
AddIncludeDir(selectedDir);
}
}
@ -180,3 +181,16 @@ void ProjectFileDialog::AppendDirname(QLineEdit *edit, const QString &dir)
wholeText += QDir::separator();
edit->setText(wholeText);
}
void ProjectFileDialog::RemoveIncludeDir()
{
const int row = mUI.mListIncludeDirs->currentRow();
QListWidgetItem *item = mUI.mListIncludeDirs->takeItem(row);
delete item;
}
void ProjectFileDialog::EditIncludeDir()
{
QListWidgetItem *item = mUI.mListIncludeDirs->currentItem();
mUI.mListIncludeDirs->editItem(item);
}

View File

@ -93,16 +93,33 @@ public:
protected slots:
/**
* @brief Browse for include directory.
* Allow user to choose new include directory.
* Allow user to add new include directory to the list.
*/
void BrowseIncludes();
void AddIncludeDir();
/**
* @brief Browse for checked directory.
* Allow user to choose new checked directory.
*/
void BrowsePaths();
/**
* @brief Remove include directory from the list.
*/
void RemoveIncludeDir();
/**
* @brief Edit include directory in the list.
*/
void EditIncludeDir();
protected:
/**
* @brief Add new indlude directory.
* @param dir Directory to add.
*/
void AddIncludeDir(const QString &dir);
/**
* @brief Append new path to the edit control.
* @param edit Edit control to modify.