Przeglądaj źródła

ctkConsole - Update comments, add const qualifier, remove white spaces

Jean-Christophe Fillion-Robin 14 lat temu
rodzic
commit
ece7dfce74

+ 11 - 11
Libs/Scripting/Python/Widgets/ctkPythonConsole.cpp

@@ -127,7 +127,7 @@ public:
     QStringList attrs;
     if (!lookup.isEmpty() || !compareText.isEmpty())
       {
-      attrs = Parent.getPythonAttributes(lookup);
+      attrs = this->Parent.pythonAttributes(lookup);
       }
 
     // Initialize the completion model
@@ -261,7 +261,7 @@ void ctkPythonConsolePrivate::executeCommand(const QString& command)
 //    this->PythonManager->executeString(command);
 //    }
 }
-  
+
 //----------------------------------------------------------------------------
 void ctkPythonConsolePrivate::promptForInput(const QString& indent)
 {
@@ -307,7 +307,7 @@ ctkPythonConsole::ctkPythonConsole(ctkAbstractPythonManager* pythonManager, QWid
 
   ctkPythonConsoleCompleter* completer = new ctkPythonConsoleCompleter(*this);
   d->Console.setCompleter(completer);
-  
+
   QObject::connect(
     &d->Console, SIGNAL(executeCommand(const QString&)),
     this, SLOT(onExecuteCommand(const QString&)));
@@ -350,7 +350,7 @@ void ctkPythonConsole::executeScript(const QString& script)
 {
   Q_D(ctkPythonConsole);
   Q_UNUSED(script);
-  
+
   this->printStdout("\n");
   emit this->executing(true);
 //   d->Interpreter->RunSimpleString(
@@ -360,7 +360,7 @@ void ctkPythonConsole::executeScript(const QString& script)
 }
 
 //----------------------------------------------------------------------------
-QStringList ctkPythonConsole::getPythonAttributes(const QString& pythonVariableName)
+QStringList ctkPythonConsole::pythonAttributes(const QString& pythonVariableName) const
 {
 //   this->makeCurrent();
 
@@ -429,9 +429,9 @@ void ctkPythonConsole::printStdout(const QString& text)
   QTextCharFormat format = d->Console.getFormat();
   format.setForeground(QColor(0, 150, 0));
   d->Console.setFormat(format);
-  
+
   d->Console.printString(text);
-  
+
   QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
 }
 
@@ -443,7 +443,7 @@ void ctkPythonConsole::printMessage(const QString& text)
   QTextCharFormat format = d->Console.getFormat();
   format.setForeground(QColor(0, 0, 150));
   d->Console.setFormat(format);
-  
+
   d->Console.printString(text);
 }
 
@@ -455,9 +455,9 @@ void ctkPythonConsole::printStderr(const QString& text)
   QTextCharFormat format = d->Console.getFormat();
   format.setForeground(QColor(255, 0, 0));
   d->Console.setFormat(format);
-  
+
   d->Console.printString(text);
-  
+
   QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
 }
 
@@ -491,7 +491,7 @@ void ctkPythonConsole::promptForInput()
 void ctkPythonConsole::internalExecuteCommand(const QString& command)
 {
   Q_D(ctkPythonConsole);
-  emit this->executing(true);  
+  emit this->executing(true);
   d->executeCommand(command);
   emit this->executing(false);
 }

+ 3 - 4
Libs/Scripting/Python/Widgets/ctkPythonConsole.h

@@ -74,16 +74,15 @@ class CTK_SCRIPTING_PYTHON_WIDGETS_EXPORT ctkPythonConsole : public QWidget
   Q_OBJECT
   
 public:
-  typedef QWidget Superclass; 
+  typedef QWidget Superclass;
   ctkPythonConsole(ctkAbstractPythonManager* pythonManager, QWidget* parentObject = 0);
   ~ctkPythonConsole();
 
   /// Prints some text on the shell.
   void printMessage(const QString&);
 
