Skip to content

Commit

Permalink
Added page input field functionality. Refs #8230.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawrainey committed Nov 20, 2013
1 parent 0a355dd commit 36c4cf5
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<x>0</x>
<y>0</y>
<width>679</width>
<height>944</height>
<height>954</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -99,10 +99,10 @@
</font>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:400;&quot;&gt;Reset all fields&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Click to retrieve the &lt;span style=&quot; font-style:italic;&quot;&gt;previous&lt;/span&gt; 100 investigations for your search.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>&lt; Prev |</string>
<string>&lt; Prev</string>
</property>
</widget>
</item>
Expand All @@ -120,15 +120,27 @@
</widget>
</item>
<item>
<widget class="QLabel" name="resPageStartNumTxt">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
<widget class="QLineEdit" name="pageStartNum">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Press &lt;span style=&quot; font-style:italic;&quot;&gt;enter&lt;/span&gt; to perform the search for that page number.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="inputMethodHints">
<set>Qt::ImhDigitsOnly</set>
</property>
<property name="maxLength">
<number>4</number>
</property>
</widget>
</item>
Expand Down Expand Up @@ -160,17 +172,30 @@
</item>
<item>
<widget class="QPushButton" name="resNext">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
<stylestrategy>PreferDefault</stylestrategy>
</font>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:400;&quot;&gt;Reset all fields&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Click to retrieve the &lt;span style=&quot; font-style:italic;&quot;&gt;next&lt;/span&gt; 100 investigations for your search.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>| Next &gt;</string>
<string>Next &gt;</string>
</property>
</widget>
</item>
Expand All @@ -187,19 +212,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="resDisplayingTxt">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down Expand Up @@ -253,16 +265,6 @@
</property>
</widget>
</item>
<item row="3" column="2" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="InvestigatorSurname_err">
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0);</string>
</property>
<property name="text">
<string>*</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="searchGridSpacer">
<property name="orientation">
Expand All @@ -279,6 +281,16 @@
</property>
</spacer>
</item>
<item row="3" column="2" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="InvestigatorSurname_err">
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0);</string>
</property>
<property name="text">
<string>*</string>
</property>
</widget>
</item>
<item row="4" column="1" alignment="Qt::AlignVCenter">
<widget class="QLineEdit" name="DataFileName"/>
</item>
Expand Down Expand Up @@ -593,9 +605,6 @@
</property>
</widget>
</item>
<item row="3" column="5" colspan="2">
<widget class="QLineEdit" name="SampleName"/>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="advSearchCbox">
<property name="text">
Expand Down Expand Up @@ -672,6 +681,9 @@
</property>
</widget>
</item>
<item row="3" column="5" colspan="2">
<widget class="QLineEdit" name="SampleName"/>
</item>
</layout>
</item>
</layout>
Expand Down
103 changes: 50 additions & 53 deletions Code/Mantid/MantidQt/MantidWidgets/src/CatalogSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ namespace MantidQt
connect(m_icatUiForm.resPrevious,SIGNAL(clicked()),this,SLOT(prevPageClicked()));
// When the user clicks "Next >" populate the results table with the next 100 results.
connect(m_icatUiForm.resNext,SIGNAL(clicked()),this,SLOT(nextPageClicked()));
// When the user is done editing & presses enter we retrieve the results for that specific page in paging.
connect(m_icatUiForm.pageStartNum,SIGNAL(editingFinished()),SLOT(goToInputPage()));

// No need for error handling as that's dealt with in the algorithm being used.
populateInstrumentBox();
Expand Down Expand Up @@ -276,7 +278,6 @@ namespace MantidQt

// In order to reset fields for the table
setupTable(table, 0, 0);

}

