GUI: library editor, edit function comments

This commit is contained in:
Daniel Marjamäki 2015-09-10 20:11:05 +02:00
parent 366a8325b5
commit e09f583096
5 changed files with 128 additions and 38 deletions

View File

@ -3321,8 +3321,8 @@
<not-uninit/>
</arg>
</function>
<!-- const char * strrchr(const char * str, int character);
char * strrchr( char * str, int character); -->
<!-- const char * strrchr(const char * str, int character);-->
<!-- char * strrchr( char * str, int character); -->
<function name="strrchr,std::strrchr">
<use-retval/>
<noreturn>false</noreturn>
@ -3336,8 +3336,8 @@
<valid>0:255</valid>
</arg>
</function>
<!-- const char * strpbrk(const char * str1, const char * str2);
char * strpbrk( char * str1, const char * str2); -->
<!-- const char * strpbrk(const char * str1, const char * str2);-->
<!-- char * strpbrk( char * str1, const char * str2); -->
<function name="strbprk">
<use-retval/>
<pure/>
@ -3352,8 +3352,8 @@
<not-uninit/>
</arg>
</function>
<!-- const wchar_t* wcsrchr(const wchar_t* ws, wchar_t wc);
wchar_t* wcsrchr( wchar_t* ws, wchar_t wc); -->
<!-- const wchar_t* wcsrchr(const wchar_t* ws, wchar_t wc);-->
<!-- wchar_t* wcsrchr( wchar_t* ws, wchar_t wc); -->
<function name="wcsrchr,std::wcsrchr">
<use-retval/>
<noreturn>false</noreturn>
@ -3595,9 +3595,9 @@
</arg>
<formatstr/>
<arg nr="2">
<not-uninit/>
<formatstr/>
<not-null/>
<not-uninit/>
</arg>
<arg nr="any">
<not-uninit/>
@ -3611,8 +3611,8 @@
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
<not-null/>
<not-uninit/>
</arg>
</function>
<!-- int vsprintf(char *s, const char *format, va_list arg); -->
@ -3621,9 +3621,9 @@
<leak-ignore/>
<formatstr/>
<arg nr="2">
<not-uninit/>
<formatstr/>
<not-null/>
<not-uninit/>
</arg>
<arg nr="3"/>
</function>
@ -3636,9 +3636,9 @@
</arg>
<formatstr/>
<arg nr="3">
<not-uninit/>
<formatstr/>
<not-null/>
<not-uninit/>
</arg>
<arg nr="4"/>
</function>
@ -3651,9 +3651,9 @@
</arg>
<formatstr/>
<arg nr="2">
<not-uninit/>
<formatstr/>
<not-null/>
<not-uninit/>
</arg>
<arg nr="any">
<not-uninit/>
@ -3668,9 +3668,9 @@
</arg>
<formatstr/>
<arg nr="3">
<not-uninit/>
<formatstr/>
<not-null/>
<not-uninit/>
</arg>
<arg nr="any">
<not-uninit/>
@ -3685,9 +3685,9 @@
</arg>
<formatstr/>
<arg nr="3">
<not-uninit/>
<formatstr/>
<not-null/>
<not-uninit/>
</arg>
<arg nr="4"/>
</function>
@ -3697,9 +3697,9 @@
<leak-ignore/>
<formatstr scan="true"/>
<arg nr="1">
<not-uninit/>
<formatstr/>
<not-null/>
<not-uninit/>
</arg>
</function>
<!-- int sscanf(const char *string, const char * format, ...); -->
@ -3712,8 +3712,8 @@
<formatstr scan="true"/>
<arg nr="2">
<formatstr/>
<not-uninit/>
<not-null/>
<not-uninit/>
</arg>
</function>
<!-- int fwscanf(FILE* stream, const wchar_t* format, ...); -->

View File