-  /// Given a python variable name, lookup its attributes and return them in a
-  /// string list.
-  QStringList getPythonAttributes(const QString& pythonVariableName);
+  /// Given a python variable name, lookup its attributes and return them in a string list.
+  QStringList pythonAttributes(const QString& pythonVariableName) const;
 
 signals:
   void executing(bool);

+ 25 - 27
Libs/Widgets/ctkConsole.cpp

@@ -128,11 +128,11 @@ void ctkConsolePrivate::keyPressEvent(QKeyEvent* e)
         {
         this->copy();
         }
-        
+
       e->accept();
       return;
       }
-      
+
     // Allow cut only if the selection is limited to the interactive area ...
     if(e->key() == Qt::Key_X && e->modifiers() == Qt::ControlModifier)
       {
@@ -140,11 +140,11 @@ void ctkConsolePrivate::keyPressEvent(QKeyEvent* e)
         {
         this->cut();
         }
-        
+
       e->accept();
       return;
       }
-    
+
     // Allow paste only if the selection is in the interactive area ...
     if(e->key() == Qt::Key_V && e->modifiers() == Qt::ControlModifier)
       {
@@ -158,18 +158,18 @@ void ctkConsolePrivate::keyPressEvent(QKeyEvent* e)
           this->updateCommandBuffer();
           }
         }
-        
+
       e->accept();
       return;
       }
-    
+
     // Force the cursor back to the interactive area
     if(history_area && e->key() != Qt::Key_Control)
       {
       text_cursor.setPosition(this->documentEnd());
       this->setTextCursor(text_cursor);
       }
-    
+
     switch(e->key())
       {
       case Qt::Key_Up:
@@ -179,7 +179,7 @@ void ctkConsolePrivate::keyPressEvent(QKeyEvent* e)
           this->replaceCommandBuffer(this->CommandHistory[--this->CommandPosition]);
           }
         break;
-        
+
       case Qt::Key_Down:
         e->accept();
         if (this->CommandPosition < this->CommandHistory.size() - 2)
@@ -203,14 +203,13 @@ void ctkConsolePrivate::keyPressEvent(QKeyEvent* e)
           e->accept();
           }
         break;
-        
 
       case Qt::Key_Delete:
         e->accept();
         QTextEdit::keyPressEvent(e);
         this->updateCommandBuffer();
         break;
-        
+
       case Qt::Key_Backspace:
         e->accept();
         if(text_cursor.position() > this->InteractivePosition)
@@ -226,24 +225,22 @@ void ctkConsolePrivate::keyPressEvent(QKeyEvent* e)
         this->updateCompleter();
         this->selectCompletion();
         break;
-        
 
       case Qt::Key_Home:
         e->accept();
         text_cursor.setPosition(this->InteractivePosition);
         this->setTextCursor(text_cursor);
         break;
-        
+
       case Qt::Key_Return:
       case Qt::Key_Enter:
         e->accept();
-        
+
         text_cursor.setPosition(this->documentEnd());
         this->setTextCursor(text_cursor);
-        
         this->internalExecuteCommand();
         break;
-        
+
       default:
         e->accept();
         QTextEdit::keyPressEvent(e);
@@ -252,9 +249,9 @@ void ctkConsolePrivate::keyPressEvent(QKeyEvent* e)
         break;
       }
 }
-  
+
 //-----------------------------------------------------------------------------
-/*const*/ int ctkConsolePrivate::documentEnd()
+int ctkConsolePrivate::documentEnd() const
 {
   QTextCursor c(this->document());
   c.movePosition(QTextCursor::End);
@@ -324,13 +321,13 @@ void ctkConsolePrivate::updateCompleter()
       }
     }
 }
-  
+
 //-----------------------------------------------------------------------------c
 void ctkConsolePrivate::updateCommandBuffer()
 {
   this->commandBuffer() = this->toPlainText().mid(this->InteractivePosition);
 }