/**
Expand Down Expand Up @@ -561,69 +562,66 @@ namespace MantidQt
*/
void CatalogSearch::searchClicked()
{
if (m_icatUiForm.searchBtn)
{
std::string name = sender()->name();
// This allows us to perform paging on each search separately
// as we call this method in three separate SLOTS (two paging & search button).
if (name.compare("searchBtn") == 0) m_currentPageNumber = 1;
std::string name = sender()->name();
// This allows us to perform paging on each search separately
// as we call this method in three separate SLOTS (two paging & search button).
if (name.compare("searchBtn") == 0) m_currentPageNumber = 1;

clearDataFileFrame();
clearDataFileFrame();

std::map<std::string, std::string> inputFields = getSearchFields();
// Contains the error label names, and the related error message.
std::map<std::string, std::string> errors = m_icatHelper->validateProperties(inputFields);
std::map<std::string, std::string> inputFields = getSearchFields();
// Contains the error label names, and the related error message.
std::map<std::string, std::string> errors = m_icatHelper->validateProperties(inputFields);

// Has any errors occurred?
if (!errors.empty() || validateDates())
{
// Clear form to prevent previous search results showing if an error occurs.
clearSearchResultFrame();
showErrorLabels(errors);
m_icatUiForm.searchResultsLbl->setText("An error has occurred in the search form.");
// Stop here to prevent the search being carried out below.
return;
}
// Has any errors occurred?
if (!errors.empty() || validateDates())
{
// Clear form to prevent previous search results showing if an error occurs.
clearSearchResultFrame();
showErrorLabels(errors);
m_icatUiForm.searchResultsLbl->setText("An error has occurred in the search form.");
// Stop here to prevent the search being carried out below.
return;
}

// Since there are no longer errors we hide the error labels.
hideErrorLabels();
// Since there are no longer errors we hide the error labels.
hideErrorLabels();

// We want to disable/hide these as a search is in progress, but no results have been obtained.
m_icatUiForm.resFrame->hide();
m_icatUiForm.searchResultsCbox->setEnabled(false);
m_icatUiForm.searchResultsCbox->setChecked(false);
// We want to disable/hide these as a search is in progress, but no results have been obtained.
m_icatUiForm.resFrame->hide();
m_icatUiForm.searchResultsCbox->setEnabled(false);
m_icatUiForm.searchResultsCbox->setChecked(false);

// Update the label to inform the user that searching is in progress.
m_icatUiForm.searchResultsLbl->setText("searching investigations...");
// Update the label to inform the user that searching is in progress.
m_icatUiForm.searchResultsLbl->setText("searching investigations...");

// Remove previous search results.
std::string searchResults = "searchResults";
clearSearch(m_icatUiForm.searchResultsTbl, searchResults);
// Remove previous search results.
std::string searchResults = "searchResults";
clearSearch(m_icatUiForm.searchResultsTbl, searchResults);

// Perform a search without limit or offset to run COUNT query.
m_icatHelper->executeSearch(inputFields);
// Perform a search without limit or offset to run COUNT query.
m_icatHelper->executeSearch(inputFields);

// Obtain the number of results for paging.
int numrows = int(m_icatHelper->getNumberOfSearchResults());
// Obtain the number of results for paging.
int numrows = int(m_icatHelper->getNumberOfSearchResults());

// Setup values used for paging.
double limit = 100; // Have to make a double for ceil to work correctly.
int totalNumPages = int(ceil(numrows / limit));
int offset = (m_currentPageNumber - 1) * int(limit);
// Setup values used for paging.
double limit = 100; // Have to make a double for ceil to work correctly.
int totalNumPages = int(ceil(numrows / limit));
int offset = (m_currentPageNumber - 1) * int(limit);

// Set paging labels.
m_icatUiForm.resPageStartNumTxt->setText(QString::number(m_currentPageNumber));
m_icatUiForm.resPageEndNumTxt->setText(QString::number(totalNumPages));
// Set paging labels.
m_icatUiForm.pageStartNum->setText(QString::number(m_currentPageNumber));
m_icatUiForm.resPageEndNumTxt->setText(QString::number(totalNumPages));

// Perform a search using paging (E.g. return only n from m).
m_icatHelper->executeSearch(inputFields,offset,int(limit));
// Perform a search using paging (E.g. return only n from m).
m_icatHelper->executeSearch(inputFields,offset,int(limit));

// Update the label to inform the user of how many investigations have been returned from the search.
m_icatUiForm.searchResultsLbl->setText(QString::number(numrows) + " investigations found.");
// Update the label to inform the user of how many investigations have been returned from the search.
m_icatUiForm.searchResultsLbl->setText(QString::number(numrows) + " investigations found.");

// Populate the result table from the searchResult workspace.
populateResultTable();
}
// Populate the result table from the searchResult workspace.
populateResultTable();
}

/**
Expand Down Expand Up @@ -662,8 +660,6 @@ namespace MantidQt
m_icatUiForm.Keywords_err->setVisible(false);
m_icatUiForm.SampleName_err->setVisible(false);
m_icatUiForm.InvestigationType_err->setVisible(false);


}

/**
Expand Down Expand Up @@ -783,7 +779,8 @@ namespace MantidQt
*/
void CatalogSearch::goToInputPage()
{

m_currentPageNumber = m_icatUiForm.pageStartNum->text().toInt();
searchClicked();
}

/**
Expand Down

0 comments on commit 36c4cf5

Please sign in to comment.