@ -119,7 +119,7 @@ static CppcheckLibraryData::Function::Arg loadFunctionArg(QXmlStreamReader &xmlR
return arg;
}
static CppcheckLibraryData::Function loadFunction(QXmlStreamReader &xmlReader, const QStringList &comments)
static CppcheckLibraryData::Function loadFunction(QXmlStreamReader &xmlReader, const QString comments)
{
CppcheckLibraryData::Function function;
function.comments = comments;
@ -185,13 +185,15 @@ static CppcheckLibraryData::PodType loadPodType(const QXmlStreamReader &xmlReade
bool CppcheckLibraryData::open(QIODevice &file)
{
clear();
QStringList comments;
QString comments;
QXmlStreamReader xmlReader(&file);
while (!xmlReader.atEnd()) {
const QXmlStreamReader::TokenType t = xmlReader.readNext();
switch (t) {
case QXmlStreamReader::Comment:
comments.append(xmlReader.text().toString());
if (!comments.isEmpty())
comments += "\n";
comments += xmlReader.text().toString();
break;
case QXmlStreamReader::StartElement:
if (xmlReader.name() == "container")
@ -263,7 +265,12 @@ static void writeContainer(QXmlStreamWriter &xmlWriter, const CppcheckLibraryDat
static void writeFunction(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::Function &function)
{
foreach(const QString &comment, function.comments) {
QString comments = function.comments;
while (comments.startsWith("\n"))
comments = comments.mid(1);
while (comments.endsWith("\n"))
comments.chop(1);
foreach(const QString &comment, comments.split('\n')) {
xmlWriter.writeComment(comment);
}

View File

@ -64,7 +64,7 @@ public:
leakignore(false), useretval(false) {
}
QStringList comments;
QString comments;
QString name;
enum TrueFalseUnknown { False, True, Unknown } noreturn;
bool gccPure;

View File

@ -167,6 +167,7 @@ void LibraryDialog::selectFunction()
}
ignoreChanges = true;
ui->comments->setPlainText(function->comments);
ui->noreturn->setCurrentIndex(function->noreturn);
ui->useretval->setChecked(function->useretval);
ui->leakignore->setChecked(function->leakignore);
@ -214,6 +215,7 @@ void LibraryDialog::changeFunction()
return;
CppcheckLibraryData::Function *function = currentFunction();
function->comments = ui->comments->toPlainText();
function->noreturn = (CppcheckLibraryData::Function::TrueFalseUnknown)ui->noreturn->currentIndex();
function->useretval = ui->useretval->isChecked();
function->leakignore = ui->leakignore->isChecked();

View File

@ -134,6 +134,55 @@
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="widget" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>32</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>80</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Comments</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>
<item>
<widget class="QPlainTextEdit" name="comments">
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
@ -249,12 +298,12 @@
<slot>changeFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>739</x>
<y>74</y>
<x>550</x>
<y>157</y>
</hint>
<hint type="destinationlabel">
<x>750</x>
<y>74</y>
<x>561</x>
<y>157</y>
</hint>
</hints>
</connection>
@ -265,12 +314,12 @@
<slot>changeFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>735</x>
<y>103</y>
<x>531</x>
<y>183</y>
</hint>
<hint type="destinationlabel">
<x>744</x>
<y>102</y>
<x>540</x>
<y>182</y>
</hint>
</hints>
</connection>
@ -313,8 +362,8 @@
<slot>editArg()</slot>
<hints>
<hint type="sourcelabel">
<x>519</x>
<y>575</y>
<x>488</x>
<y>580</y>
</hint>
<hint type="destinationlabel">
<x>497</x>
@ -329,12 +378,12 @@
<slot>editArg()</slot>
<hints>
<hint type="sourcelabel">
<x>685</x>
<y>149</y>
<x>529</x>
<y>223</y>
</hint>
<hint type="destinationlabel">
<x>693</x>
<y>148</y>
<x>543</x>
<y>223</y>
</hint>
</hints>
</connection>
@ -393,12 +442,12 @@
<slot>changeFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>696</x>
<y>46</y>
<x>545</x>
<y>137</y>
</hint>
<hint type="destinationlabel">
<x>703</x>
<y>46</y>
<x>552</x>
<y>138</y>
</hint>
</hints>
</connection>
@ -418,6 +467,38 @@
</hint>
</hints>
</connection>
<connection>
<sender>noreturn</sender>
<signal>editTextChanged(QString)</signal>
<receiver>LibraryDialog</receiver>
<slot>changeFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>548</x>
<y>128</y>
</hint>
<hint type="destinationlabel">
<x>555</x>
<y>128</y>
</hint>
</hints>
</connection>
<connection>
<sender>comments</sender>
<signal>textChanged()</signal>
<receiver>LibraryDialog</receiver>
<slot>changeFunction()</slot>
<hints>
<hint type="sourcelabel">
<x>567</x>
<y>50</y>
</hint>
<hint type="destinationlabel">
<x>584</x>
<y>48</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>addFunction()</slot>