-  
+
 //-----------------------------------------------------------------------------
 void ctkConsolePrivate::replaceCommandBuffer(const QString& Text)
 {
@@ -342,13 +339,13 @@ void ctkConsolePrivate::replaceCommandBuffer(const QString& Text)
   c.removeSelectedText();
   c.insertText(Text);
 }
-  
+
 //-----------------------------------------------------------------------------
 QString& ctkConsolePrivate::commandBuffer()
 {
   return this->CommandHistory.back();
 }
-  
+
 //-----------------------------------------------------------------------------
 void ctkConsolePrivate::internalExecuteCommand()
 {
@@ -401,9 +398,9 @@ ctkConsole::ctkConsole(QWidget* parentObject) :
   d_ptr(new ctkConsolePrivate(*this))
 {
   Q_D(ctkConsole);
-  QVBoxLayout* const l = new QVBoxLayout(this);
-  l->setMargin(0);
-  l->addWidget(d);
+  QVBoxLayout* layout = new QVBoxLayout(this);
+  layout->setMargin(0);
+  layout->addWidget(d);
 }
 
 //-----------------------------------------------------------------------------
@@ -412,9 +409,9 @@ ctkConsole::~ctkConsole()
 }
 
 //-----------------------------------------------------------------------------
-QTextCharFormat ctkConsole::getFormat()
+QTextCharFormat ctkConsole::getFormat() const
 {
-  Q_D(ctkConsole);
+  Q_D(const ctkConsole);
   return d->currentCharFormat();
 }
 
@@ -478,7 +475,7 @@ void ctkConsole::prompt(const QString& text)
 
   QTextCursor text_cursor = d->textCursor();
 
-  // if the cursor is currently on a clean line, do nothing, otherwise we move
+  // If the cursor is currently on a clean line, do nothing, otherwise we move
   // the cursor to a new line before showing the prompt.
   text_cursor.movePosition(QTextCursor::StartOfLine);
   int startpos = text_cursor.position();
@@ -511,3 +508,4 @@ void ctkConsole::internalExecuteCommand(const QString& Command)
 {
   emit this->executeCommand(Command);
 }
+

+ 2 - 4
Libs/Widgets/ctkConsole.h

@@ -78,14 +78,14 @@ public:
   virtual ~ctkConsole();
 
   /// Returns the current formatting that will be used by printString
-  QTextCharFormat getFormat();
+  QTextCharFormat getFormat() const;
   
   /// Sets formatting that will be used by printString
   void setFormat(const QTextCharFormat& Format);
 
   /// Set a completer for this console widget
   void setCompleter(ctkConsoleCompleter* completer);
-  
+
 signals:
   /// Signal emitted whenever the user enters a command
   void executeCommand(const QString& Command);
@@ -113,8 +113,6 @@ public slots:
   void insertCompletion(const QString& text);
 
 protected:
-
-protected:
   QScopedPointer<ctkConsolePrivate> d_ptr;
 
 private:

+ 6 - 4
Libs/Widgets/ctkConsole_p.h

@@ -40,7 +40,7 @@ public:
   void keyPressEvent(QKeyEvent* e);
   
   /// Returns the end of the document
-  /*const*/ int documentEnd();
+  int documentEnd() const;
 
   void focusOutEvent(QFocusEvent *e);
 
@@ -63,17 +63,19 @@ public:
   
   /// Implements command-execution
   void internalExecuteCommand();
-  
+
   void setCompleter(ctkConsoleCompleter* completer);
 
   /// A custom completer
   QPointer<ctkConsoleCompleter> Completer;
 
-  /** Stores the beginning of the area of interactive input, outside which
-  changes can't be made to the text edit contents */
+  /// Stores the beginning of the area of interactive input, outside which
+  /// changes can't be made to the text edit contents
   int InteractivePosition;
+
   /// Stores command-history, plus the current command buffer
   QStringList CommandHistory;
+
   /// Stores the current position in the command-history
   int CommandPosition;
 };